| |
| from transformers import pipeline |
| import gradio as gr |
|
|
| |
| classifier = pipeline("text-classification", model="Ahmedhany1/my-finetuned-distilbert") |
|
|
| |
| id2label = { |
| "LABEL_0": "Negative", |
| "LABEL_1": "Neutral", |
| "LABEL_2": "Positive" |
| } |
|
|
| |
| def predict_sentiment(text): |
| result = classifier(text)[0] |
| label = id2label.get(result['label'], result['label']) |
| confidence = round(result['score'], 4) |
| return f"Sentiment: {label} (Confidence: {confidence})" |
|
|
| |
| demo = gr.Interface( |
| fn=predict_sentiment, |
| inputs=gr.Textbox(lines=3, placeholder="Enter a tweet here..."), |
| outputs="text", |
| title="Twitter Sentiment Analyzer Lab Project", |
| description="Fine-tuned BERT model for classifying tweets as Positive, Neutral, or Negative." |
| ) |
|
|
| demo.launch() |
|
|