File size: 1,225 Bytes
2e8011b
 
 
 
 
 
 
 
 
 
 
af76cb7
 
13cba8b
 
af76cb7
13cba8b
2e8011b
 
 
 
 
 
 
 
 
844a9b2
13cba8b
e6ae364
8d8212a
2e8011b
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# import gradio as gr

# from transformers import pipeline
# classifier = pipeline('text-classification', model='el-filatova/clasificador-tweet-sentiment')

# def predict(text):
#     return classifier(text)

# iface = gr.Interface(fn=predict, inputs=[gr.Textbox(value="ah, what a pang of aching sharp surprise")], outputs="text")
# iface.launch()

import gradio as gr

from transformers import pipeline
classifier = pipeline('text-classification', model='el-filatova/clasificador-tweet-sentiment')

def predict(text):
    prediction = classifier(text)
    score = int(round(prediction[0]['score'] * 100))
    
    if prediction[0]['label'] == "LABEL_0":
        output = f"This tweet carries a negative sentiment with a confidence level of {score}%."
    elif prediction[0]['label'] == "LABEL_1":
        output = f"This tweet carries a neutral sentiment with a confidence level of {score}%."
    else:
        output = f"This tweet carries a positive sentiment with a confidence level of {score}%."
    return output   

iface = gr.Interface(fn=predict, inputs=[gr.Textbox(value="The feedback received was generally constructive with some areas for improvement highlighted.")], outputs="text")
iface.launch(share=True)