Swathi6 commited on
Commit
698df79
·
verified ·
1 Parent(s): 12ab480

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 Hugging Face sentiment analysis pipeline
5
+ sentiment_pipeline = pipeline("sentiment-analysis")
6
+
7
+ # Gradio interface function
8
+ def analyze_sentiment(text):
9
+ result = sentiment_pipeline(text)
10
+ label = result[0]['label']
11
+ score = result[0]['score']
12
+ return f"Sentiment: {label} (Confidence: {score:.2f})"
13
+
14
+ # Gradio App
15
+ demo = gr.Interface(fn=analyze_sentiment,
16
+ inputs=gr.Textbox(lines=2, placeholder="Enter a sentence..."),
17
+ outputs="text",
18
+ title="Sentiment Analyzer")
19
+
20
+ # Launch the Gradio app
21
+ if __name__ == "__main__":
22
+ demo.launch()