Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,25 +5,28 @@ from transformers import 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 |
-
|
| 9 |
# Analyze the mood from input text
|
| 10 |
result = sentiment_analysis(user_input)[0]
|
|
|
|
| 11 |
# Define mood and suggestion based on sentiment analysis
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
| 14 |
mood = "Happy"
|
| 15 |
suggestion = "Keep doing what you're doing! ๐"
|
| 16 |
-
elif result["label"] == "NEGATIVE" and score > 0.85:
|
| 17 |
mood = "Sad"
|
| 18 |
suggestion = "Try to talk to someone, or take a break ๐ก"
|
| 19 |
-
else:
|
| 20 |
-
mood = "Neutral"
|
| 21 |
-
suggestion = "You're doing okay! Stay calm ๐ธ"
|
| 22 |
|
| 23 |
# Return mood and suggestion
|
| 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 |
-
|
|
|
|
|
|
| 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
|
| 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()
|