hrishikesh commited on
Commit
1116146
·
1 Parent(s): a694697

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -0
app.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ senti_pipeline = pipeline("sentiment-analysis")
5
+
6
+ senti_pipeline("I am extremely happy to share this video with all of you")
7
+
8
+ senti_pipeline("I am sad that you haven't subscribed to my channel yet")
9
+
10
+ def sentiment_gradio(input):
11
+ result = senti_pipeline(input)
12
+ if result[0]["label"] == "POSITIVE":
13
+ pos_score = round(result[0]["score"], 2)
14
+ neg_score = 1 - pos_score
15
+ else:
16
+ neg_score = round(1*result[0]["score"], 2)
17
+ pos_score = 1 - neg_score
18
+
19
+ res = {'Positive': pos_score, 'Negative': neg_score}
20
+ return res
21
+
22
+ sentiment_analysis_interface = gr.Interface( title = 'Write a review of anything and get sentiment analysis - Built by Hrishikesh', fn = sentiment_gradio,
23
+ inputs="text",
24
+ outputs= gr.outputs.Label(num_top_classes=2),
25
+ interpretation="default")
26
+
27
+ sentiment_analysis_interface.launch(debug=True)