Spaces:
Sleeping
Sleeping
File size: 1,101 Bytes
3c3ff47 65f5aa2 3c3ff47 b6919df 65f5aa2 3c3ff47 b6919df 4a094f8 65f5aa2 4a094f8 b6919df 65f5aa2 e2ad6e1 b6919df 65f5aa2 e2ad6e1 b6919df e2ad6e1 3c3ff47 b6919df 847203c 3c3ff47 707c991 93b7ce0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
import gradio as gr
from transformers import pipeline
# Load pre-trained sentiment analysis model
sentiment_analysis = pipeline("sentiment-analysis", model="distilbert/distilbert-base-uncased-finetuned-sst-2-english")
# analyze user's mood from text
def analyze_mood(user_input):
result = sentiment_analysis(user_input)[0]
# assign mood based on sentiment
if result["label"] == "POSITIVE":
mood = "Happy"
suggestion = "Keep enjoying your day π"
elif result["label"] == "NEGATIVE":
mood = "Sad"
suggestion = "Try playing a game you like or practice some deep breathing exercises it might help!π"
else:
mood = "Neutral"
suggestion = "You're doing well! Stay calm πΈ"
# Output mood and suggestion
return "Your mood is " + mood + ". " + suggestion
inputs = gr.Textbox(label="How are you feeling today?", placeholder="Type your thoughts here...")
outputs = gr.Textbox(label="Mood and Suggestion")
gr.Interface(fn=analyze_mood, inputs=inputs, outputs=outputs, title="Mood Analyzer with Suggestions").launch()
|