Spaces:
Sleeping
Sleeping
Upload app.py with huggingface_hub
Browse files
app.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from transformers import pipeline
|
| 4 |
+
|
| 5 |
+
# Load model from Hub
|
| 6 |
+
classifier = pipeline(
|
| 7 |
+
"sentiment-analysis",
|
| 8 |
+
model="Nav772/distilbert-rotten-tomatoes-sentiment"
|
| 9 |
+
)
|
| 10 |
+
|
| 11 |
+
def predict_sentiment(text):
|
| 12 |
+
"""
|
| 13 |
+
Takes user input text and returns sentiment prediction.
|
| 14 |
+
"""
|
| 15 |
+
if not text.strip():
|
| 16 |
+
return "Please enter some text."
|
| 17 |
+
|
| 18 |
+
result = classifier(text)[0]
|
| 19 |
+
label = result["label"]
|
| 20 |
+
confidence = result["score"]
|
| 21 |
+
|
| 22 |
+
return f"{label} (confidence: {confidence:.2%})"
|
| 23 |
+
|
| 24 |
+
# Create interface
|
| 25 |
+
demo = gr.Interface(
|
| 26 |
+
fn=predict_sentiment,
|
| 27 |
+
inputs=gr.Textbox(
|
| 28 |
+
label="Enter a movie review",
|
| 29 |
+
placeholder="Type your review here...",
|
| 30 |
+
lines=3
|
| 31 |
+
),
|
| 32 |
+
outputs=gr.Textbox(label="Prediction"),
|
| 33 |
+
title="🎬 Movie Review Sentiment Analyzer",
|
| 34 |
+
description="This model predicts whether a movie review is positive or negative. Fine-tuned on the Rotten Tomatoes dataset using DistilBERT.",
|
| 35 |
+
examples=[
|
| 36 |
+
["This film was a masterpiece of storytelling and visual effects."],
|
| 37 |
+
["Boring plot, terrible acting, waste of money."],
|
| 38 |
+
["It was okay, not great but not terrible either."]
|
| 39 |
+
],
|
| 40 |
+
theme="soft"
|
| 41 |
+
)
|
| 42 |
+
|
| 43 |
+
demo.launch()
|