Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -665,37 +665,38 @@
|
|
665 |
|
666 |
|
667 |
import gradio as gr
|
668 |
-
import
|
669 |
-
|
670 |
-
|
671 |
-
|
672 |
-
|
673 |
-
|
674 |
-
|
675 |
-
|
676 |
-
|
677 |
-
|
678 |
-
])
|
679 |
-
|
680 |
-
|
681 |
-
|
682 |
-
|
683 |
-
|
684 |
-
|
685 |
-
|
686 |
-
|
687 |
-
|
688 |
-
|
689 |
-
|
690 |
-
|
691 |
-
|
692 |
-
# β
Gradio interface
|
693 |
gr.Interface(
|
694 |
-
fn=
|
695 |
-
inputs=gr.Textbox(label="Enter
|
696 |
-
outputs=
|
697 |
-
|
698 |
-
|
|
|
|
|
|
|
699 |
).launch()
|
700 |
|
701 |
|
|
|
665 |
|
666 |
|
667 |
import gradio as gr
|
668 |
+
import requests
|
669 |
+
|
670 |
+
# β
Fetch Surah data
|
671 |
+
def get_surah(surah_name):
|
672 |
+
try:
|
673 |
+
url = f"https://api.alquran.cloud/v1/surah/{surah_name}/editions/quran-simple,en.asad"
|
674 |
+
response = requests.get(url)
|
675 |
+
response.raise_for_status()
|
676 |
+
data = response.json()
|
677 |
+
|
678 |
+
if 'data' in data and len(data['data']) == 2:
|
679 |
+
arabic = "\n\n".join(
|
680 |
+
[f"{i+1}. {a['text']}" for i, a in enumerate(data['data'][0]['ayahs'])]
|
681 |
+
)
|
682 |
+
translation = "\n\n".join(
|
683 |
+
[f"{i+1}. {t['text']}" for i, t in enumerate(data['data'][1]['ayahs'])]
|
684 |
+
)
|
685 |
+
return arabic, translation
|
686 |
+
return "Surah not found.", "Translation not found."
|
687 |
+
except Exception as e:
|
688 |
+
return f"API Error: {e}", ""
|
689 |
+
|
690 |
+
# β
Gradio UI
|
|
|
|
|
691 |
gr.Interface(
|
692 |
+
fn=get_surah,
|
693 |
+
inputs=gr.Textbox(label="Enter Surah Name (e.g., Al-Fatiha, An-Nas)", placeholder="Al-Fatiha"),
|
694 |
+
outputs=[
|
695 |
+
gr.Textbox(label="π Arabic Text", lines=15),
|
696 |
+
gr.Textbox(label="π English Translation", lines=15)
|
697 |
+
],
|
698 |
+
title="π Surah Viewer",
|
699 |
+
description="View full Surah from Quran with Arabic and English translation (No Audio)"
|
700 |
).launch()
|
701 |
|
702 |
|