test_sentiment / app.py
msfasha's picture
Create app.py
2ed5863 verified
raw
history blame contribute delete
593 Bytes
# app.py — upload this file to your Hugging Face Space
import gradio as gr
from transformers import pipeline
model_name = "msfasha/distilbert-sentiment-imdb-small"
classifier = pipeline("sentiment-analysis", model=model_name)
def predict_sentiment(text):
result = classifier(text)[0]
return f"Label: {result['label']}, Confidence: {round(result['score'], 3)}"
interface = gr.Interface(
fn=predict_sentiment,
inputs="text",
outputs="text",
title="Sentiment Analysis",
description="Enter a movie review to classify as POSITIVE or NEGATIVE."
)
interface.launch()