ashhal commited on
Commit
c110a4c
·
verified ·
1 Parent(s): 9657db2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +123 -38
app.py CHANGED
@@ -22,15 +22,117 @@ default_moods = {
22
  "afraid": ["8:46", "33:3", "2:286", "3:173", "11:56"]
23
  }
24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  if not os.path.exists("moods.json"):
26
  with open("moods.json", "w") as f:
27
  json.dump(default_moods, f, indent=4)
28
- with open("moods.json", "r") as f:
29
- moods = json.load(f)
30
 
31
  if not os.path.exists("reflections.json"):
32
  with open("reflections.json", "w") as f:
33
  json.dump({}, f)
 
 
 
 
34
  with open("reflections.json", "r") as f:
35
  reflections = json.load(f)
36
 
@@ -44,11 +146,11 @@ if st.button("🔁 Show another verse"):
44
  st.rerun()
45
 
46
  if selected_mood:
 
47
  verse_list = moods[selected_mood]
48
  verse_ref = random.choice(verse_list)
49
  surah_num, ayah_num = verse_ref.split(":")
50
 
51
- # 1. Quran Arabic, English, Urdu
52
  quran_api = f"https://api.alquran.cloud/v1/ayah/{surah_num}:{ayah_num}/editions/quran-simple,en.asad,ur.jalandhry"
53
  response = requests.get(quran_api)
54
 
@@ -65,45 +167,28 @@ if selected_mood:
65
  st.markdown(f"**📖 English:** *{english}*")
66
  st.markdown(f"**📖 Urdu:** {urdu}")
67
  else:
68
- st.error("❌ Failed to fetch Quranic text.")
69
  st.stop()
70
 
71
- # 2. Dua (Mood-based, bilingual)
72
- dua_map = {
73
- "anxious": "اللهم اجعل قلبي مطمئنًا بذكرك\n**O Allah, make my heart tranquil with Your remembrance.**\n**یا اللہ! میرے دل کو اپنے ذکر سے اطمینان دے۔**",
74
- "sad": "اللهم اجبر قلبي جبرا يتعجب له أهل السماوات والأرض\n**O Allah, mend my heart in a way that amazes the heavens and earth.**\n**یا اللہ! میرے دل کو ایسا سہارا دے جو زمین و آسمان کو حیران کر دے۔**",
75
- "hopeless": "رب لا تذرني فردا وأنت خير الوارثين\n**My Lord, do not leave me alone — You are the Best Inheritor.**\n**یا رب! مجھے تنہا نہ چھوڑ، تو بہترین وارث ہے۔**",
76
- "grateful": "اللهم اجعلني لك شَكُورًا\n**O Allah, make me deeply grateful to You.**\n**یا اللہ! مجھے شکر گزار بنا دے۔**",
77
- "lonely": "اللهم كن معي حين لا يكون أحد بجانبي\n**O Allah, be with me when no one else is.**\n**یا اللہ! جب کوئی ساتھ نہ ہو، تو میرے ساتھ ہو۔**",
78
- "angry": "اللهم ارزقني الحلم عند الغضب\n**O Allah, grant me forbearance when I’m angry.**\n**یا اللہ! غصے میں مجھے برداشت عطا فرما۔**",
79
- "lost": "اللهم دلّني على صراطك المستقيم\n**O Allah, guide me to Your straight path.**\n**یا اللہ! مجھے اپنے سیدھے راستے پر چلا۔**",
80
- "tired": "اللهم جدد طاقتي، وارزقني راحة البال\n**O Allah, renew my energy and grant me peace of mind.**\n**یا اللہ! میری طاقت کو تازہ کر اور مجھے ذہنی سکون عطا فرما۔**",
81
- "afraid": "ربِّ أعني ولا تعن عليّ\n**My Lord, support me and not against me.**\n**میرے رب! میری مدد فرما، میرے خلاف نہ ہو۔**"
82
- }
83
-
84
- st.markdown("### 🤲 Dua (English + Urdu)")
85
- st.markdown(dua_map.get(selected_mood, "May Allah ease your situation."))
86
-
87
- # 3. Hadith (Mood-related inspiration)
88
- hadith_map = {
89
- "anxious": "The Prophet ﷺ said: *Verily, in the remembrance of Allah do hearts find rest.*",
90
- "sad": "The Prophet ﷺ said: *Indeed with hardship comes ease.*",
91
- "hopeless": "The Prophet ﷺ said: *No one relies upon Allah except that He is sufficient for him.*",
92
- "grateful": "The Prophet ﷺ said: *He who does not thank people, does not thank Allah.*",
93
- "lonely": "The Prophet ﷺ said: *I am closer to the believers than their own selves.*",
94
- "angry": "The Prophet ﷺ said: *The strong man is not one who can wrestle, but the one who controls himself at the time of anger.*",
95
- "lost": "The Prophet ﷺ said: *Whoever seeks a path in search of knowledge, Allah will ease his path to Paradise.*",
96
- "tired": "The Prophet ﷺ said: *Every hardship a believer experiences removes sin.*",
97
- "afraid": "The Prophet ﷺ said: *Be mindful of Allah, He will protect you.*"
98
- }
99
-
100
- st.markdown("### 🌟 Inspirational Hadith")
101
- st.info(hadith_map.get(selected_mood, "May peace and strength be with you."))
102
-
103
- # 4. Reflections
104
  st.markdown("### 📝 Your Reflection")
