| import gradio as gr |
| from transformers import pipeline |
|
|
| |
| classifier = pipeline("sentiment-analysis") |
|
|
| |
| def predict_sentiment(text): |
| result = classifier(text)[0] |
| label = result["label"] |
| score = round(result["score"], 4) |
| return f"Sentiment: {label} (Confidence: {score})" |
|
|
| |
| app = gr.Interface( |
| fn=predict_sentiment, |
| inputs=gr.Textbox(lines=3, placeholder="Enter your text here..."), |
| outputs="text", |
| title="BERT Sentiment Analysis", |
| description="Enter text to classify sentiment as Positive or Negative" |
| ) |
|
|
| app.launch() |