File size: 1,033 Bytes
1116146
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from transformers import pipeline

senti_pipeline = pipeline("sentiment-analysis")

senti_pipeline("I am extremely happy to share this video with all of you")

senti_pipeline("I am sad that you haven't subscribed to my channel yet")

def sentiment_gradio(input):
    result = senti_pipeline(input)
    if result[0]["label"] == "POSITIVE":
        pos_score = round(result[0]["score"], 2)
        neg_score = 1 - pos_score
    else:
        neg_score = round(1*result[0]["score"], 2)
        pos_score = 1 - neg_score

    res = {'Positive': pos_score, 'Negative': neg_score}
    return res

sentiment_analysis_interface = gr.Interface( title = 'Write a review of anything and get sentiment analysis - Built by Hrishikesh', fn = sentiment_gradio,
                                            inputs="text",
                                            outputs= gr.outputs.Label(num_top_classes=2),
                                            interpretation="default")

sentiment_analysis_interface.launch(debug=True)