lewtun HF staff commited on
Commit
eb868be
1 Parent(s): 10a2316

Create app.py

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