Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from transformers import pipeline | |
| # Load a pre-trained sentiment analysis model | |
| model = pipeline("sentiment-analysis") | |
| # Define the function to be called by Gradio | |
| def predict(text): | |
| result = model(text)[0] # e.g., {'label': 'POSITIVE', 'score': 0.999} | |
| return f"{result['label']} (score: {result['score']:.2f})" | |
| # Build Gradio interface | |
| demo = gr.Interface( | |
| fn=predict, | |
| inputs=gr.Textbox(lines=2, placeholder="Enter text here..."), | |
| outputs="text", | |
| title="Sentiment Analysis", | |
| description="This app uses a Hugging Face model to predict sentiment (positive/negative)." | |
| ) | |
| # Launch the app | |
| demo.launch() | |