Spaces:
Runtime error
Runtime error
Create app.py
Browse files
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")
|
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 |
+
["I love these running shoes"], ["J'adore ces chaussures de course"], ["Ich liebe diese Laufschuhe"]
|
25 |
+
],
|
26 |
+
)
|
27 |
+
|
28 |
+
gradio_ui.launch(debug=True)
|