Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
classifier = pipeline(
|
| 5 |
+
"sentiment-analysis",
|
| 6 |
+
model="distilbert-base-uncased-finetuned-sst-2-english"
|
| 7 |
+
)
|
| 8 |
+
|
| 9 |
+
def predict(text):
|
| 10 |
+
result = classifier(text)
|
| 11 |
+
return result[0]["label"]
|
| 12 |
+
|
| 13 |
+
with gr.Blocks() as demo:
|
| 14 |
+
gr.Markdown("# Sentiment Analysis")
|
| 15 |
+
text = gr.Textbox(label="Enter text")
|
| 16 |
+
output = gr.Textbox(label="Sentiment")
|
| 17 |
+
btn = gr.Button("Analyze")
|
| 18 |
+
btn.click(fn=predict, inputs=text, outputs=output)
|
| 19 |
+
|
| 20 |
+
demo.launch()
|