Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
#
|
8 |
def analyze_mood(user_input):
|
9 |
-
#
|
10 |
result = sentiment_analysis(user_input)[0]
|
11 |
|
12 |
-
#
|
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 |
-
#
|
24 |
return "Your mood is: " + mood, suggestion
|
25 |
|
26 |
-
|
27 |
-
|
|
|
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()
|