saivarun04 commited on
Commit
3e526b2
·
verified ·
1 Parent(s): 8326b21

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -0
app.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+ import gradio as gr
3
+
4
+ # Load pre-trained sentiment analysis pipeline
5
+ sentiment_pipeline = pipeline("sentiment-analysis")
6
+
7
+ # Function to analyze sentiment
8
+ def analyze_sentiment(text):
9
+ results = sentiment_pipeline(text)
10
+ return {result['label']: round(result['score'], 2) for result in results}
11
+
12
+ # Gradio Interface
13
+ iface = gr.Interface(
14
+ fn=analyze_sentiment,
15
+ inputs=gr.Textbox(lines=2, placeholder="Enter a sentence here..."),
16
+ outputs=gr.Label(num_top_classes=3),
17
+ title="Sentiment Analysis",
18
+ description="Enter a sentence, and the model will classify it as Positive, Negative, or Neutral."
19
+ )
20
+
21
+ # Launch the app
22
+ iface.launch()