Commit
•
6fdd656
1
Parent(s):
7cd8530
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
|
|
3 |
|
4 |
sentiment_classifier = pipeline("text-classification", return_all_scores=True)
|
5 |
|
@@ -7,6 +8,10 @@ def classifier(text):
|
|
7 |
pred = sentiment_classifier(text)
|
8 |
return {p["label"]: p["score"] for p in pred[0]}
|
9 |
|
|
|
|
|
|
|
|
|
10 |
with gr.Blocks(theme="gstaff/xkcd") as demo:
|
11 |
with gr.Row():
|
12 |
with gr.Column():
|
@@ -15,6 +20,8 @@ with gr.Blocks(theme="gstaff/xkcd") as demo:
|
|
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(enable_queue=False)
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
+
import time
|
4 |
|
5 |
sentiment_classifier = pipeline("text-classification", return_all_scores=True)
|
6 |
|
|
|
8 |
pred = sentiment_classifier(text)
|
9 |
return {p["label"]: p["score"] for p in pred[0]}
|
10 |
|
11 |
+
def sleep_for_test():
|
12 |
+
time.sleep(10)
|
13 |
+
return 2
|
14 |
+
|
15 |
with gr.Blocks(theme="gstaff/xkcd") as demo:
|
16 |
with gr.Row():
|
17 |
with gr.Column():
|
|
|
20 |
classify = gr.Button("Classify Sentiment")
|
21 |
with gr.Column():
|
22 |
label = gr.Label(label="Predicted Sentiment")
|
23 |
+
number = gr.Number()
|
24 |
+
btn = gr.Button("Sleep then print")
|
25 |
+
btn.click(sleep_for_test, None, number)
|
26 |
classify.click(classifier, input_text, label)
|
27 |
demo.launch(enable_queue=False)
|