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)