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