Spaces:
Sleeping
Sleeping
File size: 776 Bytes
e42832b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | import gradio as gr
from transformers import pipeline
classifier = pipeline(
"sentiment-analysis",
model="distilbert-base-uncased-finetuned-sst-2-english"
)
def analyze(text):
if not text.strip():
return "Please enter some text."
result = classifier(text)[0]
label = result["label"]
score = round(result["score"] * 100, 1)
return f"**{label}** ({score}% confidence)"
demo = gr.Interface(
fn=analyze,
inputs=gr.Textbox(
label="Enter text",
placeholder="Type a sentence to analyze...",
lines=3
),
outputs=gr.Markdown(label="Result"),
title="Mood Meter",
description="Analyze the sentiment of any text. "
"Uses DistilBERT (67M parameters) running on free CPU."
)
demo.launch() |