Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import streamlit as st
|
|
|
2 |
|
3 |
# Suggestion Database
|
4 |
suggestion_database = {
|
@@ -37,60 +38,73 @@ suggestion_database = {
|
|
37 |
},
|
38 |
}
|
39 |
|
40 |
-
# Function to fetch resources
|
41 |
def get_relevant_resources(emotion):
|
42 |
-
|
43 |
-
return resources.get("suggestions", []), resources.get("articles", []), resources.get("videos", [])
|
44 |
|
45 |
-
#
|
46 |
-
def
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
"emotion": max_emotion,
|
51 |
-
"suggestions": suggestions,
|
52 |
-
"articles": articles,
|
53 |
-
"videos": videos,
|
54 |
-
}
|
55 |
|
56 |
-
|
57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
|
59 |
-
#
|
60 |
-
|
61 |
-
|
|
|
|
|
|
|
|
|
|
|
62 |
|
63 |
-
|
64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
|
66 |
-
|
67 |
-
|
|
|
|
|
|
|
68 |
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
"joy": emotion_input == "happy" or emotion_week_input == "joy",
|
73 |
-
"neutral": emotion_input == "neutral" or emotion_week_input == "calm",
|
74 |
-
}
|
75 |
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
"sadness": emotion_analysis.get("sadness", 0),
|
80 |
-
"joy": emotion_analysis.get("joy", 0),
|
81 |
-
"neutral": emotion_analysis.get("neutral", 0),
|
82 |
-
}
|
83 |
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
for suggestion in suggestions["suggestions"]:
|
88 |
-
st.write(f"- {suggestion}")
|
89 |
-
|
90 |
-
st.write("### Articles to Explore:")
|
91 |
-
for article in suggestions["articles"]:
|
92 |
-
st.markdown(f"[{article['title']}]({article['url']})")
|
93 |
-
|
94 |
-
st.write("### Videos to Watch:")
|
95 |
-
for video in suggestions["videos"]:
|
96 |
-
st.markdown(f"[{video['title']}]({video['url']})")
|
|
|
1 |
import streamlit as st
|
2 |
+
import os
|
3 |
|
4 |
# Suggestion Database
|
5 |
suggestion_database = {
|
|
|
38 |
},
|
39 |
}
|
40 |
|
41 |
+
# Function to fetch relevant resources
|
42 |
def get_relevant_resources(emotion):
|
43 |
+
return suggestion_database.get(emotion, {"suggestions": [], "articles": [], "videos": []})
|
|
|
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 logic
|
53 |
+
model = "Dummy model loaded"
|
54 |
+
st.success("Model loaded successfully!")
|
55 |
+
return model
|
56 |
+
except Exception as e:
|
57 |
+
st.error(f"Error loading model: {e}")
|
58 |
+
return None
|
59 |
+
|
60 |
+
# Analyze User Input and Provide Suggestions
|
61 |
+
def analyze_emotion(user_input, model):
|
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 |
+
# Fetch and Display Suggestions
|
95 |
+
resources = get_relevant_resources(emotion)
|
96 |
+
st.subheader("Suggestions for You:")
|
97 |
+
for suggestion in resources["suggestions"]:
|
98 |
+
st.write(f"- {suggestion}")
|
99 |
|
100 |
+
st.subheader("Articles to Explore:")
|
101 |
+
for article in resources["articles"]:
|
102 |
+
st.write(f"- [{article['title']}]({article['url']})")
|
|
|
|
|
|
|
103 |
|
104 |
+
st.subheader("Videos to Watch:")
|
105 |
+
for video in resources["videos"]:
|
106 |
+
st.write(f"- [{video['title']}]({video['url']})")
|
|
|
|
|
|
|
|
|
107 |
|
108 |
+
# Run the App
|
109 |
+
if __name__ == "__main__":
|
110 |
+
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|