clp commited on
Commit
33f1383
·
1 Parent(s): 8fa7c6c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ pipe = pipeline("text-classification", model="clp/xlm-roberta-base-finetuned-marc-de")
5
+
6
+ label2emoji = {"terrible": "💩", "poor": "😾", "ok": "🐱", "good": "😺", "great": "😻"}
7
+
8
+ def predict(text):
9
+ preds = pipe(text)[0]
10
+ return label2emoji[preds["label"]], round(preds["score"], 5)
11
+
12
+ predict("I love this soccer ball")
13
+
14
+ gradio_ui = gr.Interface(
15
+ fn=predict,
16
+ title="Predicting review scores from customer reviews",
17
+ description="Enter some review text about an Amazon product and check what the model predicts for it's star rating.",
18
+ inputs=[
19
+ gr.inputs.Textbox(lines=5, label="Paste some text here"),
20
+ ],
21
+ outputs=[
22
+ gr.outputs.Textbox(label="Label"),
23
+ gr.outputs.Textbox(label="Score"),
24
+ ],
25
+ examples=[
26
+ ["I love these running shoes"], ["J'adore ces chaussures de course"], ["Ich liebe diese Laufschuhe"]
27
+ ],
28
+ )
29
+
30
+ gradio_ui.launch(debug=True)