geeaiml commited on
Commit
00f8d40
·
verified ·
1 Parent(s): 77b7ba0

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -0
app.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+ # Load the sentiment analysis pipeline
4
+ sentiment_pipeline = pipeline("sentiment-analysis")
5
+ def analyze_sentiment(text):
6
+ result = sentiment_pipeline(text)[0]
7
+ label = result["label"]
8
+ score = result["score"]
9
+ return f"Sentiment: {label}\nConfidence: {score:.2f}"
10
+ # Create the Gradio interface
11
+ iface = gr.Interface(
12
+ fn=analyze_sentiment,
13
+ inputs=gr.Textbox(placeholder="Enter text to analyze..."),
14
+ outputs=gr.Textbox(),
15
+ title="Sentiment Analysis App",
16
+ description="Enter a sentence to determine its sentiment (positive or negative).",
17
+ examples=[
18
+ ["I love this product! It's amazing!"],
19
+ ["I am very disappointed with the service."]
20
+ ]
21
+ )
22
+ import gradio as gr
23
+ from transformers import pipeline
24
+ # Load the sentiment analysis pipeline
25
+ sentiment_pipeline = pipeline("sentiment-analysis")
26
+ def analyze_sentiment(text):
27
+ result = sentiment_pipeline(text)[0]
28
+ label = result["label"]
29
+ score = result["score"]
30
+ return f"Sentiment: {label}\nConfidence: {score:.2f}"
31
+ # Create the Gradio interface
32
+ iface = gr.Interface(
33
+ fn=analyze_sentiment,
34
+ inputs=gr.Textbox(placeholder="Enter text to analyze..."),
35
+ outputs=gr.Textbox(),
36
+ title="Sentiment Analysis App",
37
+ description="Enter a sentence to determine its sentiment (positive or negative).",
38
+ examples=[
39
+ ["I love this product! It's amazing!"],
40
+ ["I am very disappointed with the service."]
41
+ ]
42
+ )
43
+ # Launch the app
44
+ if __name__ == "__main__":
45
+ iface.launch()