Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,21 @@
|
|
1 |
-
|
2 |
-
from
|
3 |
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
|
4 |
+
def analyze_sentiment(text):
|
5 |
+
classifier = pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english")
|
6 |
+
result = classifier(text)
|
7 |
+
return {
|
8 |
+
"label": result[0]["label"],
|
9 |
+
"score": result[0]["score"]
|
10 |
+
}
|
11 |
+
|
12 |
+
demo = gr.Interface(
|
13 |
+
fn=analyze_sentiment,
|
14 |
+
inputs="textbox",
|
15 |
+
outputs="json",
|
16 |
+
title="Sentiment Analysis",
|
17 |
+
description="Enter text to analyze its sentiment using DistilBERT."
|
18 |
+
)
|
19 |
+
|
20 |
+
demo.queue(api_open=True)
|
21 |
+
demo.launch()
|