Spaces:
Sleeping
Sleeping
File size: 5,674 Bytes
72fce14 d3f714e dfe4a9e c94affa 4b344bf c94affa 4b344bf 2da24f4 bebf7e5 c94affa bebf7e5 5f72fbb bebf7e5 5f72fbb 2da24f4 bebf7e5 c94affa bebf7e5 4b344bf 33842b1 4b344bf d3f714e 4b344bf c94affa 4b344bf d3f714e 4b344bf d3f714e c94affa 33842b1 c94affa 5f72fbb c94affa 4b344bf c94affa 5f72fbb c94affa 4b344bf dc7db49 c94affa 4b344bf c94affa 4b344bf c94affa 4b344bf c94affa 4b344bf c94affa |
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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
import streamlit as st
import os
# Set Page Configuration
st.set_page_config(
page_title="Emotion Prediction App",
page_icon="🌟",
layout="wide",
)
# Custom CSS for Background and Styling
def add_custom_styles():
st.markdown("""
<style>
/* Background Styling */
.stApp {
background: linear-gradient(to right, #f2f7ff, #d9faff);
color: #333333;
font-family: Arial, sans-serif;
}
/* Header Styling */
.main-title {
color: #1e88e5;
text-align: center;
font-size: 3rem;
margin-top: -20px;
margin-bottom: 30px;
font-weight: bold;
}
/* Section Headers */
.section-header {
color: #0d47a1;
font-size: 1.8rem;
margin-top: 20px;
margin-bottom: 10px;
border-bottom: 2px solid #1e88e5;
}
/* Suggestions Styling */
.suggestions {
font-size: 1.1rem;
line-height: 1.6;
}
/* Footer Styling */
.footer {
text-align: center;
margin-top: 50px;
font-size: 0.9rem;
color: #555;
}
</style>
""", unsafe_allow_html=True)
add_custom_styles()
# Debugging Logger
def debug_log(message):
st.sidebar.text(f"DEBUG: {message}")
# Suggestion Database
suggestion_database = {
"sadness": {
"suggestions": ["Try guided meditation", "Take a walk in nature", "Connect with a friend"],
"articles": [
{"title": "Overcoming Sadness", "url": "https://example.com/sadness1"},
{"title": "Understanding Depression", "url": "https://example.com/sadness2"},
],
"videos": [
{"title": "Mindfulness for Sadness", "url": "https://www.youtube.com/watch?v=sadnessvideo1"},
{"title": "Coping with Grief", "url": "https://www.youtube.com/watch?v=sadnessvideo2"},
],
},
"joy": {
"suggestions": ["Practice gratitude", "Engage in a hobby", "Spend time with loved ones"],
"articles": [
{"title": "The Benefits of Joy", "url": "https://example.com/joy1"},
{"title": "Maintaining Positive Emotions", "url": "https://example.com/joy2"},
],
"videos": [
{"title": "Boosting Your Happiness", "url": "https://www.youtube.com/watch?v=joyvideo1"},
{"title": "Practicing Gratitude", "url": "https://www.youtube.com/watch?v=joyvideo2"},
],
},
"neutral": {
"suggestions": ["Take a break", "Engage in a relaxing activity", "Spend time in nature"],
"articles": [
{"title": "Importance of Self-Care", "url": "https://example.com/selfcare1"},
{"title": "Stress Management Techniques", "url": "https://example.com/stress1"},
],
"videos": [
{"title": "Relaxation Techniques", "url": "https://www.youtube.com/watch?v=relaxvideo1"},
{"title": "Mindfulness Exercises", "url": "https://www.youtube.com/watch?v=mindfulnessvideo1"},
],
},
}
# Function to Fetch Relevant Suggestions
def get_relevant_resources(emotion):
return suggestion_database.get(emotion, suggestion_database["neutral"])
# Placeholder for Model Loading
def load_emotion_model(model_path):
try:
if not os.path.exists(model_path):
raise FileNotFoundError(f"Model file not found at {model_path}")
debug_log("Model loaded successfully.")
return "Emotion Model Placeholder"
except Exception as e:
debug_log(str(e))
return None
# Main Application Header
st.markdown('<div class="main-title">Emotion Prediction & Suggestions 🌈</div>', unsafe_allow_html=True)
st.markdown("""
This app is designed to help you discover activities, articles, and videos tailored to your emotional state.
Simply describe how you're feeling, and let us provide uplifting and insightful suggestions.
""")
# Sidebar for Model Path Input
st.sidebar.header("Emotion Model Configuration")
model_path = st.sidebar.text_input("Enter the Path to the Emotion Prediction Model", "path/to/model")
# Load Emotion Prediction Model
emotion_model = load_emotion_model(model_path)
if emotion_model is None:
st.sidebar.error("Model failed to load. Please check the path or contact support.")
# Emotion Analysis Section
st.markdown('<div class="section-header">How Are You Feeling Today?</div>', unsafe_allow_html=True)
user_response = st.text_input("Describe your current emotion (e.g., happy, sad, neutral):", "neutral")
# Display Suggestions
if user_response:
resources = get_relevant_resources(user_response.lower())
st.markdown('<div class="section-header">Here Are Some Suggestions for You:</div>', unsafe_allow_html=True)
# Suggestions
st.markdown("#### Activities:")
st.markdown('<div class="suggestions">', unsafe_allow_html=True)
for suggestion in resources["suggestions"]:
st.write(f"- {suggestion}")
st.markdown('</div>', unsafe_allow_html=True)
# Articles
st.markdown("#### Articles:")
for article in resources["articles"]:
st.write(f"- [{article['title']}]({article['url']})")
# Videos
st.markdown("#### Videos:")
for video in resources["videos"]:
st.write(f"- [{video['title']}]({video['url']})")
# Footer
st.markdown('<div class="footer">Crafted with ❤️ by Your Emotion App Team</div>', unsafe_allow_html=True)
|