tarrasyed19472007 commited on
Commit
d3f714e
·
verified ·
1 Parent(s): 2da24f4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +62 -48
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
- resources = suggestion_database.get(emotion, {})
43
- return resources.get("suggestions", []), resources.get("articles", []), resources.get("videos", [])
44
 
45
- # Suggestion Logic
46
- def suggest_activity(emotion_analysis):
47
- max_emotion = max(emotion_analysis, key=emotion_analysis.get) if emotion_analysis else "neutral"
48
- suggestions, articles, videos = get_relevant_resources(max_emotion)
49
- return {
50
- "emotion": max_emotion,
51
- "suggestions": suggestions,
52
- "articles": articles,
53
- "videos": videos,
54
- }
55
 
56
- # Streamlit Interface
57
- st.title("Personalized Emotional Wellness Recommendations")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
 
59
- # Questions
60
- st.write("### How are you feeling today?")
61
- emotion_input = st.text_input("Your response (e.g., happy, sad, neutral):", "").lower()
 
 
 
 
 
62
 
63
- st.write("### Describe your mood in a few words.")
64
- mood_input = st.text_input("Your response (e.g., calm, frustrated, joyful):", "").lower()
 
 
 
 
 
 
65
 
66
- st.write("### What was the most significant emotion you felt this week?")
67
- emotion_week_input = st.text_input("Your response (e.g., sadness, joy, anxiety):", "").lower()
 
 
 
68
 
69
- # Simulated Emotion Analysis (Here, based on user input; replace with real analysis later)
70
- emotion_analysis = {
71
- "sadness": emotion_input == "sad" or emotion_week_input == "sadness",
72
- "joy": emotion_input == "happy" or emotion_week_input == "joy",
73
- "neutral": emotion_input == "neutral" or emotion_week_input == "calm",
74
- }
75
 
76
- # Analyze and Provide Suggestions
77
- if st.button("Get Suggestions"):
78
- analysis_results = {
79
- "sadness": emotion_analysis.get("sadness", 0),
80
- "joy": emotion_analysis.get("joy", 0),
81
- "neutral": emotion_analysis.get("neutral", 0),
82
- }
83
 
84
- suggestions = suggest_activity(analysis_results)
85
- st.write(f"### Detected Emotion: {suggestions['emotion'].capitalize()}")
86
- st.write("### Suggestions for You:")
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()