razanalsulami commited on
Commit
4bb21db
β€’
1 Parent(s): 21c7d19

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -9
app.py CHANGED
@@ -1,15 +1,15 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- # pipeline
5
  sentiment_analysis = pipeline("sentiment-analysis", model="distilbert/distilbert-base-uncased-finetuned-sst-2-english")
6
 
7
- # this takes user input and analyzes mood
8
  def analyze_mood(user_input):
9
- # Analyze input text
10
  result = sentiment_analysis(user_input)[0]
11
 
12
- # Set the mood
13
  if result["label"] == "POSITIVE":
14
  mood = "Happy"
15
  suggestion = "Keep doing what you're doing! 😊"
@@ -20,11 +20,12 @@ def analyze_mood(user_input):
20
  mood = "Neutral"
21
  suggestion = "You're doing okay! Stay calm 🌸"
22
 
23
- # Return the mood and the suggestion for the user
24
  return "Your mood is: " + mood, suggestion
25
 
26
- inputs = gr.Textbox(label="How are you feeling today?", placeholder="Type your thoughts here...")
27
- outputs = gr.Textbox(label="Mood and Suggestion")
 
28
 
29
-
30
- 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
+ # pipeline for sentiment analysis
5
  sentiment_analysis = pipeline("sentiment-analysis", model="distilbert/distilbert-base-uncased-finetuned-sst-2-english")
6
 
7
+ # function to analyze user input and return mood and suggestion
8
  def analyze_mood(user_input):
9
+ # analyze the input text using the sentiment analysis model
10
  result = sentiment_analysis(user_input)[0]
11
 
12
+ # determine mood and provide suggestions based on the sentiment result
13
  if result["label"] == "POSITIVE":
14
  mood = "Happy"
15
  suggestion = "Keep doing what you're doing! 😊"
 
20
  mood = "Neutral"
21
  suggestion = "You're doing okay! Stay calm 🌸"
22
 
23
+ # return the mood analysis and suggestions
24
  return "Your mood is: " + mood, suggestion
25
 
26
+ # Gradio interface components
27
+ inputs = gr.inputs.Textbox(label="How are you feeling today?", placeholder="Type your thoughts here...")
28
+ outputs = gr.outputs.Textbox(label="Mood and Suggestion")
29
 
30
+ # create and launch the Gradio interface
31
+ gr.Interface(fn=analyze_mood, inputs=inputs, outputs=outputs, title="Mood Analyzer").launch()