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(""" """, 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('
Emotion Prediction & Suggestions 🌈
', 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('
How Are You Feeling Today?
', 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('
Here Are Some Suggestions for You:
', unsafe_allow_html=True) # Suggestions st.markdown("#### Activities:") st.markdown('
', unsafe_allow_html=True) for suggestion in resources["suggestions"]: st.write(f"- {suggestion}") st.markdown('
', 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('', unsafe_allow_html=True)