Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from transformers import pipeline | |
| # Load model | |
| sentiment_model = pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english") | |
| # Define function for inference | |
| def analyze_sentiment(text): | |
| results = sentiment_model(text) | |
| return f"Sentiment: {results[0]['label']} (Confidence: {results[0]['score']:.2f})" | |
| # Create Gradio interface | |
| interface = gr.Interface( | |
| fn=analyze_sentiment, | |
| inputs=gr.Textbox(lines=2, placeholder="Enter text here..."), | |
| outputs="text", | |
| title="Sentiment Analysis App", | |
| description="Enter a sentence to analyze its sentiment using a fine-tuned DistilBERT model.", | |
| ) | |
| # Launch the app | |
| if __name__ == "__main__": | |
| interface.launch() | |