File size: 6,459 Bytes
304b31b
 
 
 
 
 
 
 
16d2f94
304b31b
 
3dde9fc
304b31b
9657db2
 
 
 
 
 
 
 
 
304b31b
 
 
 
 
 
 
 
 
 
 
 
 
 
3dde9fc
304b31b
 
 
 
 
 
3dde9fc
304b31b
 
 
 
 
 
3dde9fc
45c97a4
304b31b
 
 
 
 
 
45c97a4
304b31b
 
 
 
 
45c97a4
 
304b31b
3dde9fc
 
 
9657db2
3dde9fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9657db2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3dde9fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import os
import json
import random
import requests
from datetime import datetime
from dotenv import load_dotenv

st.set_page_config(page_title="Kalam Comfort", page_icon="📚")
load_dotenv()

# ---------- File Setup ----------
default_moods = {
    "anxious": ["13:28", "2:286", "10:62", "20:46", "48:4"],
    "sad": ["94:5", "93:6", "65:7", "9:51", "12:86"],
    "hopeless": ["39:53", "12:87", "3:139", "65:2", "57:22"],
    "grateful": ["14:7", "31:12", "2:152", "16:114", "76:3"],
    "lonely": ["2:186", "9:40", "6:103", "50:16", "17:79"],
    "angry": ["3:134", "41:34", "7:199", "42:37", "16:126"],
    "lost": ["93:7", "6:122", "2:2", "24:35", "42:52"],
    "tired": ["94:6", "3:200", "29:69", "52:48", "6:162"],
    "afraid": ["8:46", "33:3", "2:286", "3:173", "11:56"]
}

if not os.path.exists("moods.json"):
    with open("moods.json", "w") as f:
        json.dump(default_moods, f, indent=4)
with open("moods.json", "r") as f:
    moods = json.load(f)

if not os.path.exists("reflections.json"):
    with open("reflections.json", "w") as f:
        json.dump({}, f)
with open("reflections.json", "r") as f:
    reflections = json.load(f)

# ---------- UI ----------
st.title("📚 Kalam Comfort")
st.subheader("Find Quranic comfort by emotion 💖")

selected_mood = st.selectbox("How are you feeling today?", list(moods.keys()), index=0)

if st.button("🔁 Show another verse"):
    st.rerun()

if selected_mood:
    verse_list = moods[selected_mood]
    verse_ref = random.choice(verse_list)
    surah_num, ayah_num = verse_ref.split(":")

    # 1. Quran Arabic, English, Urdu
    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("❌ Failed to fetch Quranic text.")
        st.stop()

    # 2. Dua (Mood-based, bilingual)
    dua_map = {
        "anxious": "اللهم اجعل قلبي مطمئنًا بذكرك\n**O Allah, make my heart tranquil with Your remembrance.**\n**یا اللہ! میرے دل کو اپنے ذکر سے اطمینان دے۔**",
        "sad": "اللهم اجبر قلبي جبرا يتعجب له أهل السماوات والأرض\n**O Allah, mend my heart in a way that amazes the heavens and earth.**\n**یا اللہ! میرے دل کو ایسا سہارا دے جو زمین و آسمان کو حیران کر دے۔**",
        "hopeless": "رب لا تذرني فردا وأنت خير الوارثين\n**My Lord, do not leave me alone — You are the Best Inheritor.**\n**یا رب! مجھے تنہا نہ چھوڑ، تو بہترین وارث ہے۔**",
        "grateful": "اللهم اجعلني لك شَكُورًا\n**O Allah, make me deeply grateful to You.**\n**یا اللہ! مجھے شکر گزار بنا دے۔**",
        "lonely": "اللهم كن معي حين لا يكون أحد بجانبي\n**O Allah, be with me when no one else is.**\n**یا اللہ! جب کوئی ساتھ نہ ہو، تو میرے ساتھ ہو۔**",
        "angry": "اللهم ارزقني الحلم عند الغضب\n**O Allah, grant me forbearance when I’m angry.**\n**یا اللہ! غصے میں مجھے برداشت عطا فرما۔**",
        "lost": "اللهم دلّني على صراطك المستقيم\n**O Allah, guide me to Your straight path.**\n**یا اللہ! مجھے اپنے سیدھے راستے پر چلا۔**",
        "tired": "اللهم جدد طاقتي، وارزقني راحة البال\n**O Allah, renew my energy and grant me peace of mind.**\n**یا اللہ! میری طاقت کو تازہ کر اور مجھے ذہنی سکون عطا فرما۔**",
        "afraid": "ربِّ أعني ولا تعن عليّ\n**My Lord, support me and not against me.**\n**میرے رب! میری مدد فرما، میرے خلاف نہ ہو۔**"
    }

    st.markdown("### 🤲 Dua (English + Urdu)")
    st.markdown(dua_map.get(selected_mood, "May Allah ease your situation."))

    # 3. Hadith (Mood-related inspiration)
    hadith_map = {
        "anxious": "The Prophet ﷺ said: *Verily, in the remembrance of Allah do hearts find rest.*",
        "sad": "The Prophet ﷺ said: *Indeed with hardship comes ease.*",
        "hopeless": "The Prophet ﷺ said: *No one relies upon Allah except that He is sufficient for him.*",
        "grateful": "The Prophet ﷺ said: *He who does not thank people, does not thank Allah.*",
        "lonely": "The Prophet ﷺ said: *I am closer to the believers than their own selves.*",
        "angry": "The Prophet ﷺ said: *The strong man is not one who can wrestle, but the one who controls himself at the time of anger.*",
        "lost": "The Prophet ﷺ said: *Whoever seeks a path in search of knowledge, Allah will ease his path to Paradise.*",
        "tired": "The Prophet ﷺ said: *Every hardship a believer experiences removes sin.*",
        "afraid": "The Prophet ﷺ said: *Be mindful of Allah, He will protect you.*"
    }

    st.markdown("### 🌟 Inspirational Hadith")
    st.info(hadith_map.get(selected_mood, "May peace and strength be with you."))

    # 4. Reflections
    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)
        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']}")