Jeffrey0216 commited on
Commit
e2a742f
·
verified ·
1 Parent(s): cbfaca9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -0
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()