File size: 667 Bytes
1e9a573
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import gradio as gr
from transformers import pipeline

## Load Pipeline
sentiment_pipeline == pipeline("sentiment-analysis",
                              model="AfroLogicInsect/sentiment-analysis-model")

def predict_sentiment(text):
    if not text.strip():
        return "Please enter some text", 0.0

    result = sentiment_pipeline(text)[0]
    label = "😊 Positive" if result['label'] == 'LABEL_1' else "😞 Negative"
    return label, round(result['score'], 3)

iface = gr.Interface(
    fn = predict_sentiment,
    inputs=gr.Textbox(label="Enter text"),
    outputs=[gr.Text(label="Sentiment"),
            gr.Number(label="Confidence")]
)

iface.launch()