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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -26
app.py CHANGED
@@ -11,15 +11,15 @@ load_dotenv()
11
 
12
  # ---------- File Setup ----------
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
  if not os.path.exists("moods.json"):
@@ -34,9 +34,6 @@ if not os.path.exists("reflections.json"):
34
  with open("reflections.json", "r") as f:
35
  reflections = json.load(f)
36
 
37
- if not os.path.exists(".env"):
38
- st.warning("⚠️ Optional: .env file not found. It's not required unless using secrets.")
39
-
40
  # ---------- UI ----------
41
  st.title("📚 Kalam Comfort")
42
  st.subheader("Find Quranic comfort by emotion 💖")
@@ -71,20 +68,7 @@ if selected_mood:
71
  st.error("❌ Failed to fetch Quranic text.")
72
  st.stop()
73
 
74
- # 2. Tafsir (Urdu)
75
- tafsir_api = f"https://api.quranenc.com/v1/translation/tafsir?language=ur&verse_id={surah_num}:{ayah_num}"
76
- tafsir_text = "Tafsir not available."
77
- try:
78
- tafsir_response = requests.get(tafsir_api)
79
- if tafsir_response.status_code == 200:
80
- tafsir_text = tafsir_response.json().get("result", {}).get("tafsir", "Tafsir not found.")
81
- except Exception as e:
82
- tafsir_text = "Could not fetch tafsir."
83
-
84
- st.markdown("### 📘 Tafsir (Urdu)")
85
- st.info(tafsir_text)
86
-
87
- # 3. Dua (Mood-based, bilingual)
88
  dua_map = {
89
  "anxious": "اللهم اجعل قلبي مطمئنًا بذكرك\n**O Allah, make my heart tranquil with Your remembrance.**\n**یا اللہ! میرے دل کو اپنے ذکر سے اطمینان دے۔**",
90
  "sad": "اللهم اجبر قلبي جبرا يتعجب له أهل السماوات والأرض\n**O Allah, mend my heart in a way that amazes the heavens and earth.**\n**یا اللہ! میرے دل کو ایسا سہارا دے جو زمین و آسمان کو حیران کر دے۔**",
@@ -100,6 +84,22 @@ if selected_mood:
100
  st.markdown("### 🤲 Dua (English + Urdu)")
101
  st.markdown(dua_map.get(selected_mood, "May Allah ease your situation."))
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?")
 
11
 
12
  # ---------- File Setup ----------
13
  default_moods = {
14
+ "anxious": ["13:28", "2:286", "10:62", "20:46", "48:4"],
15
+ "sad": ["94:5", "93:6", "65:7", "9:51", "12:86"],
16
+ "hopeless": ["39:53", "12:87", "3:139", "65:2", "57:22"],
17
+ "grateful": ["14:7", "31:12", "2:152", "16:114", "76:3"],
18
+ "lonely": ["2:186", "9:40", "6:103", "50:16", "17:79"],
19
+ "angry": ["3:134", "41:34", "7:199", "42:37", "16:126"],
20
+ "lost": ["93:7", "6:122", "2:2", "24:35", "42:52"],
21
+ "tired": ["94:6", "3:200", "29:69", "52:48", "6:162"],
22
+ "afraid": ["8:46", "33:3", "2:286", "3:173", "11:56"]
23
  }
24
 
25
  if not os.path.exists("moods.json"):
 
34
  with open("reflections.json", "r") as f:
35
  reflections = json.load(f)
36
 
 
 
 
37
  # ---------- UI ----------
38
  st.title("📚 Kalam Comfort")
39
  st.subheader("Find Quranic comfort by emotion 💖")
 
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**یا اللہ! میرے دل کو ایسا سہارا دے جو زمین و آسمان کو حیران کر دے۔**",
 
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?")