| |
|
| | import gradio as gr |
| | from gtts import gTTS |
| | import os |
| | import random |
| | import time |
| | from datetime import datetime |
| |
|
| | |
| | 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" |
| | ) |
| |
|
| | |
| | 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." |
| | } |
| |
|
| | |
| | def get_content(emotion): |
| | return quran_verses.get(emotion, ""), hadiths.get(emotion, ""), duas.get(emotion, "") |
| |
|
| | |
| | def text_to_speech(text): |
| | tts = gTTS(text=text, lang='ar') |
| | filename = f"audio_{int(time.time())}.mp3" |
| | tts.save(filename) |
| | return filename |
| |
|
| | |
| | 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() |
| |
|