peter2000 commited on
Commit
bff104f
1 Parent(s): a41227d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -4
app.py CHANGED
@@ -1,7 +1,28 @@
1
  import gradio as gr
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
5
 
6
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ from transformers import pipeline
3
 
4
+ pipe = pipeline("text-classification", model="peter2000/xlm-roberta-base-finetuned-ecoicop")
 
5
 
6
+ def predict(text):
7
+ preds = pipe(text)[0]
8
+ return preds["label"].split('_')[1],preds["label"].split('_')[0], round(preds["score"], 5)
9
+
10
+ gradio_ui = gr.Interface(
11
+ fn=predict,
12
+ title="Predicting E-Coicop Product Categories",
13
+ 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.",
14
+ inputs=[
15
+ gr.inputs.Textbox(lines=5, label="Paste some text here"),
16
+ ],
17
+ outputs=[
18
+ gr.outputs.Textbox(label="Label"),
19
+ gr.outputs.Textbox(label="Score"),
20
+ ],
21
+ examples=[
22
+ ["Tiefkühl Eiscreme & Eiswürfel Bechereis <sep> rewe beste wahl peanut butter eiscreme <sep> REWE Beste Wahl Peanut Butter Eiscreme 500ml"],
23
+ ["epicerie-sucree <sep> cereales chocolat fraise nat <sep> Céréales chocolat & fraise NAT"],
24
+ ["Pelati e passate <sep> unknown <sep> Mutti Polpa di Pomodoro 3 x 400 g"]
25
+ ],
26
+ )
27
+
28
+ gradio_ui.launch(debug=True)