AhmedAlyouSIF commited on
Commit
b01dbdd
·
verified ·
1 Parent(s): 24a4ce1

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
+ # Load the sentiment analysis pipeline
5
+ sentiment_pipeline = pipeline("sentiment-analysis")
6
+
7
+ def analyze_sentiment(text):
8
+ result = sentiment_pipeline(text)[0]
9
+ label = result["label"]
10
+ score = result["score"]
11
+ return f"Sentiment: {label}\nConfidence: {score:.2f}"
12
+ # Create the Gradio interface
13
+ iface = gr.Interface(
14
+ fn=analyze_sentiment,
15
+ inputs=gr.Textbox(placeholder="Enter text to analyze..."),
16
+ outputs=gr.Textbox(),
17
+ title="Sentiment Analysis App",
18
+ description="Enter a sentence to determine its sentiment (positive or negative).",
19
+ examples=[
20
+ ["I love this product! It's amazing!"],
21
+ ["I am very disappointed with the service."]
22
+ ]
23
+ )
24
+ # Launch the app
25
+ if __name__ == "__main__":
26
+ iface.launch()