| | import torch |
| | import gradio as gr |
| | from transformers import pipeline |
| |
|
| | |
| | sentiment_analysis = pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english") |
| |
|
| | |
| | def analyze_sentiment(input_text): |
| | |
| | result = sentiment_analysis(input_text) |
| | |
| | label = result[0]['label'] |
| | confidence = round(result[0]['score'] * 100, 2) |
| | return f"Sentiment: {label} (Confidence: {confidence}%)" |
| |
|
| | |
| | gr.close_all() |
| |
|
| | Demo = gr.Interface( |
| | fn=analyze_sentiment, |
| | inputs=[gr.Textbox(label="Enter Text for Sentiment Analysis", lines=5)], |
| | outputs=[gr.Textbox(label="Sentiment Analysis Result", lines=2)], |
| | title="Sentiment Analysis App", |
| | description="This application performs sentiment analysis to determine whether the text is positive or negative." |
| | ) |
| |
|
| | |
| | Demo.launch() |
| |
|