lewtun HF Staff commited on
Commit
3e84548
Β·
1 Parent(s): e98bb87

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -1,14 +1,14 @@
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.",
 
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="Review analysis",
14
  description="Enter some review text about an Amazon product and check what the model predicts for it's star rating.",