razanalsulami commited on
Commit
707c991
β€’
1 Parent(s): 4bb21db

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -11
app.py CHANGED
@@ -1,15 +1,14 @@
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,12 +19,12 @@ def analyze_mood(user_input):
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()
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ # Load the 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 the input text
10
  result = sentiment_analysis(user_input)[0]
11
+ # Define mood and suggestion based on sentiment analysis
 
12
  if result["label"] == "POSITIVE":
13
  mood = "Happy"
14
  suggestion = "Keep doing what you're doing! 😊"
 
19
  mood = "Neutral"
20
  suggestion = "You're doing okay! Stay calm 🌸"
21
 
22
+ # Return mood and suggestion
23
  return "Your mood is: " + mood, suggestion
 
 
 
 
24
 
25
+ # Define Gradio interface inputs and outputs directly without the '.inputs' or '.outputs' module
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
+ # Create and launch the Gradio interface
30
  gr.Interface(fn=analyze_mood, inputs=inputs, outputs=outputs, title="Mood Analyzer").launch()