bertSentiment / app.py
mansi sharma
model chaged
beaa23b
raw
history blame contribute delete
821 Bytes
import gradio as gr
from transformers import pipeline
# Load model from Hugging Face
model_name = "MarieAngeA13/Sentiment-Analysis-BERT"
classifier = pipeline("sentiment-analysis", model=model_name)
# Prediction function
def predict_sentiment(text):
if text.strip() == "":
return "Please enter some text."
result = classifier(text)[0]
label = result["label"]
score = result["score"]
return f"Sentiment: {label} (Confidence: {score:.2f})"
# Gradio UI
iface = gr.Interface(
fn=predict_sentiment,
inputs=gr.Textbox(lines=5, placeholder="Enter your review here..."),
outputs="text",
title="Sentiment Analysis App",
description="Enter a review to classify it as Positive or Negative using a Hugging Face model."
)
# Launch app
if __name__ == "__main__":
iface.launch()