File size: 1,359 Bytes
0997170
 
76b1db8
0997170
 
 
 
 
0cff8fb
0997170
76b1db8
c50ae20
0997170
 
 
 
 
 
 
 
 
 
 
 
 
0e7185d
c50ae20
 
 
 
 
 
0997170
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import gradio as gr
import torch
import os
from transformers import AutoTokenizer, T5ForConditionalGeneration

model_id = 'ksabeh/gavi'
max_input_length = 512
max_target_length = 10
auth_token = os.environ.get('TOKEN')

model = T5ForConditionalGeneration.from_pretrained(model_id, use_auth_token=auth_token)
tokenizer = AutoTokenizer.from_pretrained(model_id, use_auth_token=auth_token)

def predict(title, category):
    input = f"{title} <hl> {category} <hl>"
    model_input = tokenizer(input, max_length=max_input_length, truncation=True,
                           padding="max_length")
    model_input = {k:torch.unsqueeze(torch.tensor(v),dim=0) for k,v in model_input.items()}
    predictions = model.generate(**model_input, num_beams=8, do_sample=True, max_length=10)
    return tokenizer.batch_decode(predictions, skip_special_tokens=True)[0]

iface = gr.Interface(
    predict,
    inputs=["text", "text"],
    outputs=['text'],
    title="GAVI",
    examples=[["Arriba Salsa Garlic and Cilantro, 16 oz", "Food"], 
    ["MV Verholen Black GPS Ball Mount for BMW K1200S K1200R K1300S K1300R Black GPS Ball Mount VER-4901-10181", "Toys"],
    ["Mitsubishi 3000GT License Plate Frame (Zince Metal)", "Automotive"],
    ["Fun Fire Truck Pinata Personalized", "Toys"],
    ["White Chocolate Caramel Gourmet Popcorn Kelly", "Food"]
    ]
)

iface.launch()