Skip to content

Commit f5ae982

Browse files
Merge branch 'main' into emoji-mood-selector
2 parents 88aa436 + c582a09 commit f5ae982

File tree

10 files changed

+143
-52
lines changed

10 files changed

+143
-52
lines changed

App.png

-790 KB
Binary file not shown.

README.md

Lines changed: 60 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,18 @@
1515
* Gemini-powered chatbot for mental health companionship
1616
* Empathetic and encouraging tone—never clinical or diagnostic
1717
* Smart conversation history with multi-threaded support
18-
* Chatbot personality tone selector
19-
18+
* **Chatbot personality tone selector**:
19+
*Compassionate Listener*, *Motivating Coach*, *Wise Friend*, *Neutral Therapist*, *Mindfulness Guide*
20+
2021
### 📘 Resource & Crisis Help
2122

23+
* Emergency Help Button — instantly access local support via Google Maps
24+
* International helpline directory and global mental health resources
2225
* Mental health resource library with live search
23-
* International emergency contacts and helpline shortcuts
24-
* Quick access to location-based therapy centers via Google Maps
26+
27+
### 🧪 Science-Backed Assessments
28+
29+
* Integrated **PsyToolkit**-verified mental health quizzes for self-evaluation
2530

2631
### 💖 Mood Tracking & Journaling
2732

@@ -34,42 +39,60 @@
3439
* Instant-start suggestions like “Feeling overwhelmed” or “How to manage stress?”
3540
* Direct conversion of journal thoughts into chatbot prompts
3641

37-
### 🎨 Clean, Minimal UI
42+
### 🎨 Themes & UI
3843

39-
* Sidebar toggling for focus-driven interaction
40-
* 3D-inspired soft pink and magenta UI, best suited for a mentally soothing and peaceful outlook
44+
* Multiple soothing themes: **Light**, **Calm Blue**, **Mint**, **Lavender**, **Pink**, and **Dark**
45+
* 3D-inspired soft pink and magenta UI for a mentally soothing experience
4146
* Smooth transitions and responsive design for mobile and desktop
4247

4348
---
4449

4550
## 🚀 Live Demo
4651