105
  reflection_input = st.text_area("Write your thoughts:", placeholder="How does this verse speak to you today?")
106
-
107
  if st.button("💾 Save Reflection"):
108
  reflections[selected_mood] = {
109
  "text": reflection_input,
 
22
  "afraid": ["8:46", "33:3", "2:286", "3:173", "11:56"]
23
  }
24
 
25
+ default_duas = {
26
+ "anxious": [
27
+ ("اللهم اجعل قلبي مطمئنًا بذكرك",
28
+ "O Allah, make my heart tranquil with Your remembrance.",
29
+ "یا اللہ! میرے دل کو اپنے ذکر سے اطمینان دے۔"),
30
+ ("اللهم لا سهل إلا ما جعلته سهلا",
31
+ "O Allah, nothing is easy except what You make easy.",
32
+ "یا اللہ! کچھ بھی آسان نہیں سوائے اس کے جسے تُو آسان کرے۔")
33
+ ],
34
+ "sad": [
35
+ ("اللهم اجبر قلبي جبرا يتعجب له أهل السماوات والأرض",
36
+ "O Allah, mend my heart in a way that amazes the heavens and the earth.",
37
+ "یا اللہ! میرے دل کو ایسا سہارا دے جو زمین و آسمان کو حیران کر دے۔")
38
+ ],
39
+ "hopeless": [
40
+ ("رب لا تذرني فردا وأنت خير الوارثين",
41
+ "My Lord, do not leave me alone — You are the Best Inheritor.",
42
+ "یا رب! مجھے تنہا نہ چھوڑ، تو بہترین وارث ہے۔")
43
+ ],
44
+ "grateful": [
45
+ ("اللهم اجعلني لك شَكُورًا",
46
+ "O Allah, make me deeply grateful to You.",
47
+ "یا اللہ! مجھے شکر گزار بنا دے۔")
48
+ ],
49
+ "lonely": [
50
+ ("اللهم كن معي حين لا يكون أحد بجانبي",
51
+ "O Allah, be with me when no one else is.",
52
+ "یا اللہ! جب کوئی ساتھ نہ ہو، تو میرے ساتھ ہو۔")
53
+ ],
54
+ "angry": [
55
+ ("اللهم ارزقني الحلم عند الغضب",
56
+ "O Allah, grant me forbearance when I’m angry.",
57
+ "یا اللہ! غصے میں مجھے برداشت عطا فرما۔")
58
+ ],
59
+ "lost": [
60
+ ("اللهم دلّني على صراطك المستقيم",
61
+ "O Allah, guide me to Your straight path.",
62
+ "یا اللہ! مجھے اپنے سیدھے راستے پر چلا۔")
63
+ ],
64
+ "tired": [
65
+ ("اللهم جدد طاقتي، وارزقني راحة البال",
66
+ "O Allah, renew my energy and grant me peace of mind.",
67
+ "یا اللہ! میری طاقت کو تازہ کر اور مجھے ذہنی سکون عطا فرما۔")
68
+ ],
69
+ "afraid": [
70
+ ("ربِّ أعني ولا تعن عليّ",
71
+ "My Lord, support me and not against me.",
72
+ "میرے رب! میری مدد فرما، میرے خلاف نہ ہو۔")
73
+ ]
74
+ }
75
+
76
+ default_hadiths = {
77
+ "anxious": [
78
+ ("أَلَا بِذِكْرِ اللَّهِ تَطْمَئِنُّ الْقُلُوبُ",
79
+ "Verily, in the remembrance of Allah do hearts find rest.",
80
+ "خبردار! اللہ کے ذکر سے دلوں کو سکون ملتا ہے۔")
81
+ ],
82
+ "sad": [
83
+ ("إِنَّ مَعَ الْعُسْرِ يُسْرًا",
84
+ "Indeed, with hardship comes ease.",
85
+ "بیشک ہر تنگی کے ساتھ آسانی ہے۔")
86
+ ],
87
+ "hopeless": [
88
+ ("مَن تَوَكَّلَ عَلَى اللَّهِ فَهُوَ حَسْبُهُ",
89
+ "Whoever relies upon Allah — He is sufficient for him.",
90
+ "جو اللہ پر بھروسہ کرے، وہ اس کے لیے کافی ہے۔")
91
+ ],
92
+ "grateful": [
93
+ ("مَن لَا يَشْكُرُ النَّاسَ لَا يَشْكُرُ اللَّهَ",
94
+ "He who does not thank people does not thank Allah.",
95
+ "جو لوگوں کا شکر ادا نہیں کرتا، وہ اللہ کا بھی شکر نہیں کرتا۔")
96
+ ],
97
+ "lonely": [
98
+ ("أَنَا أَوْلَى بِالْمُؤْمِنِينَ مِنْ أَنْفُسِهِمْ",
99
+ "I am closer to the believers than their own selves.",
100
+ "میں مومنوں سے ان کی اپنی جانوں سے بھی زیادہ قریب ہوں۔")
101
+ ],
102
+ "angry": [
103
+ ("لَيْسَ الشَّدِيدُ بِالصُّرَعَةِ...",
104
+ "The strong man is not the one who wrestles, but controls himself in anger.",
105
+ "طاقتور وہ نہیں جو پچھاڑ دے، بلکہ وہ ہے جو غصے میں خود پر قابو رکھے۔")
106
+ ],
107
+ "lost": [
108
+ ("مَنْ سَلَكَ طَرِيقًا يَلْتَمِسُ فِيهِ عِلْمًا...",
109
+ "Whoever seeks a path in search of knowledge, Allah will ease his path to Paradise.",
110
+ "جو علم کے راستے پر چلے، اللہ اس کے لیے جنت کا راستہ آسان کر دیتا ہے۔")
111
+ ],
112
+ "tired": [
113
+ ("مَا يُصِيبُ الْمُسْلِمَ مِنْ نَصَبٍ...",
114
+ "No fatigue or disease affects a Muslim except that Allah removes sins.",
115
+ "مسلمان کو جو بھی تھکن یا مرض لاحق ہو، اللہ اس سے اس کے گناہ مٹا دیتا ہے۔")
116
+ ],
117
+ "afraid": [
118
+ ("احْفَظِ ��للَّهَ يَحْفَظْكَ",
119
+ "Be mindful of Allah, He will protect you.",
120
+ "اللہ کا دھیان رکھو، وہ تمہاری حفاظت کرے گا۔")
121
+ ]
122
+ }
123
+
124
+ # File creation if missing
125
  if not os.path.exists("moods.json"):
