File size: 614 Bytes
3b1c848 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | import gradio as gr
from transformers import pipeline
# Load sentiment analysis model
classifier = pipeline("sentiment-analysis")
# Prediction function
def predict_sentiment(text):
result = classifier(text)[0]
label = result["label"]
score = round(result["score"], 4)
return f"Sentiment: {label} (Confidence: {score})"
# Gradio UI
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() |