Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,15 +1,14 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
#
|
| 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 |
-
# 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 |
-
#
|
| 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 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|