Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -6,20 +6,22 @@ import requests
|
|
6 |
from datetime import datetime
|
7 |
from dotenv import load_dotenv
|
8 |
|
|
|
9 |
st.set_page_config(page_title="Kalam Comfort", page_icon="📚")
|
10 |
load_dotenv()
|
11 |
|
12 |
-
#
|
13 |
default_moods = {
|
14 |
-
"anxious": ["13:28", "2:286", "10:62"
|
15 |
-
"sad": ["94:5", "93:6", "65:7"
|
16 |
-
"hopeless": ["39:53", "12:87", "3:139"
|
17 |
-
"grateful": ["14:7", "31:12"
|
18 |
-
"lonely": ["2:186", "9:40"
|
19 |
-
"angry": ["3:134", "41:34"
|
20 |
-
"lost": ["93:7", "6:122"
|
21 |
-
"tired": ["94:6", "3:200"
|
22 |
-
"afraid": ["8:46", "33:3",
|
|
|
23 |
}
|
24 |
|
25 |
default_duas = {
|
@@ -67,130 +69,121 @@ default_duas = {
|
|
67 |
("ربِّ أعني ولا تعن عليّ", "My Lord, support me and not against me.", "میرے رب! میری مدد فرما، میرے خلاف نہ ہو۔"),
|
68 |
("اللهم اجعلني من المتوكلين عليك", "O Allah, make me among those who rely on You.", "یا اللہ! مجھے اپنے اوپر بھروسہ کرنے والوں میں شامل فرما۔"),
|
69 |
("اللهم احفظني من بين يديّ ومن خلفي", "O Allah, protect me from in front of me and behind me.", "یا اللہ! میرے آگے پیچھے سے میری حفاظت فرما۔")
|
|
|
|
|
|
|
|
|
|
|
70 |
]
|
71 |
}
|
72 |
|
73 |
-
|
74 |
default_hadiths = {
|
75 |
"anxious": [
|
76 |
("أَلَا بِذِكْرِ اللَّهِ تَطْمَئِنُّ الْقُلُوبُ", "Verily, in the remembrance of Allah do hearts find rest.", "خبردار! اللہ کے ذکر سے دلوں کو سکون ملتا ہے۔"),
|
77 |
-
("
|
78 |
-
("
|
79 |
],
|
80 |
"sad": [
|
81 |
("إِنَّ مَعَ الْعُسْرِ يُسْرًا", "Indeed, with hardship comes ease.", "بیشک ہر تنگی کے ساتھ آسانی ہے۔"),
|
82 |
-
("لَا
|
83 |
-
("
|
84 |
],
|
85 |
"hopeless": [
|
86 |
("مَن تَوَكَّلَ عَلَى اللَّهِ فَهُوَ حَسْبُهُ", "Whoever relies upon Allah — He is sufficient for him.", "جو اللہ پر بھروسہ کرے، وہ اس کے لیے کافی ہے۔"),
|
87 |
-
("
|
88 |
-
("
|
89 |
],
|
90 |
"grateful": [
|
91 |
("مَن لَا يَشْكُرُ النَّاسَ لَا يَشْكُرُ اللَّهَ", "He who does not thank people does not thank Allah.", "جو لوگوں کا شکر ادا نہیں کرتا، وہ اللہ کا بھی شکر نہیں کرتا۔"),
|
92 |
-
("
|
93 |
-
("
|
94 |
],
|
95 |
"lonely": [
|
96 |
("أَنَا أَوْلَى بِالْمُؤْمِنِينَ مِنْ أَنْفُسِهِمْ", "I am closer to the believers than their own selves.", "میں مومنوں سے ان کی اپنی جانوں سے بھی زیادہ قریب ہوں۔"),
|
97 |
-
("إِنِّي مَعَكُمَا أَسْمَعُ وَأَرَى", "Indeed, I am with you both; I hear and
|
98 |
-
("
|
99 |
],
|
100 |
"angry": [
|
101 |
-
("لَيْسَ الشَّدِيدُ بِالصُّرَعَةِ...", "The strong
|
102 |
-
("
|
103 |
-
("
|
104 |
],
|
105 |
"lost": [
|
106 |
-
("مَنْ سَلَكَ طَرِيقًا يَلْتَمِسُ فِيهِ عِلْمًا...", "Whoever
|
107 |
-
("
|
108 |
-
("
|
109 |
],
|
110 |
"tired": [
|
111 |
-
("مَا يُصِيبُ الْمُسْلِمَ مِنْ نَصَبٍ...", "No fatigue
|
112 |
-
("وَاصْبِرْ وَمَا صَبْرُكَ إِلَّا بِاللَّهِ", "
|
113 |
-
("
|
114 |
],
|
115 |
"afraid": [
|
116 |
-
("احْفَظِ اللَّهَ يَحْفَظْكَ", "Be mindful of Allah
|
117 |
-
("
|
118 |
-
("
|
|
|
|
|
|
|
|
|
|
|
119 |
]
|
120 |
}
|
121 |
|
122 |
|
123 |
-
# File
|
124 |
if not os.path.exists("moods.json"):
|
125 |
with open("moods.json", "w") as f:
|
126 |
json.dump(default_moods, f, indent=4)
|
127 |
-
|
128 |
if not os.path.exists("reflections.json"):
|
129 |
with open("reflections.json", "w") as f:
|
130 |
-
json.dump({}, f)
|
131 |
|
132 |
-
|
133 |
-
with open("moods.json", "r") as f:
|
134 |
moods = json.load(f)
|
135 |
-
with open("reflections.json"
|
136 |
reflections = json.load(f)
|
137 |
|
138 |
-
#
|
139 |
st.title("📚 Kalam Comfort")
|
140 |
st.subheader("Find Quranic comfort by emotion 💖")
|
141 |
|
142 |
selected_mood = st.selectbox("How are you feeling today?", list(moods.keys()), index=0)
|
143 |
|
144 |
-
if st.button("🔁 Show another verse"):
|
145 |
-
st.rerun()
|
146 |
-
|
147 |
if selected_mood:
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
quran_api = f"https://api.alquran.cloud/v1/ayah/{surah_num}:{ayah_num}/editions/quran-simple,en.asad,ur.jalandhry"
|
154 |
-
response = requests.get(quran_api)
|
155 |
|
156 |
if response.status_code == 200:
|
157 |
-
data = response.json()[
|
158 |
-
arabic = data[0]['text']
|
159 |
-
english = data[1]['text']
|
160 |
-
urdu = data[2]['text']
|
161 |
-
surah_info = f"{data[0]['surah']['englishName']} ({data[0]['surah']['name']})"
|
162 |
-
|
163 |
st.markdown("### 🌙 Quranic Verse")
|
164 |
-
st.markdown(f"**Surah:** {
|
165 |
-
st.markdown(f"<div style='font-size:24px; direction: rtl'>{
|
166 |
-
st.markdown(f"**📖 English:** *{
|
167 |
-
st.markdown(f"**📖 Urdu:** {
|
168 |
else:
|
169 |
-
st.error("
|
170 |
-
st.stop()
|
171 |
|
172 |
-
# ---------- Dua ----------
|
173 |
st.markdown("### 🤲 Dua")
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
# ---------- Hadith ----------
|
181 |
-
st.markdown("### 🌟 Hadith")
|
182 |
if selected_mood in default_hadiths:
|
183 |
-
|
184 |
-
st.markdown(
|
185 |
-
st.markdown(f"**
|
186 |
-
st.markdown(f"**
|
187 |
-
|
188 |
-
|
189 |
-
st.markdown("### 📝
|
190 |
-
|
191 |
if st.button("💾 Save Reflection"):
|
192 |
reflections[selected_mood] = {
|
193 |
-
"text":
|
194 |
"timestamp": datetime.now().strftime("%Y-%m-%d %H:%M")
|
195 |
}
|
196 |
with open("reflections.json", "w") as f:
|
@@ -199,5 +192,8 @@ if selected_mood:
|
|
199 |
|
200 |
if selected_mood in reflections:
|
201 |
last = reflections[selected_mood]
|
202 |
-
st.markdown("####
|
203 |
st.markdown(f"**{last['timestamp']}** — {last['text']}")
|
|
|
|
|
|
|
|
6 |
from datetime import datetime
|
7 |
from dotenv import load_dotenv
|
8 |
|
9 |
+
# --- Streamlit Config ---
|
10 |
st.set_page_config(page_title="Kalam Comfort", page_icon="📚")
|
11 |
load_dotenv()
|
12 |
|
13 |
+
# --- Default Mappings ---
|
14 |
default_moods = {
|
15 |
+
"anxious": ["13:28", "2:286", "10:62"],
|
16 |
+
"sad": ["94:5", "93:6", "65:7"],
|
17 |
+
"hopeless": ["39:53", "12:87", "3:139"],
|
18 |
+
"grateful": ["14:7", "31:12"],
|
19 |
+
"lonely": ["2:186", "9:40"],
|
20 |
+
"angry": ["3:134", "41:34"],
|
21 |
+
"lost": ["93:7", "6:122"],
|
22 |
+
"tired": ["94:6", "3:200"],
|
23 |
+
"afraid": ["8:46", "33:3"],
|
24 |
+
"happy": ["16:18", "28:70", "55:13"]
|
25 |
}
|
26 |
|
27 |
default_duas = {
|
|
|
69 |
("ربِّ أعني ولا تعن عليّ", "My Lord, support me and not against me.", "میرے رب! میری مدد فرما، میرے خلاف نہ ہو۔"),
|
70 |
("اللهم اجعلني من المتوكلين عليك", "O Allah, make me among those who rely on You.", "یا اللہ! مجھے اپنے اوپر بھروسہ کرنے والوں میں شامل فرما۔"),
|
71 |
("اللهم احفظني من بين يديّ ومن خلفي", "O Allah, protect me from in front of me and behind me.", "یا اللہ! میرے آگے پیچھے سے میری حفاظت فرما۔")
|
72 |
+
],
|
73 |
+
"happy": [
|
74 |
+
("اللهم اجعل سعادتي دائمة", "O Allah, make my happiness everlasting.", "یا اللہ! میری خوشی کو دائمی بنا دے۔"),
|
75 |
+
("اللهم كما أسعدتني فأسعد قلبي دومًا بذكرك", "O Allah, as You made me happy, keep my heart joyful with Your remembrance.", "یا اللہ! جیسے تو نے مجھے خوشی دی، ویسے ہی اپنے ذکر سے میرے دل کو ہمیشہ خوش رکھ۔"),
|
76 |
+
("اللهم بارك لي في نعمك ولا تجعلني من الغافلين", "O Allah, bless me in Your blessings and don’t make me among the heedless.", "یا اللہ! اپنی نعمتوں میں برکت عطا فرما اور مجھے غافلوں میں سے نہ بنا۔")
|
77 |
]
|
78 |
}
|
79 |
|
|
|
80 |
default_hadiths = {
|
81 |
"anxious": [
|
82 |
("أَلَا بِذِكْرِ اللَّهِ تَطْمَئِنُّ الْقُلُوبُ", "Verily, in the remembrance of Allah do hearts find rest.", "خبردار! اللہ کے ذکر سے دلوں کو سکون ملتا ہے۔"),
|
83 |
+
("إِذَا سَأَلْتَ فَاسْأَلِ اللَّهَ", "If you ask, ask Allah.", "اگر سوال کرو تو اللہ سے کرو۔"),
|
84 |
+
("اللَّهُ أَرْحَمُ بِعِبَادِهِ", "Allah is more merciful to His slaves than a mother to her child.", "اللہ اپنے بندوں پر ماں سے بھی زیادہ رحم کرنے والا ہے۔")
|
85 |
],
|
86 |
"sad": [
|
87 |
("إِنَّ مَعَ الْعُسْرِ يُسْرًا", "Indeed, with hardship comes ease.", "بیشک ہر تنگی کے ساتھ آسانی ہے۔"),
|
88 |
+
("لَا يَحْزُنكَ قَوْلُهُمْ", "Let not their words grieve you.", "ان کی باتیں آپ کو غمگین نہ کریں۔"),
|
89 |
+
("لَا تَحْزَنْ إِنَّ اللَّهَ مَعَنَا", "Do not grieve, indeed Allah is with us.", "غم نہ کرو، بے شک اللہ ہمارے ساتھ ہے۔")
|
90 |
],
|
91 |
"hopeless": [
|
92 |
("مَن تَوَكَّلَ عَلَى اللَّهِ فَهُوَ حَسْبُهُ", "Whoever relies upon Allah — He is sufficient for him.", "جو اللہ پر بھروسہ کرے، وہ اس کے لیے کافی ہے۔"),
|
93 |
+
("إِنَّهُ لَا يَيْأَسُ مِنْ رَوْحِ اللَّهِ", "None despairs of Allah's mercy except the disbelieving people.", "اللہ کی رحمت سے صرف کافر ہی ناامید ہوتے ہیں۔"),
|
94 |
+
("وَرَحْمَتِي وَسِعَتْ كُلَّ شَيْءٍ", "My mercy encompasses all things.", "میری رحمت ہر چیز کو محیط ہے۔")
|
95 |
],
|
96 |
"grateful": [
|
97 |
("مَن لَا يَشْكُرُ النَّاسَ لَا يَشْكُرُ اللَّهَ", "He who does not thank people does not thank Allah.", "جو لوگوں کا شکر ادا نہیں کرتا، وہ اللہ کا بھی شکر نہیں کرتا۔"),
|
98 |
+
("اللَّهُ يُحِبُّ الشَّاكِرِينَ", "Allah loves those who are grateful.", "اللہ شکر گزاروں سے محبت کرتا ہے۔"),
|
99 |
+
("وَاشْكُرُوا لِي وَلَا تَكْفُرُونِ", "Be thankful to Me and do not deny Me.", "میرا شکر ادا کرو اور ناشکری نہ کرو۔")
|
100 |
],
|
101 |
"lonely": [
|
102 |
("أَنَا أَوْلَى بِالْمُؤْمِنِينَ مِنْ أَنْفُسِهِمْ", "I am closer to the believers than their own selves.", "میں مومنوں سے ان کی اپنی جانوں سے بھی زیادہ قریب ہوں۔"),
|
103 |
+
("إِنِّي مَعَكُمَا أَسْمَعُ وَأَرَى", "Indeed, I am with you both; I hear and see.", "بے شک میں تم دونوں کے ساتھ ہوں، میں سنتا اور دیکھتا ہوں۔"),
|
104 |
+
("اللَّهُ وَلِيُّ الَّذِينَ آمَنُوا", "Allah is the protector of those who believe.", "اللہ ایمان والوں کا ولی ہے۔")
|
105 |
],
|
106 |
"angry": [
|
107 |
+
("لَيْسَ الشَّدِيدُ بِالصُّرَعَةِ...", "The strong is not the one who overcomes others in wrestling but the one who controls himself in anger.", "طاقتور وہ نہیں جو پچھاڑ دے، بلکہ وہ ہے جو غصے میں خود پر قابو رکھے۔"),
|
108 |
+
("لَا تَغْضَبْ", "Do not become angry.", "غصہ نہ کرو۔"),
|
109 |
+
("وَإِذَا مَا غَضِبُوا هُمْ يَغْفِرُونَ", "When they are angry, they forgive.", "جب وہ غصے میں ہوتے ہیں تو معاف کر دیتے ہیں۔")
|
110 |
],
|
111 |
"lost": [
|
112 |
+
("مَنْ سَلَكَ طَرِيقًا يَلْتَمِسُ فِيهِ عِلْمًا...", "Whoever treads a path in search of knowledge, Allah makes his path to Paradise easy.", "جو علم کے راستے پر چلے، اللہ اس کے لیے جنت کا راستہ آسان کر دیتا ہے۔"),
|
113 |
+
("وَوَجَدَكَ ضَالًّا فَهَدَى", "And He found you lost and guided [you].", "اور اُس نے آپ کو بھٹکا ہوا پایا، تو راہ دکھائی۔"),
|
114 |
+
("اللَّهُ نُورُ السَّمَاوَاتِ وَالْأَرْضِ", "Allah is the Light of the heavens and the earth.", "اللہ آسمانوں اور زمین کا نور ہے۔")
|
115 |
],
|
116 |
"tired": [
|
117 |
+
("مَا يُصِيبُ الْمُسْلِمَ مِنْ نَصَبٍ...", "No fatigue afflicts a Muslim except that Allah removes sins thereby.", "مسلمان کو جو بھی تھکن یا مرض لاحق ہو، اللہ اس سے اس کے گناہ مٹا دیتا ہے۔"),
|
118 |
+
("وَاصْبِرْ وَمَا صَبْرُكَ إِلَّا بِاللَّهِ", "And be patient, and your patience is not but through Allah.", "صبر کرو، اور تمہارا صبر صرف اللہ کے لیے ہے۔"),
|
119 |
+
("إِنَّ مَعَ الْعُسْرِ يُسْرًا", "Indeed, with hardship comes ease.", "بے شک تنگی کے ساتھ آسانی ہے۔")
|
120 |
],
|
121 |
"afraid": [
|
122 |
+
("احْفَظِ اللَّهَ يَحْفَظْكَ", "Be mindful of Allah and He will protect you.", "اللہ کا دھیان رکھو، وہ تمہاری حفاظت کرے گا۔"),
|
123 |
+
("لَا خَوْفٌ عَلَيْهِمْ وَلَا هُمْ يَحْزَنُونَ", "No fear will there be concerning them, nor will they grieve.", "ان پر نہ کوئی خوف ہوگا اور نہ وہ غمگین ہوں گے۔"),
|
124 |
+
("إِنَّ اللَّهَ مَعَ الَّذِينَ اتَّقَوْا", "Indeed, Allah is with those who fear Him.", "بے شک اللہ پرہیزگاروں کے ساتھ ہے۔")
|
125 |
+
],
|
126 |
+
"happy": [
|
127 |
+
("الْفَرَحُ نِعْمَةٌ مِنَ اللَّهِ", "Happiness is a blessing from Allah.", "خوشی اللہ کی طرف سے ایک نعمت ہے۔"),
|
128 |
+
("تَبَسُّمُكَ فِي وَجْهِ أَخِيكَ صَدَقَةٌ", "Smiling in the face of your brother is charity.", "اپنے بھائی کے چہرے پر مسکرانا صدقہ ہے۔"),
|
129 |
+
("إِنَّ اللَّهَ يُحِبُّ الْفَرَحِينَ بِطَاعَتِهِ", "Indeed, Allah loves those who rejoice in His obedience.", "بیشک اللہ ان لوگوں سے محبت کرتا ہے جو اس کی اطاعت میں خوش ہوتے ہیں۔")
|
130 |
]
|
131 |
}
|
132 |
|
133 |
|
134 |
+
# --- Initial File Setup ---
|
135 |
if not os.path.exists("moods.json"):
|
136 |
with open("moods.json", "w") as f:
|
137 |
json.dump(default_moods, f, indent=4)
|
|
|
138 |
if not os.path.exists("reflections.json"):
|
139 |
with open("reflections.json", "w") as f:
|
140 |
+
json.dump({}, f, indent=4)
|
141 |
|
142 |
+
with open("moods.json") as f:
|
|
|
143 |
moods = json.load(f)
|
144 |
+
with open("reflections.json") as f:
|
145 |
reflections = json.load(f)
|
146 |
|
147 |
+
# --- UI ---
|
148 |
st.title("📚 Kalam Comfort")
|
149 |
st.subheader("Find Quranic comfort by emotion 💖")
|
150 |
|
151 |
selected_mood = st.selectbox("How are you feeling today?", list(moods.keys()), index=0)
|
152 |
|
|
|
|
|
|
|
153 |
if selected_mood:
|
154 |
+
verse_ref = random.choice(moods[selected_mood])
|
155 |
+
surah, ayah = verse_ref.split(":")
|
156 |
+
url = f"https://api.alquran.cloud/v1/ayah/{surah}:{ayah}/editions/quran-simple,en.asad,ur.jalandhry"
|
157 |
+
response = requests.get(url)
|
|
|
|
|
|
|
158 |
|
159 |
if response.status_code == 200:
|
160 |
+
data = response.json()["data"]
|
|
|
|
|
|
|
|
|
|
|
161 |
st.markdown("### 🌙 Quranic Verse")
|
162 |
+
st.markdown(f"**Surah:** {data[0]['surah']['englishName']} — Ayah {ayah}")
|
163 |
+
st.markdown(f"<div style='font-size:24px; direction: rtl'>{data[0]['text']}</div>", unsafe_allow_html=True)
|
164 |
+
st.markdown(f"**📖 English:** *{data[1]['text']}*")
|
165 |
+
st.markdown(f"**📖 Urdu:** {data[2]['text']}")
|
166 |
else:
|
167 |
+
st.error("Failed to fetch Quranic verse.")
|
|
|
168 |
|
|
|
169 |
st.markdown("### 🤲 Dua")
|
170 |
+
dua = random.choice(default_duas[selected_mood])
|
171 |
+
st.markdown(f"**Arabic:** {dua[0]}")
|
172 |
+
st.markdown(f"**English:** *{dua[1]}*")
|
173 |
+
st.markdown(f"**Urdu:** {dua[2]}")
|
174 |
+
|
|
|
|
|
|
|
175 |
if selected_mood in default_hadiths:
|
176 |
+
hadith = random.choice(default_hadiths[selected_mood])
|
177 |
+
st.markdown("### 📜 Hadith")
|
178 |
+
st.markdown(f"**Arabic:** {hadith[0]}")
|
179 |
+
st.markdown(f"**English:** *{hadith[1]}*")
|
180 |
+
st.markdown(f"**Urdu:** {hadith[2]}")
|
181 |
+
|
182 |
+
st.markdown("### 📝 Reflection")
|
183 |
+
reflection = st.text_area("Write your reflection:")
|
184 |
if st.button("💾 Save Reflection"):
|
185 |
reflections[selected_mood] = {
|
186 |
+
"text": reflection,
|
187 |
"timestamp": datetime.now().strftime("%Y-%m-%d %H:%M")
|
188 |
}
|
189 |
with open("reflections.json", "w") as f:
|
|
|
192 |
|
193 |
if selected_mood in reflections:
|
194 |
last = reflections[selected_mood]
|
195 |
+
st.markdown("#### 📄 Last Reflection")
|
196 |
st.markdown(f"**{last['timestamp']}** — {last['text']}")
|
197 |
+
|
198 |
+
if st.button("🔁 Show another"):
|
199 |
+
st.rerun()
|