-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
189 lines (163 loc) · 5.26 KB
/
Copy pathapp.py
File metadata and controls
189 lines (163 loc) · 5.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import streamlit as st
from gemini_client import analyze_text
import storage
import pandas as pd
import os
from dotenv import load_dotenv
load_dotenv()
st.set_page_config(page_title="MindMate", page_icon="🧠", layout="centered")
# === 🎨 STYLING ===
st.markdown("""
<style>
/* Background gradient */
[data-testid="stAppViewContainer"] {
background: linear-gradient(135deg, #1e1f29 0%, #2a2d3e 40%, #1a1b24 100%);
color: #ffffff;
}
/* Transparent header */
[data-testid="stHeader"] {
background: rgba(0, 0, 0, 0);
}
/* Card style for containers */
.block-container {
background: rgba(255, 255, 255, 0.05);
padding: 2rem 3rem;
border-radius: 20px;
box-shadow: 0 0 25px rgba(0, 0, 0, 0.3);
backdrop-filter: blur(8px);
}
/* Buttons */
div.stButton > button:first-child {
background: linear-gradient(90deg, #00c6ff 0%, #0072ff 100%);
color: white;
border: none;
border-radius: 8px;
font-size: 1.05rem;
padding: 0.5rem 1.2rem;
box-shadow: 0 0 10px rgba(0, 114, 255, 0.4);
transition: 0.3s;
}
div.stButton > button:hover {
transform: scale(1.03);
box-shadow: 0 0 20px rgba(0, 114, 255, 0.6);
}
/* Text area */
textarea {
background: rgba(255, 255, 255, 0.1) !important;
color: #f8f9fa !important;
border-radius: 10px !important;
}
/* DataFrame styling */
[data-testid="stDataFrame"] {
background: rgba(255, 255, 255, 0.05);
border-radius: 10px;
padding: 0.8rem;
}
/* Progress bar color */
[data-testid="stProgress"] > div > div {
background: linear-gradient(90deg, #0072ff, #00c6ff);
}
/* Info boxes */
div.stAlert {
border-radius: 10px;
}
/* Titles */
h1, h2, h3 {
color: #00c6ff;
}
/* Scrollbar */
::-webkit-scrollbar {
width: 8px;
}
::-webkit-scrollbar-thumb {
background: #0072ff;
border-radius: 4px;
}
</style>
""", unsafe_allow_html=True)
# === HEADER ===
st.title("🧠 MindMate — Your AI Mood & Wellness Companion")
# Gemini Key Status
if os.getenv("GEMINI_API_KEY"):
st.success("✅ Gemini API connected successfully", icon="🤖")
else:
st.warning("⚠️ Running in offline fallback mode (heuristic analysis only)", icon="⚙️")
st.write(
"MindMate helps you reflect on your emotions through journaling. "
"It uses Google's **Gemini AI** to analyze your mood and suggest mindfulness actions."
)
# === INPUT SECTION ===
st.markdown("## 📝 Journal Entry")
with st.form("journal_form"):
text = st.text_area("How are you feeling today?", height=200, placeholder="Type freely about your thoughts, emotions, or day...")
submitted = st.form_submit_button("💫 Analyze Mood")
if submitted:
if not text.strip():
st.error("Please write something first.")
else:
with st.spinner("Analyzing your entry with Gemini AI..."):
result = analyze_text(text)
mood = result["mood"].capitalize()
score = result["score"]
# Select emoji based on mood and score for better visual feedback
mood_lower = result["mood"].lower()
if mood_lower == "positive":
if score >= 80:
emoji = "😄" # Very happy
elif score >= 65:
emoji = "😊" # Happy
else:
emoji = "🙂" # Slightly positive
elif mood_lower == "negative":
if score <= 20:
emoji = "😢" # Very sad
elif score <= 35:
emoji = "😔" # Sad
else:
emoji = "😟" # Worried
elif mood_lower == "neutral":
emoji = "😐" # Neutral
else:
# Fallback based on score if mood is unexpected
if score >= 80:
emoji = "😄"
elif score >= 65:
emoji = "😊"
elif score >= 50:
emoji = "😐"
elif score >= 35:
emoji = "😟"
else:
emoji = "😔"
st.markdown(f"### {emoji} **Mood:** {mood} — Score: {score}/100")
st.progress(score)
st.write(f"**Summary:** {result['summary']}")
st.markdown("### 🪷 Coping Tips 🫂")
for tip in result["tips"]:
st.markdown(f"- {tip}")
st.markdown(f"**Reflection Prompt:** {result['journaling_prompt']}")
# Automatically save to mood history
entry = storage.create_entry(text, result)
storage.save_entry(entry)
st.success("✅ Automatically saved to your mood history!")
# === HISTORY SECTION ===
st.markdown("---")
st.markdown("## 📊 Mood History")
history = storage.load_history()
if history:
df = pd.DataFrame(history)
df["timestamp"] = pd.to_datetime(df["timestamp"])
df = df.sort_values("timestamp")
st.line_chart(df.set_index("timestamp")["score"], height=300)
st.dataframe(df[["timestamp", "mood", "score", "summary"]].tail(10))
csv = df.to_csv(index=False).encode("utf-8")
st.download_button("⬇️ Download History CSV", csv, "mood_history.csv", "text/csv")
else:
st.info("No history yet — write your first reflection and save it to see your mood trends!")
# === FOOTER ===
st.markdown("""
---
<p style='text-align: center; color: #aaa;'>
Built with ❤️ using <b>Google Gemini API</b> & <b>Streamlit</b> for TFUG Build-a-thon 2025.
</p>
""", unsafe_allow_html=True)