126
  with open("moods.json", "w") as f:
127
  json.dump(default_moods, f, indent=4)
 
 
128
 
129
  if not os.path.exists("reflections.json"):
130
  with open("reflections.json", "w") as f:
131
  json.dump({}, f)
132
+
133
+ # Load data
134
+ with open("moods.json", "r") as f:
135
+ moods = json.load(f)
136
  with open("reflections.json", "r") as f:
137
  reflections = json.load(f)
138
 
 
146
  st.rerun()
147
 
148
  if selected_mood:
149
+ # ----------- Quranic Verse -----------
150
  verse_list = moods[selected_mood]
151
  verse_ref = random.choice(verse_list)
152
  surah_num, ayah_num = verse_ref.split(":")
153
 
 
154
  quran_api = f"https://api.alquran.cloud/v1/ayah/{surah_num}:{ayah_num}/editions/quran-simple,en.asad,ur.jalandhry"
155
  response = requests.get(quran_api)
156
 
 
167
  st.markdown(f"**📖 English:** *{english}*")
168
  st.markdown(f"**📖 Urdu:** {urdu}")
169
  else:
170
+ st.error("❌ Failed to fetch Quranic verse.")
171
  st.stop()
172
 
173
+ # ---------- Dua ----------
174
+ st.markdown("### 🤲 Dua")
175
+ if selected_mood in default_duas:
176
+ dua_ar, dua_en, dua_ur = random.choice(default_duas[selected_mood])
177
+ st.markdown(f"<div style='font-size:22px; direction: rtl'>{dua_ar}</div>", unsafe_allow_html=True)
178
+ st.markdown(f"**English:** {dua_en}")
179
+ st.markdown(f"**Urdu:** {dua_ur}")
180
+
181
+ # ---------- Hadith ----------
182
+ st.markdown("### 🌟 Hadith")
183
+ if selected_mood in default_hadiths:
184
+ had_ar, had_en, had_ur = random.choice(default_hadiths[selected_mood])
185
+ st.markdown(f"<div style='font-size:20px; direction: rtl'>{had_ar}</div>", unsafe_allow_html=True)
186
+ st.markdown(f"**English:** {had_en}")
187
+ st.markdown(f"**Urdu:** {had_ur}")
188
+
189
+ # ---------- Reflection ----------
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
190
  st.markdown("### 📝 Your Reflection")
191
  reflection_input = st.text_area("Write your thoughts:", placeholder="How does this verse speak to you today?")
 
192
  if st.button("💾 Save Reflection"):
193
  reflections[selected_mood] = {
194
  "text": reflection_input,