lewtun HF staff commited on
Commit
4def53f
โ€ข
1 Parent(s): fd8b637

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ pipe = pipeline("text-classification", model="lewtun/xlm-roberta-base-finetuned-marc-en")
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
+ gradio_ui = gr.Interface(
13
+ fn=predict,
14
+ title="Predicting review scores from customer reviews",
15
+ description="Enter some review text about an Amazon product and check what the model predicts for it's star rating.",
16
+ inputs=[
17
+ gr.inputs.Textbox(lines=5, label="Paste some text here"),
18
+ ],
19
+ outputs=[
20
+ gr.outputs.Textbox(label="Label"),
21
+ gr.outputs.Textbox(label="Score"),
22
+ ],
23
+ examples=[
24
+ ["My favourite book is Cryptonomicon!"], ["็งใฎๅฅฝใใชๆœฌใฏใ€Œใ‚ฏใƒชใƒ—ใƒˆใƒŽใƒŸใ‚ณใƒณใ€ใงใ™"]
25
+ ],
26
+ )
27
+
28
+ gradio_ui.launch(debug=True)