Spaces:
Running
Running
File size: 18,616 Bytes
304b31b f9ed339 33b5855 f9ed339 33b5855 f9ed339 33b5855 f9ed339 33b5855 f9ed339 33b5855 f9ed339 5365be5 f9ed339 304b31b 33b5855 7152de4 c110a4c 8ec540a c110a4c 8ec540a c110a4c 8ec540a c110a4c 8ec540a c110a4c 8ec540a c110a4c 8ec540a c110a4c 8ec540a c110a4c 8ec540a c110a4c 8ec540a 5365be5 c110a4c 8ec540a 5365be5 c110a4c 7152de4 c110a4c 7152de4 33b5855 f9ed339 7b273a4 f9ed339 ac6f9e3 f9ed339 ac6f9e3 |
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 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 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
import streamlit as st
import os
import json
import random
import requests
from datetime import datetime
st.set_page_config(page_title="Kalam Comfort", page_icon="📚", layout="centered")
# Custom CSS for dark/light modes and centering
st.markdown("""
<style>
html, body, [class*="css"] {
font-family: 'Segoe UI', sans-serif;
}
#MainMenu, footer {visibility: hidden;}
div.stButton > button {
display: block;
margin: 0 auto;
background-color: #4F8BF9;
color: white;
font-size: 18px;
padding: 10px 24px;
border-radius: 8px;
}
</style>
""", unsafe_allow_html=True)
# Session state to manage page switching
if "page" not in st.session_state:
st.session_state.page = "welcome"
# Load or create JSON
def load_or_create_json(filename, default_data):
if not os.path.exists(filename):
with open(filename, "w") as f:
json.dump(default_data, f, indent=4, ensure_ascii=False)
with open(filename, "r") as f:
return json.load(f)
# Mood-to-Ayah mapping
moods = load_or_create_json("moods.json", {
"anxious": ["13:28", "2:286", "10:62"],
"sad": ["94:5", "93:6", "65:7"],
"hopeless": ["39:53", "12:87", "3:139"],
"grateful": ["14:7", "31:12"],
"lonely": ["2:186", "9:40"],
"angry": ["3:134", "41:34"],
"lost": ["93:7", "6:122"],
"tired": ["94:6", "3:200"],
"afraid": ["8:46", "33:3"],
"happy": ["10:58", "28:70", "55:13"]
})
reflections = load_or_create_json("reflections.json", {})
# ====== DUAS and HADITHS EMBEDDED DIRECTLY ======
default_duas = {
"anxious": [
("اللهم اجعل قلبي مطمئنًا بذكرك", "O Allah, make my heart tranquil with Your remembrance.", "یا اللہ! میرے دل کو اپنے ذکر سے اطمینان دے۔"),
("اللهم لا سهل إلا ما جعلته سهلا", "O Allah, nothing is easy except what You make easy.", "یا اللہ! کچھ بھی آسان نہیں سوائے اس کے جسے تُو آسان کرے۔"),
("اللهم إني أعوذ بك من الهم والحزن", "O Allah, I seek refuge in You from worry and grief.", "یا اللہ! میں فکروں اور غم سے تیری پناہ چاہتا ہوں۔")
],
"sad": [
("اللهم اجبر قلبي جبرا يتعجب له أهل السماوات والأرض", "O Allah, mend my heart in a way that amazes the heavens and the earth.", "یا اللہ! میرے دل کو ایسا سہارا دے جو زمین و آسمان کو حیران کر دے۔"),
("اللهم ارزقني الصبر الجميل على كل ما أحزنني", "O Allah, grant me beautiful patience for all that has saddened me.", "یا اللہ! مجھے ان تمام غموں پر خوبصورت صبر عطا فرما۔"),
("يا حي يا قيوم برحمتك أستغيث", "O Ever-Living, O Sustainer, by Your mercy I seek relief.", "اے زندہ اور قائم رہنے والے! تیری رحمت سے مدد مانگتا ہوں۔")
],
"hopeless": [
("رب لا تذرني فردا وأنت خير الوارثين", "My Lord, do not leave me alone — You are the Best Inheritor.", "یا رب! مجھے تنہا نہ چھوڑ، تو بہترین وارث ہے۔"),
("اللهم افتح لي أبواب رحمتك", "O Allah, open for me the doors of Your mercy.", "یا اللہ! اپنی رحمت کے دروازے میرے لیے کھول دے۔"),
("اللهم لا تجعلني من القانطين", "O Allah, do not make me among the despairing.", "یا اللہ! مجھے مایوس لوگوں میں شامل نہ فرما۔")
],
"grateful": [
("اللهم اجعلني لك شَكُورًا", "O Allah, make me deeply grateful to You.", "یا اللہ! مجھے شکر گزار بنا دے۔"),
("اللهم أعني على ذكرك وشكرك وحسن عبادتك", "O Allah, help me remember You, thank You, and worship You beautifully.", "یا اللہ! میری مدد فرما کہ میں تیرا ذکر، شکر اور عمدہ عبادت کر سکوں۔"),
("رب أوزعني أن أشكر نعمتك التي أنعمت عليّ", "My Lord, inspire me to thank You for Your blessing upon me.", "اے میرے رب! مجھے توفیق دے کہ میں تیری نعمتوں پر شکر ادا کروں۔")
],
"lonely": [
("اللهم كن معي حين لا يكون أحد بجانبي", "O Allah, be with me when no one else is.", "یا اللہ! جب کوئی ساتھ نہ ہو، تو میرے ساتھ ہو۔"),
("اللهم انس وحشتي", "O Allah, remove my loneliness.", "یا اللہ! میری تنہائی کو دور کر دے۔"),
("اللهم لا تكلني إلى نفسي طرفة عين", "O Allah, do not leave me to myself even for a moment.", "یا اللہ! مجھے ایک لمحے کے لیے بھی میرے نفس کے حوالے نہ کر۔")
],
"angry": [
("اللهم ارزقني الحلم عند الغضب", "O Allah, grant me forbearance when I’m angry.", "یا اللہ! غصے میں مجھے برداشت عطا فرما۔"),
("اللهم اجعلني من الكاظمين الغيظ والعافين عن الناس", "O Allah, make me among those who suppress anger and forgive others.", "یا اللہ! مجھے ان میں شامل فرما جو غصے کو پی جاتے اور دوسروں کو معاف کرتے ہیں۔"),
("اللهم اهد قلبي وسدد لساني", "O Allah, guide my heart and control my tongue.", "یا اللہ! میرے دل کو ہدایت دے اور میری زبان کو قابو میں رکھ۔")
],
"lost": [
("اللهم دلّني على صراطك المستقيم", "O Allah, guide me to Your straight path.", "یا اللہ! مجھے اپنے سیدھے راستے پر چلا۔"),
("اللهم نور بصيرتي", "O Allah, illuminate my insight.", "یا اللہ! میری بصیرت کو منور فرما۔"),
("اللهم اجعل لي فرقانًا", "O Allah, grant me the ability to distinguish right from wrong.", "یا اللہ! مجھے حق و باطل میں فرق کرنے کی بصیرت عطا فرما۔")
],
"tired": [
("اللهم جدد طاقتي، وارزقني راحة البال", "O Allah, renew my energy and grant me peace of mind.", "یا اللہ! میری طاقت کو تازہ کر اور مجھے ذہنی سکون عطا فرما۔"),
("اللهم إنّ نفسي ضعيفة، فقوّها", "O Allah, my soul is weak, so strengthen it.", "یا اللہ! میری جان کمزور ہے، اسے مضبوط کر دے۔"),
("اللهم خفف عني ما أثقل كاهلي", "O Allah, lighten the burdens on my shoulders.", "یا اللہ! میرے کندھوں پر بوجھ کو ہلکا کر دے۔")
],
"afraid": [
("ربِّ أعني ولا تعن عليّ", "My Lord, support me and not against me.", "میرے رب! میری مدد فرما، میرے خلاف نہ ہو۔"),
("اللهم اجعلني من المتوكلين عليك", "O Allah, make me among those who rely on You.", "یا اللہ! مجھے اپنے اوپر بھروسہ کرنے والوں میں شامل فرما۔"),
("اللهم احفظني من بين يديّ ومن خلفي", "O Allah, protect me from in front of me and behind me.", "یا اللہ! میرے آگے پیچھے سے میری حفاظت فرما۔")
],
"happy": [
("اللهم اجعل سعادتي دائمة", "O Allah, make my happiness everlasting.", "یا اللہ! میری خوشی کو دائمی بنا دے۔"),
("اللهم كما أسعدتني فأسعد قلبي دومًا بذكرك", "O Allah, as You made me happy, keep my heart joyful with Your remembrance.", "یا اللہ! جیسے تو نے مجھے خوشی دی، ویسے ہی اپنے ذکر سے میرے دل کو ہمیشہ خوش رکھ۔"),
("اللهم بارك لي في نعمك ولا تجعلني من الغافلين", "O Allah, bless me in Your blessings and don’t make me among the heedless.", "یا اللہ! اپنی نعمتوں میں برکت عطا فرما اور مجھے غافلوں میں سے نہ بنا۔")
]
}
default_hadiths = {
"anxious": [
("أَلَا بِذِكْرِ اللَّهِ تَطْمَئِنُّ الْقُلُوبُ", "Verily, in the remembrance of Allah do hearts find rest.", "خبردار! اللہ کے ذکر سے دلوں کو سکون ملتا ہے۔"),
("إِذَا سَأَلْتَ فَاسْأَلِ اللَّهَ", "If you ask, ask Allah.", "اگر سوال کرو تو اللہ سے کرو۔"),
("اللَّهُ أَرْحَمُ بِعِبَادِهِ", "Allah is more merciful to His slaves than a mother to her child.", "اللہ اپنے بندوں پر ماں سے بھی زیادہ رحم کرنے والا ہے۔")
],
"sad": [
("إِنَّ مَعَ الْعُسْرِ يُسْرًا", "Indeed, with hardship comes ease.", "بیشک ہر تنگی کے ساتھ آسانی ہے۔"),
("لَا يَحْزُنكَ قَوْلُهُمْ", "Let not their words grieve you.", "ان کی باتیں آپ کو غمگین نہ کریں۔"),
("لَا تَحْزَنْ إِنَّ اللَّهَ مَعَنَا", "Do not grieve, indeed Allah is with us.", "غم نہ کرو، بے شک اللہ ہمارے ساتھ ہے۔")
],
"hopeless": [
("مَن تَوَكَّلَ عَلَى اللَّهِ فَهُوَ حَسْبُهُ", "Whoever relies upon Allah — He is sufficient for him.", "جو اللہ پر بھروسہ کرے، وہ اس کے لیے کافی ہے۔"),
("إِنَّهُ لَا يَيْأَسُ مِنْ رَوْحِ اللَّهِ", "None despairs of Allah's mercy except the disbelieving people.", "اللہ کی رحمت سے صرف کافر ہی ناامید ہوتے ہیں۔"),
("وَرَحْمَتِي وَسِعَتْ كُلَّ شَيْءٍ", "My mercy encompasses all things.", "میری رحمت ہر چیز کو محیط ہے۔")
],
"grateful": [
("مَن لَا يَشْكُرُ النَّاسَ لَا يَشْكُرُ اللَّهَ", "He who does not thank people does not thank Allah.", "جو لوگوں کا شکر ادا نہیں کرتا، وہ اللہ کا بھی شکر نہیں کرتا۔"),
("اللَّهُ يُحِبُّ الشَّاكِرِينَ", "Allah loves those who are grateful.", "اللہ شکر گزاروں سے محبت کرتا ہے۔"),
("وَاشْكُرُوا لِي وَلَا تَكْفُرُونِ", "Be thankful to Me and do not deny Me.", "میرا شکر ادا کرو اور ناشکری نہ کرو۔")
],
"lonely": [
("أَنَا أَوْلَى بِالْمُؤْمِنِينَ مِنْ أَنْفُسِهِمْ", "I am closer to the believers than their own selves.", "میں مومنوں سے ان کی اپنی جانوں سے بھی زیادہ قریب ہوں۔"),
("إِنِّي مَعَكُمَا أَسْمَعُ وَأَرَى", "Indeed, I am with you both; I hear and see.", "بے شک میں تم دونوں کے ساتھ ہوں، میں سنتا اور دیکھتا ہوں۔"),
("اللَّهُ وَلِيُّ الَّذِينَ آمَنُوا", "Allah is the protector of those who believe.", "اللہ ایمان والوں کا ولی ہے۔")
],
"angry": [
("لَيْسَ الشَّدِيدُ بِالصُّرَعَةِ...", "The strong is not the one who overcomes others in wrestling but the one who controls himself in anger.", "طاقتور وہ نہیں جو پچھاڑ دے، بلکہ وہ ہے جو غصے میں خود پر قابو رکھے۔"),
("لَا تَغْضَبْ", "Do not become angry.", "غصہ نہ کرو۔"),
("وَإِذَا مَا غَضِبُوا هُمْ يَغْفِرُونَ", "When they are angry, they forgive.", "جب وہ غصے میں ہوتے ہیں تو معاف کر دیتے ہیں۔")
],
"lost": [
("مَنْ سَلَكَ طَرِيقًا يَلْتَمِسُ فِيهِ عِلْمًا...", "Whoever treads a path in search of knowledge, Allah makes his path to Paradise easy.", "جو علم کے راستے پر چلے، اللہ اس کے لیے جنت کا راستہ آسان کر دیتا ہے۔"),
("وَوَجَدَكَ ضَالًّا فَهَدَى", "And He found you lost and guided [you].", "اور اُس نے آپ کو بھٹکا ہوا پایا، تو راہ دکھائی۔"),
("اللَّهُ نُورُ السَّمَاوَاتِ وَالْأَرْضِ", "Allah is the Light of the heavens and the earth.", "اللہ آسمانوں اور زمین کا نور ہے۔")
],
"tired": [
("مَا يُصِيبُ الْمُسْلِمَ مِنْ نَصَبٍ...", "No fatigue afflicts a Muslim except that Allah removes sins thereby.", "مسلمان کو جو بھی تھکن یا مرض لاحق ہو، اللہ اس سے اس کے گناہ مٹا دیتا ہے۔"),
("وَاصْبِرْ وَمَا صَبْرُكَ إِلَّا بِاللَّهِ", "And be patient, and your patience is not but through Allah.", "صبر کرو، اور تمہارا صبر صرف اللہ کے لیے ہے۔"),
("إِنَّ مَعَ الْعُسْرِ يُسْرًا", "Indeed, with hardship comes ease.", "بے شک تنگی کے ساتھ آسانی ہے۔")
],
"afraid": [
("احْفَظِ اللَّهَ يَحْفَظْكَ", "Be mindful of Allah and He will protect you.", "اللہ کا دھیان رکھو، وہ تمہاری حفاظت کرے گا۔"),
("لَا خَوْفٌ عَلَيْهِمْ وَلَا هُمْ يَحْزَنُونَ", "No fear will there be concerning them, nor will they grieve.", "ان پر نہ کوئی خوف ہوگا اور نہ وہ غمگین ہوں گے۔"),
("إِنَّ اللَّهَ مَعَ الَّذِينَ اتَّقَوْا", "Indeed, Allah is with those who fear Him.", "بے شک اللہ پرہیزگاروں کے ساتھ ہے۔")
],
"happy": [
("الْفَرَحُ نِعْمَةٌ مِنَ اللَّهِ", "Happiness is a blessing from Allah.", "خوشی اللہ کی طرف سے ایک نعمت ہے۔"),
("تَبَسُّمُكَ فِي وَجْهِ أَخِيكَ صَدَقَةٌ", "Smiling in the face of your brother is charity.", "اپنے بھائی کے چہرے پر مسکرانا صدقہ ہے۔"),
("إِنَّ اللَّهَ يُحِبُّ الْفَرَحِينَ بِطَاعَتِهِ", "Indeed, Allah loves those who rejoice in His obedience.", "بیشک اللہ ان لوگوں سے محبت کرتا ہے جو اس کی اطاعت میں خوش ہوتے ہیں۔")
]
}
# ========== END OF DUAS & HADITHS ==========
# ---------------- Page 1: Welcome ----------------
if st.session_state.page == "welcome":
st.title("📚 Kalam Comfort")
st.subheader("Let the Qur'an speak to your heart 🤍")
if st.button("✨ Let's Dive In"):
st.session_state.page = "main"
st.rerun()
#---------------- Page 2: Main App ----------------
if st.session_state.page == "main":
st.title("📖 Kalam Comfort")
st.subheader("Select your mood to receive comfort from the Qur'an")
selected_mood = st.selectbox("How are you feeling today?", list(moods.keys()), index=0)
# Reset index on mood change
if "current_mood" not in st.session_state:
st.session_state.current_mood = ""
if selected_mood != st.session_state.current_mood:
st.session_state.current_mood = selected_mood
st.session_state.response_index = 0
# Show Another Response button
if st.button("🔁 Show Another Response"):
st.session_state.response_index += 1
st.rerun()
index = st.session_state.get("response_index", 0)
# Quranic Verse
verse_list = moods[selected_mood]
verse_ref = verse_list[index % len(verse_list)]
surah_num, ayah_num = verse_ref.split(":")
quran_api = f"https://api.alquran.cloud/v1/ayah/{surah_num}:{ayah_num}/editions/quran-simple,en.asad,ur.jalandhry"
response = requests.get(quran_api)
if response.status_code == 200:
data = response.json()["data"]
arabic = data[0]["text"]
english = data[1]["text"]
urdu = data[2]["text"]
surah_info = f"{data[0]['surah']['englishName']} ({data[0]['surah']['name']})"
st.markdown("### 🌙 Quranic Verse")
st.markdown(f"**Surah:** {surah_info} — Ayah {ayah_num}")
st.markdown(f"<div style='font-size:24px; direction: rtl'>{arabic}</div>", unsafe_allow_html=True)
st.markdown(f"**📖 English:** *{english}*")
st.markdown(f"**📖 Urdu:** {urdu}")
else:
st.error("❌ Could not fetch verse.")
# Dua
st.markdown("### 🤲 Dua")
duas = default_duas.get(selected_mood, [])
if duas:
dua = duas[index % len(duas)]
st.markdown(f"<div style='font-size:22px; direction: rtl'>{dua[0]}</div>", unsafe_allow_html=True)
st.markdown(f"**English:** {dua[1]}")
st.markdown(f"**Urdu:** {dua[2]}")
else:
st.warning("No duas available for this mood.")
# Hadith
st.markdown("### 📜 Hadith")
hadiths = default_hadiths.get(selected_mood, [])
if hadiths:
hadith = hadiths[index % len(hadiths)]
st.markdown(f"<div style='font-size:22px; direction: rtl'>{hadith[0]}</div>", unsafe_allow_html=True)
st.markdown(f"**English:** {hadith[1]}")
st.markdown(f"**Urdu:** {hadith[2]}")
else:
st.warning("No hadiths available for this mood.")
# Reflection Section
st.markdown("### 📝 Your Reflection")
reflection_input = st.text_area("Write your thoughts:", placeholder="How does this verse speak to you today?")
if st.button("💾 Save Reflection"):
reflections[selected_mood] = {
"text": reflection_input,
"timestamp": datetime.now().strftime("%Y-%m-%d %H:%M")
}
with open("reflections.json", "w") as f:
json.dump(reflections, f, indent=4, ensure_ascii=False)
st.success("Reflection saved.")
if selected_mood in reflections:
last = reflections[selected_mood]
st.markdown("#### 📜 Last Saved Reflection:")
st.markdown(f"**{last['timestamp']}** — {last['text']}")
|