Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
from TTS.api import TTS
|
| 4 |
+
|
| 5 |
+
# 1️⃣ Load Multilingual TTS Model
|
| 6 |
+
# Note: This is an example, you can use other Arabic-capable TTS models from Hugging Face or Coqui.
|
| 7 |
+
tts = TTS(model_name="tts_models/multilingual/multi-dataset/your_tts")
|
| 8 |
+
|
| 9 |
+
# 2️⃣ Function to fetch Ayat + translation
|
| 10 |
+
def get_quran_ayat(surah_num, ayat_num):
|
| 11 |
+
url = f"http://api.alquran.cloud/v1/ayah/{surah_num}:{ayat_num}/editions/quran-simple,en.asad"
|
| 12 |
+
response = requests.get(url)
|
| 13 |
+
if response.status_code == 200:
|
| 14 |
+
data = response.json()['data']
|
| 15 |
+
arabic_text = data[0]['text']
|
| 16 |
+
translation = data[1]['text']
|
| 17 |
+
return arabic_text, translation
|
| 18 |
+
else:
|
| 19 |
+
return "Error fetching Ayat. Please check the Surah/Ayat number.", ""
|
| 20 |
+
|
| 21 |
+
# 3️⃣ Main function for Gradio
|
| 22 |
+
def qari_bot(surah, ayat):
|
| 23 |
+
arabic_text, translation = get_quran_ayat(surah, ayat)
|
| 24 |
+
# Generate TTS audio file
|
| 25 |
+
tts.tts_to_file(
|
| 26 |
+
text=arabic_text,
|
| 27 |
+
speaker_wav=None,
|
| 28 |
+
language="ar",
|
| 29 |
+
file_path="ayat.wav"
|
| 30 |
+
)
|
| 31 |
+
return arabic_text, translation, "ayat.wav"
|
| 32 |
+
|
| 33 |
+
# 4️⃣ Gradio UI
|
| 34 |
+
interface = gr.Interface(
|
| 35 |
+
fn=qari_bot,
|
| 36 |
+
inputs=[
|
| 37 |
+
gr.Number(label="Surah Number", value=1),
|
| 38 |
+
gr.Number(label="Ayat Number", value=1)
|
| 39 |
+
],
|
| 40 |
+
outputs=[
|
| 41 |
+
gr.Textbox(label="📜 Arabic Ayat"),
|
| 42 |
+
gr.Textbox(label="🌐 Translation (English)"),
|
| 43 |
+
gr.Audio(label="🔊 Listen to Ayat")
|
| 44 |
+
],
|
| 45 |
+
title="📖 AI Qari Bot",
|
| 46 |
+
description=(
|
| 47 |
+
"Enter any Surah & Ayat number to hear the Quran Ayat in Arabic "
|
| 48 |
+
"with AI voice and see its translation.\n"
|
| 49 |
+
"Example: Surah 1, Ayat 1 (Al-Fatiha)"
|
| 50 |
+
),
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
# 5️⃣ Run on Spaces
|
| 54 |
+
interface.launch()
|