Spaces:
Runtime error
Runtime error
| import os | |
| os.system("pip install torch==2.1.2 --force-reinstall") | |
| from transformers import pipeline | |
| import gradio as gr | |
| # Load sentiment analysis pipeline | |
| classifier = pipeline("sentiment-analysis") | |
| def analyze_sentiment(text): | |
| result = classifier(text)[0] | |
| label = result['label'] | |
| score = round(result['score'], 4) | |
| return f"Sentiment: {label} (Confidence: {score})" | |
| demo = gr.Interface(fn=analyze_sentiment, | |
| inputs=gr.Textbox(lines=2, placeholder="Type your sentence here..."), | |
| outputs="text", | |
| title="Sentiment Analyzer 🤗", | |
| description="Enter a sentence to analyze sentiment using Hugging Face Transformers.") | |
| demo.launch() | |