saiwaimaung's picture
FIX: classifier result access
83d0aae verified
from transformers import pipeline
import gradio as gr
classifier = pipeline("sentiment-analysis")
def score_text(text):
result = classifier(text)[0]
label = result["label"]
score = result["score"]
return f"Sentiment: {label}. Score: {score}."
app = gr.Interface(
fn=score_text,
inputs=["textbox"],
outputs=["textbox"],
title="Sentiment Analysis App πŸ€—πŸ˜ΆπŸ˜€",
description="Enter any text to analyse its sentiment using ML. The app returns whether the sentiment is Positive, Neutral, Negative with confidence score."
)
app.launch()