CoolFace
Apppublic

socanalyst1/Sentiment_Analyzer

sourceHugging Faceupdated 11mo agoView on Hugging Face
0likes
app.py26 linesDownload Raw Back to root
1import gradio as gr2from transformers import pipeline3 4# Load a pretrained model from Hugging Face (NO AUTH REQUIRED)5model = pipeline(6    "text-classification",7    model="distilbert-base-uncased-finetuned-sst-2-english"8)9 10def analyze_sentiment(text):11    result = model(text)[0]  # returns dict: {label: POSITIVE, score: 0.98}12    label = result["label"]13    confidence = round(result["score"] * 100, 2)14 15    return f"Sentiment: **{label}**\nConfidence: {confidence}%"16 17app = gr.Interface(18    fn=analyze_sentiment,19    inputs=gr.Textbox(lines=3, label="Enter text"),20    outputs="markdown",21    title="AI Sentiment Analyzer",22    description="AI classifier that detects if the text is Positive or Negative.",23)24 25app.launch()26