Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -171,67 +171,85 @@ if st.session_state.page == "welcome":
|
|
171 |
st.session_state.page = "main"
|
172 |
st.rerun()
|
173 |
|
174 |
-
|
175 |
if st.session_state.page == "main":
|
176 |
st.title("π Kalam Comfort")
|
177 |
st.subheader("Select your mood to receive comfort from the Qur'an")
|
178 |
|
179 |
selected_mood = st.selectbox("How are you feeling today?", list(moods.keys()), index=0)
|
180 |
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
st.markdown("
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
st.markdown("
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
171 |
st.session_state.page = "main"
|
172 |
st.rerun()
|
173 |
|
174 |
+
#---------------- Page 2: Main App ----------------
|
175 |
if st.session_state.page == "main":
|
176 |
st.title("π Kalam Comfort")
|
177 |
st.subheader("Select your mood to receive comfort from the Qur'an")
|
178 |
|
179 |
selected_mood = st.selectbox("How are you feeling today?", list(moods.keys()), index=0)
|
180 |
|
181 |
+
# Reset index on mood change
|
182 |
+
if "current_mood" not in st.session_state:
|
183 |
+
st.session_state.current_mood = ""
|
184 |
+
if selected_mood != st.session_state.current_mood:
|
185 |
+
st.session_state.current_mood = selected_mood
|
186 |
+
st.session_state.response_index = 0
|
187 |
+
|
188 |
+
# Show Another Response button
|
189 |
+
if st.button("π Show Another Response"):
|
190 |
+
st.session_state.response_index += 1
|
191 |
+
st.rerun()
|
192 |
+
|
193 |
+
index = st.session_state.get("response_index", 0)
|
194 |
+
|
195 |
+
# Quranic Verse
|
196 |
+
verse_list = moods[selected_mood]
|
197 |
+
verse_ref = verse_list[index % len(verse_list)]
|
198 |
+
surah_num, ayah_num = verse_ref.split(":")
|
199 |
+
|
200 |
+
quran_api = f"https://api.alquran.cloud/v1/ayah/{surah_num}:{ayah_num}/editions/quran-simple,en.asad,ur.jalandhry"
|
201 |
+
response = requests.get(quran_api)
|
202 |
+
|
203 |
+
if response.status_code == 200:
|
204 |
+
data = response.json()["data"]
|
205 |
+
arabic = data[0]["text"]
|
206 |
+
english = data[1]["text"]
|
207 |
+
urdu = data[2]["text"]
|
208 |
+
surah_info = f"{data[0]['surah']['englishName']} ({data[0]['surah']['name']})"
|
209 |
+
|
210 |
+
st.markdown("### π Quranic Verse")
|
211 |
+
st.markdown(f"**Surah:** {surah_info} β Ayah {ayah_num}")
|
212 |
+
st.markdown(f"<div style='font-size:24px; direction: rtl'>{arabic}</div>", unsafe_allow_html=True)
|
213 |
+
st.markdown(f"**π English:** *{english}*")
|
214 |
+
st.markdown(f"**π Urdu:** {urdu}")
|
215 |
+
else:
|
216 |
+
st.error("β Could not fetch verse.")
|
217 |
+
|
218 |
+
# Dua
|
219 |
+
st.markdown("### π€² Dua")
|
220 |
+
duas = default_duas.get(selected_mood, [])
|
221 |
+
if duas:
|
222 |
+
dua = duas[index % len(duas)]
|
223 |
+
st.markdown(f"<div style='font-size:22px; direction: rtl'>{dua[0]}</div>", unsafe_allow_html=True)
|
224 |
+
st.markdown(f"**English:** {dua[1]}")
|
225 |
+
st.markdown(f"**Urdu:** {dua[2]}")
|
226 |
+
else:
|
227 |
+
st.warning("No duas available for this mood.")
|
228 |
+
|
229 |
+
# Hadith
|
230 |
+
st.markdown("### π Hadith")
|
231 |
+
hadiths = default_hadiths.get(selected_mood, [])
|
232 |
+
if hadiths:
|
233 |
+
hadith = hadiths[index % len(hadiths)]
|
234 |
+
st.markdown(f"<div style='font-size:22px; direction: rtl'>{hadith[0]}</div>", unsafe_allow_html=True)
|
235 |
+
st.markdown(f"**English:** {hadith[1]}")
|
236 |
+
st.markdown(f"**Urdu:** {hadith[2]}")
|
237 |
+
else:
|
238 |
+
st.warning("No hadiths available for this mood.")
|
239 |
+
|
240 |
+
# Reflection Section
|
241 |
+
st.markdown("### π Your Reflection")
|
242 |
+
reflection_input = st.text_area("Write your thoughts:", placeholder="How does this verse speak to you today?")
|
243 |
+
if st.button("πΎ Save Reflection"):
|
244 |
+
reflections[selected_mood] = {
|
245 |
+
"text": reflection_input,
|
246 |
+
"timestamp": datetime.now().strftime("%Y-%m-%d %H:%M")
|
247 |
+
}
|
248 |
+
with open("reflections.json", "w") as f:
|
249 |
+
json.dump(reflections, f, indent=4, ensure_ascii=False)
|
250 |
+
st.success("Reflection saved.")
|
251 |
+
|
252 |
+
if selected_mood in reflections:
|
253 |
+
last = reflections[selected_mood]
|
254 |
+
st.markdown("#### π Last Saved Reflection:")
|
255 |
+
st.markdown(f"**{last['timestamp']}** β {last['text']}")
|