lewtun HF Staff commited on
Commit
e760e21
Β·
1 Parent(s): 388f9e6

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-500-samples")
5
+
6
+ def predict(text):
7
+ label2star = {"LABEL_0": "⭐", "LABEL_1": "⭐⭐", "LABEL_2": "⭐⭐⭐", "LABEL_3": "⭐⭐⭐⭐", "LABEL_4": "⭐⭐⭐⭐⭐"}
8
+ preds = pipe(text)[0]
9
+ return label2star[preds["label"]], round(preds["score"], 5)
10
+
11
+ gradio_ui = gr.Interface(
12
+ fn=predict,
13
+ title="Review analysis",
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 this book!", "The Hunger Games is the worst book ever"],
24
+ ],
25
+ )
26
+
27
+ gradio_ui.launch()