File size: 917 Bytes
1e9a573 c42c6a5 e7da2c8 1e9a573 9d9e6ed 1e9a573 c9e1d41 |
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 29 30 31 32 |
import gradio as gr
from transformers import pipeline
## Load Pipeline
sentiment_pipeline = pipeline("sentiment-analysis",
model="AfroLogicInsect/sentiment-analysis-model_v2")
def predict_sentiment(text):
if not text.strip():
return "Please enter some text", 0.0
result = sentiment_pipeline(text)[0]
# Fixed label interpretation
if result['label'] == 'POSITIVE':
label = "π Positive"
elif result['label'] == 'NEGATIVE':
label = "π Negative"
else:
# Fallback for LABEL_0/LABEL_1
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(share=True) |