Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from transformers import pipeline | |
| # Load sentiment analysis pipeline | |
| classifier = pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english") | |
| # Define prediction function | |
| def predict(text): | |
| result = classifier(text)[0] | |
| return result["label"], round(result["score"], 3) | |
| # Create Gradio interface | |
| app = gr.Interface( | |
| fn=predict, | |
| inputs=gr.Textbox(label="Enter text"), | |
| outputs=[gr.Text(label="Sentiment"), gr.Number(label="Confidence Score")] | |
| ) | |
| # 🚀 This is required in Spaces | |
| app.launch() | |