Spaces:
Sleeping
Sleeping
el-filatova
commited on
Commit
•
2e8011b
1
Parent(s):
b22e92c
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
from transformers import pipeline
|
4 |
classifier = pipeline('text-classification', model='el-filatova/clasificador-tweet-sentiment')
|
5 |
|
6 |
def predict(text):
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
iface = gr.Interface(fn=predict, inputs=[gr.Textbox(value="ah, what a pang of aching sharp surprise")], outputs="text")
|
10 |
-
iface.launch()
|
|
|
|
|
|
|
|
|
|
1 |
+
# import gradio as gr
|
2 |
+
|
3 |
+
# from transformers import pipeline
|
4 |
+
# classifier = pipeline('text-classification', model='el-filatova/clasificador-tweet-sentiment')
|
5 |
+
|
6 |
+
# def predict(text):
|
7 |
+
# return classifier(text)
|
8 |
+
|
9 |
+
# iface = gr.Interface(fn=predict, inputs=[gr.Textbox(value="ah, what a pang of aching sharp surprise")], outputs="text")
|
10 |
+
# iface.launch()
|
11 |
+
|
12 |
import gradio as gr
|
13 |
|
14 |
from transformers import pipeline
|
15 |
classifier = pipeline('text-classification', model='el-filatova/clasificador-tweet-sentiment')
|
16 |
|
17 |
def predict(text):
|
18 |
+
prediction = classifier(text)
|
19 |
+
score = int(round(prediction[0]['score'] * 100))
|
20 |
+
|
21 |
+
if prediction[0]['label'] == "LABEL_0":
|
22 |
+
output = f"This tweet carries a negative sentiment with a confidence level of {score}%."
|
23 |
+
elif prediction[0]['label'] == "LABEL_1":
|
24 |
+
output = f"This tweet carries a neutral sentiment with a confidence level of {score}%."
|
25 |
+
else:
|
26 |
+
output = f"This tweet carries a positive sentiment with a confidence level of {score}%."
|
27 |
+
|
28 |
+
return output
|
29 |
+
|
30 |
|
31 |
iface = gr.Interface(fn=predict, inputs=[gr.Textbox(value="ah, what a pang of aching sharp surprise")], outputs="text")
|
32 |
+
iface.launch()
|
33 |
+
|
34 |
+
|
35 |
+
|
36 |
+
|