ProfAKJ commited on
Commit
f44a133
·
verified ·
1 Parent(s): 14357b5

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -0
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ classifier = pipeline('sentiment-analysis', model='distilbert/distilbert-base-uncased-finetuned-sst-2-english')
5
+
6
+
7
+ def analyze_sentiment(text):
8
+ result = classifier(text)
9
+ # The result is a list of dictionaries, e.g., [{'label': 'POSITIVE', 'score': 0.9998}]
10
+ # We extract the label and score for better presentation.
11
+ sentiment_label = result[0]['label']
12
+ sentiment_score = result[0]['score']
13
+ return f"Sentiment: {sentiment_label}, Score: {sentiment_score:.2f}"
14
+
15
+ # Create and launch the Gradio interface
16
+ iface = gr.Interface(
17
+ fn=analyze_sentiment,
18
+ inputs='text',
19
+ outputs='text',
20
+ title='Sentiment Analysis Application',
21
+ description='Enter text to get its sentiment (positive/negative) and score.'
22
+ )
23
+
24
+
25
+ # Launch the interface
26
+ iface.launch()