razanalsulami commited on
Commit
b6919df
β€’
1 Parent(s): 18faac8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -15
app.py CHANGED
@@ -1,32 +1,28 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- # Load sentiment analysis pipeline
5
  sentiment_analysis = pipeline("sentiment-analysis", model="distilbert/distilbert-base-uncased-finetuned-sst-2-english")
6
 
7
- # Function to analyze user's mood based on input
8
  def analyze_mood(user_input):
9
- # Analyze the mood from input text
10
  result = sentiment_analysis(user_input)[0]
11
 
12
- # Define mood and suggestion based on sentiment analysis
13
- mood = "Neutral" # Default mood
14
- suggestion = "You're doing okay! Stay calm 🌸" # Default suggestion
15
-
16
- # Adjust mood based on analysis
17
- if result["label"] == "POSITIVE" and result["score"] > 0.85:
18
  mood = "Happy"
19
  suggestion = "Keep doing what you're doing! 😊"
20
- elif result["label"] == "NEGATIVE" and result["score"] > 0.85:
21
  mood = "Sad"
22
  suggestion = "Try to talk to someone, or take a break πŸ’‘"
 
 
 
23
 
24
- # Return mood and suggestion without parentheses and quotes
25
- return "Your mood is: " + mood + ". " + suggestion
26
 
27
- # Set up Gradio inputs and outputs
28
  inputs = gr.Textbox(label="How are you feeling today?", placeholder="Type your thoughts here...")
29
  outputs = gr.Textbox(label="Mood and Suggestion")
30
 
31
- # Launch the Gradio interface
32
- gr.Interface(fn=analyze_mood, inputs=inputs, outputs=outputs, title="Mood Analyzer").launch()
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ # Load pre-trained sentiment analysis model
5
  sentiment_analysis = pipeline("sentiment-analysis", model="distilbert/distilbert-base-uncased-finetuned-sst-2-english")
6
 
7
+ # analyze user's mood from text
8
  def analyze_mood(user_input):
 
9
  result = sentiment_analysis(user_input)[0]
10
 
11
+ # assign mood based on sentiment
12
+ if result["label"] == "POSITIVE":
 
 
 
 
13
  mood = "Happy"
14
  suggestion = "Keep doing what you're doing! 😊"
15
+ elif result["label"] == "NEGATIVE":
16
  mood = "Sad"
17
  suggestion = "Try to talk to someone, or take a break πŸ’‘"
18
+ else:
19
+ mood = "Neutral"
20
+ suggestion = "You're doing okay! Stay calm 🌸"
21
 
22
+ # Output mood and suggestion
23
+ return "Your mood is " + mood, suggestion
24
 
 
25
  inputs = gr.Textbox(label="How are you feeling today?", placeholder="Type your thoughts here...")
26
  outputs = gr.Textbox(label="Mood and Suggestion")
27
 
28
+ gr.Interface(fn=analyze_mood, inputs=inputs, outputs=outputs, title="Mood Analyzer").launch()