freddyaboulton HF staff commited on
Commit
e2c7dcc
1 Parent(s): b9f212e

Add app file

Browse files
Files changed (2) hide show
  1. app.py +20 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ sentiment_classifier = pipeline("text-classification", return_all_scores=True)
5
+
6
+ def classifier(text):
7
+ pred = sentiment_classifier(text)
8
+ return {p["label"]: p["score"] for p in pred[0]}
9
+
10
+ with gr.Blocks() as demo:
11
+ with gr.Row():
12
+ with gr.Column():
13
+ input_text = gr.Textbox(label="Input Text")
14
+ with gr.Row():
15
+ classify = gr.Button("Classify Sentiment")
16
+ with gr.Column():
17
+ label = gr.Label(label="Predicted Sentiment")
18
+
19
+ classify.click(classifier, input_text, label)
20
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ torch
2
+ transformers