47-
Experience TalkHeal live here:
48-
👉 [![**TalkHeal**](https://img.shields.io/badge/View-Live%20Demo-brightgreen?style=for-the-badge)](https://www.google.com/search?q=https://TalkHeal.streamlit.app)
49-
50-
<div align="center">
51-
<p>
52-
53-
[![Open Source Love svg1](https://badges.frapsoft.com/os/v1/open-source.svg?v=103)](https://github.com/ellerbrock/open-source-badges/)
54-
![PRs Welcome](https://img.shields.io/badge/PRs-Welcome-brightgreen.svg?style=flat)
55-
![Visitors](https://api.visitorbadge.io/api/Visitors?path=eccentriccoder01%2FTalkHeal%20&countColor=%23263759&style=flat)
56-
![GitHub Forks](https://img.shields.io/github/forks/eccentriccoder01/TalkHeal)
57-
![GitHub Repo Stars](https://img.shields.io/github/stars/eccentriccoder01/TalkHeal)
58-
![GitHub Contributors](https://img.shields.io/github/contributors/eccentriccoder01/TalkHeal)
59-
![GitHub Last Commit](https://img.shields.io/github/last-commit/eccentriccoder01/TalkHeal)
60-
![GitHub Repo Size](https://img.shields.io/github/repo-size/eccentriccoder01/TalkHeal)
61-
![GitHub Total Lines](https://sloc.xyz/github/eccentriccoder01/TalkHeal)
62-
![Github](https://img.shields.io/github/license/eccentriccoder01/TalkHeal)
63-
![GitHub Issues](https://img.shields.io/github/issues/eccentriccoder01/TalkHeal)
64-
![GitHub Closed Issues](https://img.shields.io/github/issues-closed-raw/eccentriccoder01/TalkHeal)
65-
![GitHub Pull Requests](https://img.shields.io/github/issues-pr/eccentriccoder01/TalkHeal)
66-
![GitHub Closed Pull Requests](https://img.shields.io/github/issues-pr-closed/eccentriccoder01/TalkHeal)
67-
</p>
68-
</div>
52+
### 🎯 **Experience TalkHeal live now!**
53+
🔗 [https://TalkHeal.streamlit.app](https://TalkHeal.streamlit.app)
54+
55+
---
56+
57+
## 📊 Project Stats
58+
59+
<p align="center">
60+
<a href="https://github.com/eccentriccoder01/TalkHeal">
61+
<img alt="GitHub Stars" src="https://img.shields.io/github/stars/eccentriccoder01/TalkHeal?style=flat-square" />
62+
</a>
63+
<a href="https://github.com/eccentriccoder01/TalkHeal/fork">
64+
<img alt="GitHub Forks" src="https://img.shields.io/github/forks/eccentriccoder01/TalkHeal?style=flat-square" />
65+
</a>
66+
<a href="https://github.com/eccentriccoder01/TalkHeal/graphs/contributors">
67+
<img alt="Contributors" src="https://img.shields.io/github/contributors/eccentriccoder01/TalkHeal?style=flat-square" />
68+
</a>
69+
<a href="https://github.com/eccentriccoder01/TalkHeal/issues">
70+
<img alt="Open Issues" src="https://img.shields.io/github/issues/eccentriccoder01/TalkHeal?style=flat-square" />
71+
</a>
72+
<a href="https://github.com/eccentriccoder01/TalkHeal/pulls">
73+
<img alt="Open Pull Requests" src="https://img.shields.io/github/issues-pr/eccentriccoder01/TalkHeal?style=flat-square" />
74+
</a>
75+
<a href="https://github.com/eccentriccoder01/TalkHeal/commits/main">
76+
<img alt="Last Commit" src="https://img.shields.io/github/last-commit/eccentriccoder01/TalkHeal?style=flat-square" />
77+
</a>
78+
<a href="https://github.com/eccentriccoder01/TalkHeal/blob/main/LICENSE">
79+
<img alt="License" src="https://img.shields.io/github/license/eccentriccoder01/TalkHeal?style=flat-square" />
80+
</a>
81+
</p>
82+
83+
---
84+
85+
> 💡 **PRs Welcome!** We love contributions. Check out the [Contribution Guidelines](CONTRIBUTING.md) to get started.
6986
7087
## 📸 Screenshots
7188

72-
<div align="center"><img src="App.png"/></div>
89+
<div align="center">
90+
<img src="light_ss.jpg" alt="Main Screenshot" width="600"/>
91+
<br>
92+
<img src="dark_ss.jpg" width="200"/></a>
93+
<img src="blue_ss.jpg" width="200"/></a>
94+
<img src="lav_ss.jpg" width="200"/></a>
95+
</div>
7396

7497
## 📺 Video Explanation
7598

@@ -138,7 +161,6 @@ Report bugs and issues or propose improvements through our GitHub repository.
138161
- Add Screenshots and updated website links to help us understand what changes is all about.
139162

140163
- Check the [CONTRIBUTING.md](CONTRIBUTING.md) for detailed steps...
141-
142164

143165
## Contributing is fun🧡
144166

@@ -147,9 +169,15 @@ Whether it's a new feature, design improvement, or a bug fix — your voice matt
147169

148170
Your insights are invaluable to us. Reach out to us team for any inquiries, feedback, or concerns.
149171

172+
## 👥 Contributors
173+
174+
Thanks to these wonderful people for contributing 💖
175+
176+
[![Contributors](https://contrib.rocks/image?repo=eccentriccoder01/TalkHeal)](https://github.com/eccentriccoder01/TalkHeal/graphs/contributors)
177+
150178
## 📄 License
151179

152-
This project is open-source and available under the MIT License.
180+
This project is open-source and available under the [MIT License](LICENSE).
153181

154182
## 📞 Contact
155183

blue_ss.jpg

161 KB
Loading

components/chat_interface.py

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import streamlit as st
2-
from core.utils import save_conversations, get_current_time
3-
from core.gemini import get_ai_response
4-
2+
# ---------- Display chat messages ----------
53
def render_chat_interface():
64
st.markdown("### 🗨️ TalkHeal Conversation")
75

@@ -12,6 +10,15 @@ def render_chat_interface():
1210

1311
conversation = st.session_state.conversations[active_index]
1412

13+
if not conversation["messages"]:
14+
st.markdown(f"""
15+
<div class="welcome-message">
16+
<strong>Hello! I'm TalkHeal, your mental health companion 🤗</strong><br>
17+
How are you feeling today? You can write below or start a new topic.
18+
<div class="message-time">{get_current_time()}</div>
19+
</div>
20+
""", unsafe_allow_html=True)
21+
1522
for msg in conversation["messages"]:
1623
sender = msg["sender"]
1724
message = msg["message"]
@@ -23,8 +30,7 @@ def render_chat_interface():
2330
else:
2431
with st.chat_message("assistant", avatar="💬"):
2532
st.markdown(f"{message}\n\n<sub>{time}</sub>", unsafe_allow_html=True)
26-
27-
33+
input and generate AI response
2834
def handle_chat_input(model, system_prompt):
2935
pre_filled = st.session_state.get("pre_filled_chat_input", "")
3036
st.session_state.pre_filled_chat_input = ""
@@ -93,11 +99,25 @@ def format_memory(convo_history, max_turns=10):
9399
"time": get_current_time()
94100
})
95101

102+
except ValueError as e:
103+
st.error("I'm having trouble understanding your message. Could you please rephrase it?")
104+
active_convo["messages"].append({
105+
"sender": "bot",
106+
"message": "I'm having trouble understanding your message. Could you please rephrase it?",
107+
"time": get_current_time()
108+
})
109+
except requests.RequestException as e:
110+
st.error("Network connection issue. Please check your internet connection.")
111+
active_convo["messages"].append({
112+
"sender": "bot",
113+
"message": "I'm having trouble connecting to my services. Please check your internet connection and try again.",
114+
"time": get_current_time()
115+
})
96116
except Exception as e:
97-
st.error(f"An error occurred: {e}")
117+
st.error(f"An unexpected error occurred. Please try again.")
98118
active_convo["messages"].append({
99119
"sender": "bot",
100-
"message": "Im having trouble responding right now. Please try again in a moment.",
120+
"message": "I'm having trouble responding right now. Please try again in a moment.",
101121
"time": get_current_time()
102122
})
103123

components/emergency_page.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
from geopy.geocoders import Nominatim
33
import urllib.parse
44
from .sidebar import GLOBAL_RESOURCES
5+
import geopy.exc
6+
import requests
57

68

79
def render_emergency_page():
@@ -41,8 +43,20 @@ def render_emergency_page():
4143
st.error(
4244
f"Could not find a location for '{location_query}'. Please try again.")
4345
st.session_state.pop('location_info', None)
46+
except geopy.exc.GeocoderTimedOut:
47+
st.error("Location search timed out. Please try again with a more specific location.")
48+
st.session_state.pop('location_info', None)
49+
except geopy.exc.GeocoderUnavailable:
50+
st.error("Location service is currently unavailable. Please try again later.")
51+
st.session_state.pop('location_info', None)
52+
except geopy.exc.GeocoderQuotaExceeded:
53+
st.error("Location service quota exceeded. Please try again later.")
54+
st.session_state.pop('location_info', None)
55+
except requests.RequestException as e:
56+
st.error("Network error while searching for location. Please check your internet connection.")
57+
st.session_state.pop('location_info', None)
4458
except Exception as e:
45-
st.error(f"An error occurred during search: {e}")
59+
st.error(f"An unexpected error occurred during search. Please try again.")
4660
st.session_state.pop('location_info', None)
4761
else:
4862
st.warning("Please enter a location to search.")

core/config.py

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import streamlit as st
22
import google.generativeai as genai
33
from pathlib import Path
4+
import requests
45

56
# ---------- Logo and Page Config ----------
67
logo_path = str(Path(__file__).resolve().parent.parent / "TalkHealLogo.png")
@@ -63,18 +64,30 @@ def get_mood_context():
6364
mood = st.session_state.get("current_mood_val") or get_selected_mood()
6465
return f"The user is currently feeling '{mood}'. Please respond empathetically and supportively based on their emotional state."
6566

66-
# ---------- Conversation State Utility ----------
67-
def create_new_conversation():
68-
from datetime import datetime
69-
70-
new_convo = {
71-
"title": "New Chat",
72-
"messages": [],
73-
"date": datetime.now().strftime("%Y-%m-%d %H:%M:%S")
74-
}
75-
76-
if "conversations" not in st.session_state:
77-
st.session_state.conversations = []
67+
# ---------- Generate AI Response ----------
68+
def generate_response(user_input, model):
69+
system_prompt = get_tone_system_prompt() + "\n" + get_mood_context()
70+
try:
71+
response = model.generate_content([
72+
{"role": "system", "parts": [system_prompt]},
73+
{"role": "user", "parts": [user_input]}
74+
])
75+
return response.text
76+
except ValueError as e:
77+
st.error("❌ Invalid input or model configuration issue. Please check your input.")
78+
return None
79+
except google.generativeai.types.BlockedPromptException as e:
80+
st.error("❌ Content policy violation. Please rephrase your message.")
81+
return None
82+
except google.generativeai.types.GenerationException as e:
83+
st.error("❌ Failed to generate response. Please try again.")
84+
return None
85+
except requests.RequestException as e:
86+
st.error("❌ Network connection issue. Please check your internet connection.")
87+
return None
88+
except Exception as e:
89+
st.error(f"❌ Unexpected error occurred: {e}")
90+
return None
7891

7992
st.session_state.conversations.insert(0, new_convo)
8093
st.session_state.active_conversation = 0

core/utils.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import json
55
import os
66
import requests
7+
import google.generativeai
78

89
def get_current_time():
910
"""Returns the user's local time formatted as HH:MM AM/PM."""
@@ -78,7 +79,22 @@ def get_ai_response(user_message, model):
7879
response = model.generate_content(mental_health_prompt)
7980
cleaned_response = clean_ai_response(response.text)
8081
return cleaned_response
82+
except ValueError as e:
83+
# Handle invalid input or model configuration issues
84+
return "I'm having trouble understanding your message. Could you please rephrase it?"
85+
except google.generativeai.types.BlockedPromptException as e:
86+
# Handle content policy violations
87+
return "I understand you're going through something difficult. Let's focus on how you're feeling and what might help you feel better."
88+
except google.generativeai.types.GenerationException as e:
89+
# Handle generation errors
90+
return "I'm having trouble generating a response right now. Please try again in a moment."
91+
except requests.RequestException as e:
92+
# Handle network/API connection issues
93+
return "I'm having trouble connecting to my services. Please check your internet connection and try again."
8194
except Exception as e:
95+
# Log unexpected errors for debugging (you can add logging here)
96+
# import logging
97+
# logging.error(f"Unexpected error in get_ai_response: {e}")
8298
return "I'm here to listen and support you. Sometimes I have trouble connecting, but I want you to know that your feelings are valid and you're not alone. Would you like to share more about what you're experiencing?"
8399

84100
# Implementing IP Based Isolation

dark_ss.jpg

140 KB
Loading

lav_ss.jpg

146 KB
Loading

light_ss.jpg

147 KB
Loading

0 commit comments

Comments
 (0)