Spaces:
Running
Running
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") | |
# Hide Streamlit UI elements | |
st.markdown(""" | |
<style> | |
#MainMenu, footer {visibility: hidden;} | |
button {font-size: 16px !important;} | |
</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 required files | |
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", {}) | |
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.", "بیشک اللہ ان لوگوں سے محبت کرتا ہے جو اس کی اطاعت میں خوش ہوتے ہیں۔") | |
] | |
} | |
# ---------------- Page 1: Welcome ---------------- | |
if st.session_state.page == "welcome": | |
st.title("📚 Kalam Comfort") | |
st.subheader("Let the Qur'an speak to your heart 🤍") | |
st.markdown(""" | |
<div style='text-align:center; margin-top: 30px;'> | |
<img src='https://i.ibb.co/0n7MpKx/quran-light.png' width='200'> | |
</div> | |
""", unsafe_allow_html=True) | |
if st.button("✨ Let's Dive In"): | |
st.session_state.page = "main" | |
st.experimental_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) | |
if selected_mood: | |
verse_ref = random.choice(moods[selected_mood]) | |
surah_num, ayah_num = verse_ref.split(":") | |
# Get Quranic text | |
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 Section | |
st.markdown("### 🤲 Duas") | |
duas = random.sample(default_duas.get(selected_mood, []), k=min(2, len(default_duas.get(selected_mood, [])))) | |
for arabic, eng, ur in duas: | |
st.markdown(f"<div style='font-size:22px; direction: rtl'>{arabic}</div>", unsafe_allow_html=True) | |
st.markdown(f"**English:** {eng}") | |
st.markdown(f"**Urdu:** {ur}") | |
st.markdown("---") | |
# Hadith Section | |
st.markdown("### 📜 Hadith") | |
mood_hadiths = default_hadiths.get(selected_mood, []) | |
for arabic, eng, ur, src in mood_hadiths: | |
st.markdown(f"<div style='font-size:22px; direction: rtl'>{arabic}</div>", unsafe_allow_html=True) | |
st.markdown(f"**English:** {eng}") | |
st.markdown(f"**Urdu:** {ur}") | |
st.markdown(f"_Source: {src}_") | |
st.markdown("---") | |
# 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']}") | |