Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,14 +1,69 @@
|
|
1 |
import streamlit as st
|
2 |
import os
|
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
# Debugging Logger
|
5 |
def debug_log(message):
|
6 |
-
st.text(f"DEBUG: {message}")
|
7 |
|
8 |
# Suggestion Database
|
9 |
suggestion_database = {
|
10 |
"sadness": {
|
11 |
-
"suggestions": ["Try
|
12 |
"articles": [
|
13 |
{"title": "Overcoming Sadness", "url": "https://example.com/sadness1"},
|
14 |
{"title": "Understanding Depression", "url": "https://example.com/sadness2"},
|
@@ -42,50 +97,62 @@ suggestion_database = {
|
|
42 |
},
|
43 |
}
|
44 |
|
45 |
-
# Function to Fetch Suggestions
|
46 |
def get_relevant_resources(emotion):
|
47 |
return suggestion_database.get(emotion, suggestion_database["neutral"])
|
48 |
|
49 |
# Placeholder for Model Loading
|
50 |
def load_emotion_model(model_path):
|
51 |
try:
|
52 |
-
# Placeholder logic: Replace this with actual model loading code
|
53 |
if not os.path.exists(model_path):
|
54 |
raise FileNotFoundError(f"Model file not found at {model_path}")
|
55 |
-
debug_log("Model loaded successfully
|
56 |
return "Emotion Model Placeholder"
|
57 |
except Exception as e:
|
58 |
debug_log(str(e))
|
59 |
return None
|
60 |
|
61 |
-
#
|
62 |
-
st.
|
|
|
|
|
|
|
|
|
63 |
|
64 |
-
# Sidebar for Model Path
|
65 |
-
|
|
|
66 |
|
67 |
-
# Load Model
|
68 |
emotion_model = load_emotion_model(model_path)
|
69 |
if emotion_model is None:
|
70 |
-
st.error("Model failed to load. Please check the path
|
71 |
|
72 |
-
# Emotion Analysis
|
73 |
-
st.
|
74 |
user_response = st.text_input("Describe your current emotion (e.g., happy, sad, neutral):", "neutral")
|
75 |
|
76 |
-
#
|
77 |
if user_response:
|
78 |
resources = get_relevant_resources(user_response.lower())
|
79 |
-
st.
|
80 |
-
|
81 |
-
|
|
|
|
|
82 |
for suggestion in resources["suggestions"]:
|
83 |
st.write(f"- {suggestion}")
|
84 |
-
|
85 |
-
|
|
|
|
|
86 |
for article in resources["articles"]:
|
87 |
st.write(f"- [{article['title']}]({article['url']})")
|
88 |
-
|
89 |
-
|
|
|
90 |
for video in resources["videos"]:
|
91 |
st.write(f"- [{video['title']}]({video['url']})")
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
import os
|
3 |
|
4 |
+
# Set Page Configuration
|
5 |
+
st.set_page_config(
|
6 |
+
page_title="Emotion Prediction App",
|
7 |
+
page_icon="🌟",
|
8 |
+
layout="wide",
|
9 |
+
)
|
10 |
+
|
11 |
+
# Custom CSS for Background and Styling
|
12 |
+
def add_custom_styles():
|
13 |
+
st.markdown("""
|
14 |
+
<style>
|
15 |
+
/* Background Styling */
|
16 |
+
.stApp {
|
17 |
+
background: linear-gradient(to right, #f2f7ff, #d9faff);
|
18 |
+
color: #333333;
|
19 |
+
font-family: Arial, sans-serif;
|
20 |
+
}
|
21 |
+
|
22 |
+
/* Header Styling */
|
23 |
+
.main-title {
|
24 |
+
color: #1e88e5;
|
25 |
+
text-align: center;
|
26 |
+
font-size: 3rem;
|
27 |
+
margin-top: -20px;
|
28 |
+
margin-bottom: 30px;
|
29 |
+
font-weight: bold;
|
30 |
+
}
|
31 |
+
|
32 |
+
/* Section Headers */
|
33 |
+
.section-header {
|
34 |
+
color: #0d47a1;
|
35 |
+
font-size: 1.8rem;
|
36 |
+
margin-top: 20px;
|
37 |
+
margin-bottom: 10px;
|
38 |
+
border-bottom: 2px solid #1e88e5;
|
39 |
+
}
|
40 |
+
|
41 |
+
/* Suggestions Styling */
|
42 |
+
.suggestions {
|
43 |
+
font-size: 1.1rem;
|
44 |
+
line-height: 1.6;
|
45 |
+
}
|
46 |
+
|
47 |
+
/* Footer Styling */
|
48 |
+
.footer {
|
49 |
+
text-align: center;
|
50 |
+
margin-top: 50px;
|
51 |
+
font-size: 0.9rem;
|
52 |
+
color: #555;
|
53 |
+
}
|
54 |
+
</style>
|
55 |
+
""", unsafe_allow_html=True)
|
56 |
+
|
57 |
+
add_custom_styles()
|
58 |
+
|
59 |
# Debugging Logger
|
60 |
def debug_log(message):
|
61 |
+
st.sidebar.text(f"DEBUG: {message}")
|
62 |
|
63 |
# Suggestion Database
|
64 |
suggestion_database = {
|
65 |
"sadness": {
|
66 |
+
"suggestions": ["Try guided meditation", "Take a walk in nature", "Connect with a friend"],
|
67 |
"articles": [
|
68 |
{"title": "Overcoming Sadness", "url": "https://example.com/sadness1"},
|
69 |
{"title": "Understanding Depression", "url": "https://example.com/sadness2"},
|
|
|
97 |
},
|
98 |
}
|
99 |
|
100 |
+
# Function to Fetch Relevant Suggestions
|
101 |
def get_relevant_resources(emotion):
|
102 |
return suggestion_database.get(emotion, suggestion_database["neutral"])
|
103 |
|
104 |
# Placeholder for Model Loading
|
105 |
def load_emotion_model(model_path):
|
106 |
try:
|
|
|
107 |
if not os.path.exists(model_path):
|
108 |
raise FileNotFoundError(f"Model file not found at {model_path}")
|
109 |
+
debug_log("Model loaded successfully.")
|
110 |
return "Emotion Model Placeholder"
|
111 |
except Exception as e:
|
112 |
debug_log(str(e))
|
113 |
return None
|
114 |
|
115 |
+
# Main Application Header
|
116 |
+
st.markdown('<div class="main-title">Emotion Prediction & Suggestions 🌈</div>', unsafe_allow_html=True)
|
117 |
+
st.markdown("""
|
118 |
+
This app is designed to help you discover activities, articles, and videos tailored to your emotional state.
|
119 |
+
Simply describe how you're feeling, and let us provide uplifting and insightful suggestions.
|
120 |
+
""")
|
121 |
|
122 |
+
# Sidebar for Model Path Input
|
123 |
+
st.sidebar.header("Emotion Model Configuration")
|
124 |
+
model_path = st.sidebar.text_input("Enter the Path to the Emotion Prediction Model", "path/to/model")
|
125 |
|
126 |
+
# Load Emotion Prediction Model
|
127 |
emotion_model = load_emotion_model(model_path)
|
128 |
if emotion_model is None:
|
129 |
+
st.sidebar.error("Model failed to load. Please check the path or contact support.")
|
130 |
|
131 |
+
# Emotion Analysis Section
|
132 |
+
st.markdown('<div class="section-header">How Are You Feeling Today?</div>', unsafe_allow_html=True)
|
133 |
user_response = st.text_input("Describe your current emotion (e.g., happy, sad, neutral):", "neutral")
|
134 |
|
135 |
+
# Display Suggestions
|
136 |
if user_response:
|
137 |
resources = get_relevant_resources(user_response.lower())
|
138 |
+
st.markdown('<div class="section-header">Here Are Some Suggestions for You:</div>', unsafe_allow_html=True)
|
139 |
+
|
140 |
+
# Suggestions
|
141 |
+
st.markdown("#### Activities:")
|
142 |
+
st.markdown('<div class="suggestions">', unsafe_allow_html=True)
|
143 |
for suggestion in resources["suggestions"]:
|
144 |
st.write(f"- {suggestion}")
|
145 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
146 |
+
|
147 |
+
# Articles
|
148 |
+
st.markdown("#### Articles:")
|
149 |
for article in resources["articles"]:
|
150 |
st.write(f"- [{article['title']}]({article['url']})")
|
151 |
+
|
152 |
+
# Videos
|
153 |
+
st.markdown("#### Videos:")
|
154 |
for video in resources["videos"]:
|
155 |
st.write(f"- [{video['title']}]({video['url']})")
|
156 |
+
|
157 |
+
# Footer
|
158 |
+
st.markdown('<div class="footer">Crafted with ❤️ by Your Emotion App Team</div>', unsafe_allow_html=True)
|