File size: 931 Bytes
1c66f05
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import gradio as gr
from transformers import pipeline

pipe = pipeline("text-classification", model="lewtun/xlm-roberta-base-finetuned-marc-en")

label2emoji = {"terrible": "๐Ÿ’ฉ", "poor": "๐Ÿ˜พ", "ok": "๐Ÿฑ", "good": "๐Ÿ˜บ", "great": "๐Ÿ˜ป"}

def predict(text):
    preds = pipe(text)[0]
    return label2emoji[preds["label"]], round(preds["score"], 5)
    
gradio_ui = gr.Interface(
    fn=predict,
    title="Predicting review scores from customer reviews",
    description="Enter some review text about an Amazon product and check what the model predicts for it's star rating.",
    inputs=[
        gr.inputs.Textbox(lines=5, label="Paste some text here"),
    ],
    outputs=[
        gr.outputs.Textbox(label="Label"),
        gr.outputs.Textbox(label="Score"),
    ],
    examples=[
        ["My favourite book is Cryptonomicon!"], ["็งใฎๅฅฝใใชๆœฌใฏใ€Œใ‚ฏใƒชใƒ—ใƒˆใƒŽใƒŸใ‚ณใƒณใ€ใงใ™"]
    ],
)

gradio_ui.launch()