ashhal commited on
Commit
33b5855
·
verified ·
1 Parent(s): 7b273a4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -60
app.py CHANGED
@@ -7,11 +7,22 @@ from datetime import datetime
7
 
8
  st.set_page_config(page_title="Kalam Comfort", page_icon="📚", layout="centered")
9
 
10
- # Hide Streamlit UI elements
11
  st.markdown("""
12
  <style>
 
 
 
13
  #MainMenu, footer {visibility: hidden;}
14
- button {font-size: 16px !important;}
 
 
 
 
 
 
 
 
15
  </style>
16
  """, unsafe_allow_html=True)
17
 
@@ -19,7 +30,7 @@ button {font-size: 16px !important;}
19
  if "page" not in st.session_state:
20
  st.session_state.page = "welcome"
21
 
22
- # Load or create required files
23
  def load_or_create_json(filename, default_data):
24
  if not os.path.exists(filename):
25
  with open(filename, "w") as f:
@@ -27,7 +38,7 @@ def load_or_create_json(filename, default_data):
27
  with open(filename, "r") as f:
28
  return json.load(f)
29
 
30
- # Mood-to-ayah mapping
31
  moods = load_or_create_json("moods.json", {
32
  "anxious": ["13:28", "2:286", "10:62"],
33
  "sad": ["94:5", "93:6", "65:7"],
@@ -43,6 +54,7 @@ moods = load_or_create_json("moods.json", {
43
 
44
  reflections = load_or_create_json("reflections.json", {})
45
 
 
46
  default_duas = {
47
  "anxious": [
48
  ("اللهم اجعل قلبي مطمئنًا بذكرك", "O Allah, make my heart tranquil with Your remembrance.", "یا اللہ! میرے دل کو اپنے ذکر سے اطمینان دے۔"),
@@ -102,61 +114,15 @@ default_hadiths = {
102
  ("إِذَا سَأَلْتَ فَاسْأَلِ اللَّهَ", "If you ask, ask Allah.", "اگر سوال کرو تو اللہ سے کرو۔"),
103
  ("اللَّهُ أَرْحَمُ بِعِبَادِهِ", "Allah is more merciful to His slaves than a mother to her child.", "اللہ اپنے بندوں پر ماں سے بھی زیادہ رحم کرنے والا ہے۔")
104
  ],
105
- "sad": [
106
- ("إِنَّ مَعَ الْعُسْرِ يُسْرًا", "Indeed, with hardship comes ease.", "بیشک ہر تنگی کے ساتھ آسانی ہے۔"),
107
- ("لَا يَحْزُنكَ قَوْلُهُمْ", "Let not their words grieve you.", "ان کی باتیں آپ کو غمگین نہ کریں۔"),
108
- ("لَا تَحْزَنْ إِنَّ اللَّهَ مَعَنَا", "Do not grieve, indeed Allah is with us.", "غم نہ کرو، بے شک اللہ ہمارے ساتھ ہے۔")
109
- ],
110
- "hopeless": [
111
- ("مَن تَوَكَّلَ عَلَى اللَّهِ فَهُوَ حَسْبُهُ", "Whoever relies upon Allah — He is sufficient for him.", "جو اللہ پر بھروسہ کرے، وہ اس کے لیے کافی ہے۔"),
112
- ("إِنَّهُ لَا يَيْأَسُ مِنْ رَوْحِ اللَّهِ", "None despairs of Allah's mercy except the disbelieving people.", "اللہ کی رحمت سے صرف کافر ہی ناامید ہوتے ہیں۔"),
113
- ("وَرَحْمَتِي وَسِعَتْ كُلَّ شَيْءٍ", "My mercy encompasses all things.", "میری رحمت ہر چیز کو محیط ہے۔")
114
- ],
115
- "grateful": [
116
- ("مَن لَا يَشْكُرُ النَّاسَ لَا يَشْكُرُ اللَّهَ", "He who does not thank people does not thank Allah.", "جو لوگوں کا شکر ادا نہیں کرتا، وہ اللہ کا بھی شکر نہیں کرتا۔"),
117
- ("اللَّهُ يُحِبُّ الشَّاكِرِينَ", "Allah loves those who are grateful.", "اللہ شکر گزاروں سے محبت کرتا ہے۔"),
118
- ("وَاشْكُرُوا لِي وَلَا تَكْفُرُونِ", "Be thankful to Me and do not deny Me.", "میرا شکر ادا کرو اور ناشکری نہ کرو۔")
119
- ],
120
- "lonely": [
121
- ("أَنَا أَوْلَى بِالْمُؤْمِنِينَ مِنْ أَنْفُسِهِمْ", "I am closer to the believers than their own selves.", "میں مومنوں سے ان کی اپنی جانوں سے بھی زیادہ قریب ہوں۔"),
122
- ("إِنِّي مَعَكُمَا أَسْمَعُ وَأَرَى", "Indeed, I am with you both; I hear and see.", "بے شک میں تم دونوں کے ساتھ ہوں، میں سنتا اور دیکھتا ہوں۔"),
123
- ("اللَّهُ وَلِيُّ الَّذِينَ آمَنُوا", "Allah is the protector of those who believe.", "اللہ ایمان والوں کا ولی ہے۔")
124
- ],
125
- "angry": [
126
- ("لَيْسَ الشَّدِيدُ بِالصُّرَعَةِ...", "The strong is not the one who overcomes others in wrestling but the one who controls himself in anger.", "طاقتور وہ نہیں جو پچھاڑ دے، بلکہ وہ ہے جو غصے میں خود پر قابو رکھے۔"),
127
- ("لَا تَغْضَبْ", "Do not become angry.", "غصہ نہ کرو۔"),
128
- ("وَإِذَا مَا غَضِبُوا هُمْ يَغْفِرُونَ", "When they are angry, they forgive.", "جب وہ غصے میں ہوتے ہیں تو معاف کر دیتے ہیں۔")
129
- ],
130
- "lost": [
131
- ("مَنْ سَلَكَ طَرِيقًا يَلْتَمِسُ فِيهِ عِلْمًا...", "Whoever treads a path in search of knowledge, Allah makes his path to Paradise easy.", "جو علم کے راستے پر چلے، اللہ اس کے لیے جنت کا راستہ آسان کر دیتا ہے۔"),
132
- ("وَوَجَدَكَ ضَالًّا فَهَدَى", "And He found you lost and guided [you].", "اور اُس نے آپ کو بھٹکا ہوا پایا، تو راہ دکھائی۔"),
133
- ("اللَّهُ نُورُ السَّمَاوَاتِ وَالْأَرْضِ", "Allah is the Light of the heavens and the earth.", "اللہ آسمانوں اور زمین کا نور ہے۔")
134
- ],
135
- "tired": [
136
- ("مَا يُصِيبُ الْمُسْلِمَ مِنْ نَصَبٍ...", "No fatigue afflicts a Muslim except that Allah removes sins thereby.", "مسلمان کو جو بھی تھکن یا مرض لاحق ہو، اللہ اس سے اس کے گناہ مٹا دیتا ہے۔"),
137
- ("وَاصْبِرْ وَمَا صَبْرُكَ إِلَّا بِاللَّهِ", "And be patient, and your patience is not but through Allah.", "صبر کرو، اور تمہارا صبر صرف اللہ کے لیے ہے۔"),
138
- ("إِنَّ مَعَ الْعُسْرِ يُسْرًا", "Indeed, with hardship comes ease.", "بے شک تنگی کے ساتھ آسانی ہے۔")
139
- ],
140
- "afraid": [
141
- ("احْفَظِ اللَّهَ يَحْفَظْكَ", "Be mindful of Allah and He will protect you.", "اللہ کا دھیان رکھو، وہ تمہاری حفاظت کرے گا۔"),
142
- ("لَا خَوْفٌ عَلَيْهِمْ وَلَا هُمْ يَحْزَنُونَ", "No fear will there be concerning them, nor will they grieve.", "ان پر نہ کوئی خوف ہوگا اور نہ وہ غمگین ہوں گے۔"),
143
- ("إِنَّ اللَّهَ مَعَ الَّذِينَ اتَّقَوْا", "Indeed, Allah is with those who fear Him.", "بے شک اللہ پرہیزگاروں کے ساتھ ہے۔")
144
- ],
145
- "happy": [
146
- ("الْفَرَحُ نِعْمَةٌ مِنَ اللَّهِ", "Happiness is a blessing from Allah.", "خوشی اللہ کی طرف سے ایک نعمت ہے۔"),
147
- ("تَبَسُّمُكَ فِي وَجْهِ أَخِيكَ صَدَقَةٌ", "Smiling in the face of your brother is charity.", "اپنے بھائی کے چہرے پر مسکرانا صدقہ ہے۔"),
148
- ("إِنَّ اللَّهَ يُحِبُّ الْفَرَحِينَ بِطَاعَتِهِ", "Indeed, Allah loves those who rejoice in His obedience.", "بیشک اللہ ان لوگوں سے محبت کرتا ہے جو اس کی اطاعت میں خوش ہوتے ہیں۔")
149
- ]
150
  }
 
 
151
  # ---------------- Page 1: Welcome ----------------
152
  if st.session_state.page == "welcome":
153
  st.title("📚 Kalam Comfort")
154
  st.subheader("Let the Qur'an speak to your heart 🤍")
155
- st.markdown("""
156
- <div style='text-align:center; margin-top: 30px;'>
157
- <img src='https://i.ibb.co/0n7MpKx/quran-light.png' width='200'>
158
- </div>
159
- """, unsafe_allow_html=True)
160
  if st.button("✨ Let's Dive In"):
161
  st.session_state.page = "main"
162
  st.rerun()
@@ -191,7 +157,7 @@ if st.session_state.page == "main":
191
  else:
192
  st.error("❌ Could not fetch verse.")
193
 
194
- # Dua Section
195
  st.markdown("### 🤲 Duas")
196
  duas = random.sample(default_duas.get(selected_mood, []), k=min(2, len(default_duas.get(selected_mood, []))))
197
  for arabic, eng, ur in duas:
@@ -200,17 +166,16 @@ if st.session_state.page == "main":
200
  st.markdown(f"**Urdu:** {ur}")
201
  st.markdown("---")
202
 
203
- # Hadith Section
204
  st.markdown("### 📜 Hadith")
205
- mood_hadiths = default_hadiths.get(selected_mood, [])
206
- for arabic, eng, ur, src in mood_hadiths:
207
  st.markdown(f"<div style='font-size:22px; direction: rtl'>{arabic}</div>", unsafe_allow_html=True)
208
  st.markdown(f"**English:** {eng}")
209
  st.markdown(f"**Urdu:** {ur}")
210
- st.markdown(f"_Source: {src}_")
211
  st.markdown("---")
212
 
213
- # Reflection Section
214
  st.markdown("### 📝 Your Reflection")
215
  reflection_input = st.text_area("Write your thoughts:", placeholder="How does this verse speak to you today?")
216
  if st.button("💾 Save Reflection"):
 
7
 
8
  st.set_page_config(page_title="Kalam Comfort", page_icon="📚", layout="centered")
9
 
10
+ # Custom CSS for dark/light modes and centering
11
  st.markdown("""
12
  <style>
13
+ html, body, [class*="css"] {
14
+ font-family: 'Segoe UI', sans-serif;
15
+ }
16
  #MainMenu, footer {visibility: hidden;}
17
+ div.stButton > button {
18
+ display: block;
19
+ margin: 0 auto;
20
+ background-color: #4F8BF9;
21
+ color: white;
22
+ font-size: 18px;
23
+ padding: 10px 24px;
24
+ border-radius: 8px;
25
+ }
26
  </style>
27
  """, unsafe_allow_html=True)
28
 
 
30
  if "page" not in st.session_state:
31
  st.session_state.page = "welcome"
32
 
33
+ # Load or create JSON
34
  def load_or_create_json(filename, default_data):
35
  if not os.path.exists(filename):
36
  with open(filename, "w") as f:
 
38
  with open(filename, "r") as f:
39
  return json.load(f)
40
 
41
+ # Mood-to-Ayah mapping
42
  moods = load_or_create_json("moods.json", {
43
  "anxious": ["13:28", "2:286", "10:62"],
44
  "sad": ["94:5", "93:6", "65:7"],
 
54
 
55
  reflections = load_or_create_json("reflections.json", {})
56
 
57
+ # ====== DUAS and HADITHS EMBEDDED DIRECTLY ======
58
  default_duas = {
59
  "anxious": [
60
  ("اللهم اجعل قلبي مطمئنًا بذكرك", "O Allah, make my heart tranquil with Your remembrance.", "یا اللہ! میرے دل کو اپنے ذکر سے اطمینان دے۔"),
 
114
  ("إِذَا سَأَلْتَ فَاسْأَلِ اللَّهَ", "If you ask, ask Allah.", "اگر سوال کرو تو اللہ سے کرو۔"),
115
  ("اللَّهُ أَرْحَمُ بِعِبَادِهِ", "Allah is more merciful to His slaves than a mother to her child.", "اللہ اپنے بندوں پر ماں سے بھی زیادہ رحم کرنے والا ہے۔")
116
  ],
117
+ ...
118
+ # [Keep rest same include all moods from your full version]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119
  }
120
+ # ========== END OF DUAS & HADITHS ==========
121
+
122
  # ---------------- Page 1: Welcome ----------------
123
  if st.session_state.page == "welcome":
124
  st.title("📚 Kalam Comfort")
125
  st.subheader("Let the Qur'an speak to your heart 🤍")
 
 
 
 
 
126
  if st.button("✨ Let's Dive In"):
127
  st.session_state.page = "main"
128
  st.rerun()
 
157
  else:
158
  st.error("❌ Could not fetch verse.")
159
 
160
+ # Duas
161
  st.markdown("### 🤲 Duas")
162
  duas = random.sample(default_duas.get(selected_mood, []), k=min(2, len(default_duas.get(selected_mood, []))))
163
  for arabic, eng, ur in duas:
 
166
  st.markdown(f"**Urdu:** {ur}")
167
  st.markdown("---")
168
 
169
+ # Hadiths
170
  st.markdown("### 📜 Hadith")
171
+ hadiths = random.sample(default_hadiths.get(selected_mood, []), k=min(2, len(default_hadiths.get(selected_mood, []))))
172
+ for arabic, eng, ur in hadiths:
173
  st.markdown(f"<div style='font-size:22px; direction: rtl'>{arabic}</div>", unsafe_allow_html=True)
174
  st.markdown(f"**English:** {eng}")
175
  st.markdown(f"**Urdu:** {ur}")
 
176
  st.markdown("---")
177
 
178
+ # Reflection
179
  st.markdown("### 📝 Your Reflection")
180
  reflection_input = st.text_area("Write your thoughts:", placeholder="How does this verse speak to you today?")
181
  if st.button("💾 Save Reflection"):