Spaces:
Sleeping
Sleeping
Create app.py
Browse files12345678910111213141516171819202122232425262728import gradio as grfrom transformers import pipeline
# Return scores for both labels so Gradio can show a nice bar chartclassifier = pipeline("sentiment-analysis", return_all_scores=True)
def analyze(text: str): if not text.strip(): return {} scores = classifier(text)[0] # [{'label': 'NEGATIVE', 'score': ...}, {'label': 'POSITIVE', 'score': ...}] return {item["label"]: float(item["score"]) for item in scores}
demo = gr.Interface( fn=analyze, inputs=gr.Textbox(lines=4, label="Enter text"), outputs=gr.Label(num_top_classes=2, label="Sentiment"), title="Hugging Face Sentiment (Transformers + Gradio)", description="Type text and get POSITIVE/NEGATIVE scores.", examples=[ ["I've been waiting for a Hugging Face course my whole life."], ["This is the worst thing ever."], ["Meh, it's okay—nothing special."] ],)
if __name__ == "__main__": demo.launch()app.pyAdded+28