themanas021 commited on
Commit
1a0842b
·
1 Parent(s): 27c073d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ senti_pipeline = pipeline("sentiment-analysis")
5
+
6
+ result= senti_pipeline("I am extremely happy to share this video with all of you")
7
+ result
8
+
9
+ sentiment_label = result[0]['label']
10
+ sentiment_score = result[0]['score']
11
+
12
+ formatted_output = f"This sentiment is {sentiment_label} with the probability {sentiment_score*100:.2f}%"
13
+ print(formatted_output)
14
+
15
+ app_inputs = gr.inputs.Textbox(lines=2, placeholder="Enter title here...")
16
+
17
+ def res(app_inputs):
18
+ result= senti_pipeline(app_inputs)
19
+ sentiment_label = result[0]['label']
20
+ sentiment_score = result[0]['score']
21
+
22
+ formatted_output = f"This sentiment is {sentiment_label} with the probability {sentiment_score*100:.2f}%"
23
+ return formatted_output
24
+
25
+ interface = gr.Interface(fn=res,
26
+ inputs=app_inputs,
27
+ outputs=gr.outputs.Textbox(label="Sentiment Analysis Result"),
28
+ title="Sup, I'm a Sentiment Analyzer Babe",
29
+ description="Enter a text and see the sentiment analysis result!")
30
+
31
+ interface.launch(share=True)
32
+