import gradio as gr from transformers import pipeline # Load model from Hub classifier = pipeline( "sentiment-analysis", model="Nav772/distilbert-rotten-tomatoes-sentiment" ) def predict_sentiment(text): """ Takes user input text and returns sentiment prediction. """ if not text.strip(): return "Please enter some text." result = classifier(text)[0] label = result["label"] confidence = result["score"] return f"{label} (confidence: {confidence:.2%})" # Create interface demo = gr.Interface( fn=predict_sentiment, inputs=gr.Textbox( label="Enter a movie review", placeholder="Type your review here...", lines=3 ), outputs=gr.Textbox(label="Prediction"), title="🎬 Movie Review Sentiment Analyzer", description="This model predicts whether a movie review is positive or negative. Fine-tuned on the Rotten Tomatoes dataset using DistilBERT.", examples=[ ["This film was a masterpiece of storytelling and visual effects."], ["Boring plot, terrible acting, waste of money."], ["It was okay, not great but not terrible either."] ], theme="soft" ) demo.launch()