Create app.py

#1
by florentgbelidji HF staff - opened
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="qualitydatalab/autotrain-car-review-project-966432120")
5
+
6
+ def predict(text):
7
+ label2emoji = {"poor": "☹️", "ok": "😐", "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)