Kaiyeee commited on
Commit
ee40669
·
verified ·
1 Parent(s): 13b078a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -0
app.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load the sentiment analysis pipeline
5
+ sentiment_pipeline = pipeline("sentiment-analysis")
6
+
7
+ def analyze_sentiment(text):
8
+ result = sentiment_pipeline(text)[0] # Extract the first result
9
+ label = result["label"]
10
+ score = result["score"]
11
+ return f"Sentiment: {label} (Confidence: {score:.2f})"
12
+
13
+ # Create a Gradio interface
14
+ demo = gr.Interface(
15
+ fn=analyze_sentiment,
16
+ inputs=gr.Textbox(lines=3, placeholder="Enter a sentence..."),
17
+ outputs="text",
18
+ title="Sentiment Analysis Demo",
19
+ description="Enter text to see its sentiment (Positive/Negative) along with a confidence score.",
20
+ )
21
+
22
+ if __name__ == "__main__":
23
+ demo.launch(server_name="0.0.0.0", server_port=7860)