Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,10 @@
|
|
1 |
import streamlit as st
|
2 |
import os
|
3 |
|
|
|
|
|
|
|
|
|
4 |
# Suggestion Database
|
5 |
suggestion_database = {
|
6 |
"sadness": {
|
@@ -38,73 +42,50 @@ suggestion_database = {
|
|
38 |
},
|
39 |
}
|
40 |
|
41 |
-
# Function to
|
42 |
def get_relevant_resources(emotion):
|
43 |
-
return suggestion_database.get(emotion,
|
44 |
-
|
45 |
-
# Debugging Model Initialization
|
46 |
-
def load_emotion_model(model_path="path/to/model"):
|
47 |
-
if not os.path.exists(model_path):
|
48 |
-
st.error(f"Model file not found at {model_path}")
|
49 |
-
return None
|
50 |
|
|
|
|
|
51 |
try:
|
52 |
-
# Replace with actual model loading
|
53 |
-
|
54 |
-
|
55 |
-
|
|
|
56 |
except Exception as e:
|
57 |
-
|
58 |
return None
|
59 |
|
60 |
-
#
|
61 |
-
|
62 |
-
if model is None:
|
63 |
-
return "neutral" # Default to neutral if model failed to load
|
64 |
-
try:
|
65 |
-
# Dummy emotion analysis (replace with model prediction logic)
|
66 |
-
if "sad" in user_input.lower():
|
67 |
-
return "sadness"
|
68 |
-
elif "happy" in user_input.lower() or "joy" in user_input.lower():
|
69 |
-
return "joy"
|
70 |
-
else:
|
71 |
-
return "neutral"
|
72 |
-
except Exception as e:
|
73 |
-
st.error(f"Error during emotion analysis: {e}")
|
74 |
-
return "neutral"
|
75 |
-
|
76 |
-
# Streamlit Interface
|
77 |
-
def main():
|
78 |
-
st.title("Emotion-Based Suggestions")
|
79 |
-
|
80 |
-
# Load Model
|
81 |
-
st.sidebar.title("Model Loader")
|
82 |
-
model_path = st.sidebar.text_input("Model Path", "path/to/model")
|
83 |
-
model = load_emotion_model(model_path)
|
84 |
-
|
85 |
-
# User Input
|
86 |
-
st.header("How are you feeling today?")
|
87 |
-
user_input = st.text_input("Describe your mood in a few words:")
|
88 |
-
|
89 |
-
if user_input:
|
90 |
-
# Analyze Emotion
|
91 |
-
emotion = analyze_emotion(user_input, model)
|
92 |
-
st.subheader(f"Detected Emotion: {emotion.capitalize()}")
|
93 |
|
94 |
-
|
95 |
-
|
96 |
-
st.subheader("Suggestions for You:")
|
97 |
-
for suggestion in resources["suggestions"]:
|
98 |
-
st.write(f"- {suggestion}")
|
99 |
|
100 |
-
|
101 |
-
|
102 |
-
|
|
|
103 |
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
|
108 |
-
#
|
109 |
-
if
|
110 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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": {
|
|
|
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 |
+
# Streamlit UI
|
62 |
+
st.title("Emotion-Based Suggestions")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
|
64 |
+
# Sidebar for Model Path
|
65 |
+
model_path = st.sidebar.text_input("Enter Model Path", "path/to/model")
|
|
|
|
|
|
|
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 and try again.")
|
71 |
|
72 |
+
# Emotion Analysis Inputs
|
73 |
+
st.header("How are you feeling today?")
|
74 |
+
user_response = st.text_input("Describe your current emotion (e.g., happy, sad, neutral):", "neutral")
|
75 |
|
76 |
+
# Get Suggestions
|
77 |
+
if user_response:
|
78 |
+
resources = get_relevant_resources(user_response.lower())
|
79 |
+
st.subheader("Here are some suggestions for you:")
|
80 |
+
|
81 |
+
st.write("**Activities:**")
|
82 |
+
for suggestion in resources["suggestions"]:
|
83 |
+
st.write(f"- {suggestion}")
|
84 |
+
|
85 |
+
st.write("**Articles:**")
|
86 |
+
for article in resources["articles"]:
|
87 |
+
st.write(f"- [{article['title']}]({article['url']})")
|
88 |
+
|
89 |
+
st.write("**Videos:**")
|
90 |
+
for video in resources["videos"]:
|
91 |
+
st.write(f"- [{video['title']}]({video['url']})")
|