Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# app.py — upload this file to your Hugging Face Space
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from transformers import pipeline
|
| 4 |
+
|
| 5 |
+
model_name = "msfasha/distilbert-sentiment-imdb-small"
|
| 6 |
+
classifier = pipeline("sentiment-analysis", model=model_name)
|
| 7 |
+
|
| 8 |
+
def predict_sentiment(text):
|
| 9 |
+
result = classifier(text)[0]
|
| 10 |
+
return f"Label: {result['label']}, Confidence: {round(result['score'], 3)}"
|
| 11 |
+
|
| 12 |
+
interface = gr.Interface(
|
| 13 |
+
fn=predict_sentiment,
|
| 14 |
+
inputs="text",
|
| 15 |
+
outputs="text",
|
| 16 |
+
title="Sentiment Analysis",
|
| 17 |
+
description="Enter a movie review to classify as POSITIVE or NEGATIVE."
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
interface.launch()
|