Babyloncoder commited on
Commit
155b172
Β·
verified Β·
1 Parent(s): 912a3f8

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Create a sentiment-analysis classifier
5
+ classifier = pipeline("sentiment-analysis")
6
+
7
+ def sentiment_analysis(sentence1, sentence2, sentence3):
8
+ sentences = [sentence1, sentence2, sentence3]
9
+ # Perform sentiment analysis on each sentence
10
+ results = classifier(sentences)
11
+ # Formatting the output with emojis
12
+ output = []
13
+ for sentence, result in zip(sentences, results):
14
+ emoji = '😊' if result['label'] == 'POSITIVE' else '😞'
15
+ output.append(f"Sentence: '{sentence}' - Label: {result['label']} {emoji}, Score: {round(result['score'], 4)}")
16
+ return "\n".join(output)
17
+
18
+ # Create a Gradio interface with three text inputs
19
+ interface = gr.Interface(
20
+ fn=sentiment_analysis,
21
+ inputs=["text", "text", "text"],
22
+ outputs="text",
23
+ title="Sentiment Analysis",
24
+ description="Enter three separate sentences to check their sentiments. An emoji will indicate the sentiment."
25
+ )
26
+
27
+ # Launch the interface
28
+ interface.launch()