File size: 2,463 Bytes
b69c07c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

import gradio as gr
from gtts import gTTS
import os
import random
import time
from datetime import datetime

# UI theme
theme = gr.themes.Default(
    primary_hue="blue",
    secondary_hue="blue",
    neutral_hue="gray",
    font=["Arial", "sans-serif"]
).set(
    button_primary_background_fill="*primary_200",
    button_primary_background_fill_hover="*primary_300",
    button_primary_text_color="white",
    button_secondary_background_fill="*secondary_200",
    button_secondary_background_fill_hover="*secondary_300",
    button_secondary_text_color="white",
    background_fill_primary="#f0f8ff",
    background_fill_secondary="white",
    border_color_primary="#cfe2f3",
    block_background_fill="white",
    block_label_background_fill="#e6f0ff",
    block_label_text_color="#1a5fb4",
    block_title_text_color="#1a5fb4"
)

# Spiritual content
quran_verses = {
    "Calm": "Indeed, in the remembrance of Allah do hearts find rest. (Surah Ar-Ra’d: 28)",
    "Sad": "Indeed, with hardship comes ease. (Surah Ash-Sharh: 6)"
}
hadiths = {
    "Calm": "The Prophet ﷺ said: Verily, in the remembrance of Allah do hearts find rest.",
    "Sad": "The Prophet ﷺ said: With hardship comes ease."
}
duas = {
    "Calm": "O Allah, place light in my heart.",
    "Sad": "O Allah, relieve my distress and ease my affairs."
}

# Get content by feeling
def get_content(emotion):
    return quran_verses.get(emotion, ""), hadiths.get(emotion, ""), duas.get(emotion, "")

# Convert text to audio
def text_to_speech(text):
    tts = gTTS(text=text, lang='ar')
    filename = f"audio_{int(time.time())}.mp3"
    tts.save(filename)
    return filename

# Build the Gradio app
with gr.Blocks(theme=theme, title="Therapy of Enlightenment") as app:
    gr.Markdown("## 🌟 Therapy of Enlightenment")
    gr.Markdown("Select your current emotional state to receive personalized spiritual content.")

    emotion = gr.Radio(choices=["Calm", "Sad"], label="How do you feel now?")
    verse = gr.Textbox(label="📖 Quranic Verse")
    hadith = gr.Textbox(label="📜 Hadith")
    dua = gr.Textbox(label="🙏 Suggested Supplication (Dua)")
    audio = gr.Audio(label="🎧 Listen to the Dua")

    btn = gr.Button("Get Spiritual Content")

    def full_process(e):
        v, h, d = get_content(e)
        audio_file = text_to_speech(d)
        return v, h, d, audio_file

    btn.click(fn=full_process, inputs=emotion, outputs=[verse, hadith, dua, audio])

app.launch()