File size: 1,163 Bytes
a41227d
bff104f
a41227d
bff104f
a41227d
bff104f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from transformers import pipeline

pipe = pipeline("text-classification", model="peter2000/xlm-roberta-base-finetuned-ecoicop")

def predict(text):
    preds = pipe(text)[0]
    return preds["label"].split('_')[1],preds["label"].split('_')[0], round(preds["score"], 5)

gradio_ui = gr.Interface(
    fn=predict,
    title="Predicting E-Coicop Product Categories",
    description="Enter some product text (trained on name, category and url) from an online supermarket and predict the corresponding ECOICOP (level 5) product category for food and baverages.",
    inputs=[
        gr.inputs.Textbox(lines=5, label="Paste some text here"),
    ],
    outputs=[
        gr.outputs.Textbox(label="Label"),
        gr.outputs.Textbox(label="Score"),
    ],
    examples=[
        ["Tiefkühl Eiscreme & Eiswürfel Bechereis <sep> rewe beste wahl peanut butter eiscreme <sep> REWE Beste Wahl Peanut Butter Eiscreme 500ml"], 
        ["epicerie-sucree <sep> cereales chocolat fraise nat <sep> Céréales chocolat & fraise NAT"],
        ["Pelati e passate <sep> unknown <sep> Mutti Polpa di Pomodoro 3 x 400 g"]
    ],
)

gradio_ui.launch(debug=True)