Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,32 +1,28 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
# Load sentiment analysis
|
| 5 |
sentiment_analysis = pipeline("sentiment-analysis", model="distilbert/distilbert-base-uncased-finetuned-sst-2-english")
|
| 6 |
|
| 7 |
-
#
|
| 8 |
def analyze_mood(user_input):
|
| 9 |
-
# Analyze the mood from input text
|
| 10 |
result = sentiment_analysis(user_input)[0]
|
| 11 |
|
| 12 |
-
#
|
| 13 |
-
|
| 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"
|
| 21 |
mood = "Sad"
|
| 22 |
suggestion = "Try to talk to someone, or take a break π‘"
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
#
|
| 25 |
-
return "Your mood is
|
| 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 |
-
|
| 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()
|
|
|