| import gradio as gr |
| from transformers import pipeline |
|
|
| |
| sentiment_pipeline = pipeline("sentiment-analysis") |
|
|
| def analyze_sentiment(text): |
| result = sentiment_pipeline(text)[0] |
| label = result["label"] |
| score = result["score"] |
| return f"Sentiment: {label} (Confidence: {score:.2f})" |
|
|
| |
| demo = gr.Interface( |
| fn=analyze_sentiment, |
| inputs=gr.Textbox(lines=3, placeholder="Enter a sentence..."), |
| outputs="text", |
| title="Sentiment Analysis Demo", |
| description="Enter text to see its sentiment (Positive/Negative) along with a confidence score.", |
| ) |
|
|
| if __name__ == "__main__": |
| demo.launch(server_name="0.0.0.0", server_port=7860) |