tarrasyed19472007's picture
Update app.py
aac8809 verified
raw
history blame
3.93 kB
import streamlit as st
from transformers import pipeline
# Load the emotion analysis pipeline using an open-access model
emotion_analyzer = pipeline(
"text-classification",
model="j-hartmann/emotion-english-distilroberta-base"
)
# App title and description
st.set_page_config(page_title="Hawaii Emotion Wellness", layout="centered", page_icon="🌴")
st.markdown(
"""
<style>
body {
background-color: #E0F7FA;
color: #004D40;
}
.main-header {
font-size: 36px;
font-weight: bold;
text-align: center;
margin-bottom: 10px;
}
.sub-header {
font-size: 18px;
text-align: center;
margin-bottom: 20px;
}
.suggestion-card {
background-color: #B2EBF2;
padding: 15px;
border-radius: 8px;
margin-bottom: 15px;
}
</style>
""",
unsafe_allow_html=True,
)
st.markdown('<div class="main-header">🌺 Hawaii Emotion Wellness App 🌴</div>', unsafe_allow_html=True)
st.markdown('<div class="sub-header">Understand your emotions and find the right balance in paradise.</div>', unsafe_allow_html=True)
# Step 1: Collect user's responses
st.markdown("### Answer these three questions to get started:")
questions = [
"How are you feeling right now? (e.g., stressed, happy, sad)",
"What is the most pressing issue on your mind currently?",
"On a scale of 1-10, how motivated do you feel to take care of yourself today?",
]
responses = []
for question in questions:
response = st.text_input(question)
responses.append(response)
# Analyze the emotions if the user has answered all questions
if st.button("Analyze Emotions"):
if all(responses):
# Aggregate responses into a single input for emotion analysis
aggregated_response = " ".join(responses)
emotion_results = emotion_analyzer(aggregated_response)
# Get the most likely emotion
predicted_emotion = emotion_results[0]["label"]
st.markdown(f"### Your Predicted Emotion: **{predicted_emotion}** 🎭")
# Provide well-being suggestions
st.markdown("### Here's what we recommend for you:")
suggestions = {
"joy": [
{"activity": "Go for a walk on the beach", "url": "https://www.hawaiibeachwalks.com"},
{"activity": "Try a short surfing session", "url": "https://www.learnsurf.com"},
{"activity": "Join a hula dancing class", "url": "https://www.hulahawaii.com"},
],
"sadness": [
{"activity": "Practice deep breathing for 5 minutes", "url": "https://www.breathingexercise.com"},
{"activity": "Watch a calming ocean video", "url": "https://www.youtube.com/watch?v=lM02vNMRRB0"},
{"activity": "Do a quick yoga session", "url": "https://www.doyogawithme.com"},
],
# Add more emotions as needed
}
user_suggestions = suggestions.get(predicted_emotion.lower(), [])
if user_suggestions:
for suggestion in user_suggestions:
st.markdown(
f"""
<div class="suggestion-card">
<strong>{suggestion['activity']}</strong>
<br>
<a href="{suggestion['url']}" target="_blank">Learn More</a>
</div>
""",
unsafe_allow_html=True,
)
else:
st.markdown("Stay positive! Enjoy the aloha spirit and take a deep breath.")
else:
st.warning("Please answer all the questions to analyze your emotions.")
# Footer
st.markdown("---")
st.markdown(
"Built with ❀️ for the Hawaii Hackathon 2024 by [Your Team Name]. Deployed on Hugging Face Spaces."
)