Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -765,11 +765,81 @@
|
|
| 765 |
# description="Select a Surah to see its Arabic text and English translation."
|
| 766 |
# ).launch()
|
| 767 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 768 |
import gradio as gr
|
| 769 |
import requests
|
| 770 |
|
| 771 |
-
# β
Get
|
| 772 |
-
def
|
| 773 |
try:
|
| 774 |
url = f"https://api.alquran.cloud/v1/surah/{surah_number}/editions/quran-simple,en.asad,ur.jalandhry"
|
| 775 |
response = requests.get(url)
|
|
@@ -777,15 +847,21 @@ def get_surah(surah_number):
|
|
| 777 |
data = response.json()
|
| 778 |
|
| 779 |
if 'data' in data and len(data['data']) == 3:
|
| 780 |
-
|
| 781 |
-
|
| 782 |
-
|
| 783 |
-
|
| 784 |
-
|
| 785 |
-
|
| 786 |
-
|
| 787 |
-
|
| 788 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 789 |
return arabic, english, urdu
|
| 790 |
return "β Surah not found.", "β English not found.", "β Urdu not found."
|
| 791 |
except Exception as e:
|
|
@@ -818,19 +894,23 @@ surah_names = [
|
|
| 818 |
"111 - Al-Masad", "112 - Al-Ikhlas", "113 - Al-Falaq", "114 - An-Nas"
|
| 819 |
]
|
| 820 |
|
| 821 |
-
# β
Extract
|
| 822 |
def extract_number(surah_name):
|
| 823 |
return int(surah_name.split(" - ")[0])
|
| 824 |
|
| 825 |
-
# β
Gradio App (
|
| 826 |
gr.Interface(
|
| 827 |
-
fn=lambda
|
| 828 |
-
inputs=
|
|
|
|
|
|
|
|
|
|
| 829 |
outputs=[
|
| 830 |
-
gr.Textbox(label="π Arabic
|
| 831 |
-
gr.Textbox(label="π English
|
| 832 |
-
gr.Textbox(label="π Urdu
|
| 833 |
],
|
| 834 |
-
title="π Quran Surah Viewer (Arabic + English + Urdu)",
|
| 835 |
-
description="Select a Surah to view
|
| 836 |
).launch()
|
|
|
|
|
|
| 765 |
# description="Select a Surah to see its Arabic text and English translation."
|
| 766 |
# ).launch()
|
| 767 |
|
| 768 |
+
# import gradio as gr
|
| 769 |
+
# import requests
|
| 770 |
+
|
| 771 |
+
# # β
Get Arabic, English, and Urdu text
|
| 772 |
+
# def get_surah(surah_number):
|
| 773 |
+
# try:
|
| 774 |
+
# url = f"https://api.alquran.cloud/v1/surah/{surah_number}/editions/quran-simple,en.asad,ur.jalandhry"
|
| 775 |
+
# response = requests.get(url)
|
| 776 |
+
# response.raise_for_status()
|
| 777 |
+
# data = response.json()
|
| 778 |
+
|
| 779 |
+
# if 'data' in data and len(data['data']) == 3:
|
| 780 |
+
# arabic = "\n\n".join(
|
| 781 |
+
# [f"{i+1}. {a['text']}" for i, a in enumerate(data['data'][0]['ayahs'])]
|
| 782 |
+
# )
|
| 783 |
+
# english = "\n\n".join(
|
| 784 |
+
# [f"{i+1}. {t['text']}" for i, t in enumerate(data['data'][1]['ayahs'])]
|
| 785 |
+
# )
|
| 786 |
+
# urdu = "\n\n".join(
|
| 787 |
+
# [f"{i+1}. {u['text']}" for i, u in enumerate(data['data'][2]['ayahs'])]
|
| 788 |
+
# )
|
| 789 |
+
# return arabic, english, urdu
|
| 790 |
+
# return "β Surah not found.", "β English not found.", "β Urdu not found."
|
| 791 |
+
# except Exception as e:
|
| 792 |
+
# return f"β API Error: {e}", "", ""
|
| 793 |
+
|
| 794 |
+
# # β
Surah List
|
| 795 |
+
# surah_names = [
|
| 796 |
+
# "1 - Al-Fatiha", "2 - Al-Baqarah", "3 - Aal-E-Imran", "4 - An-Nisa", "5 - Al-Ma'idah",
|
| 797 |
+
# "6 - Al-An'am", "7 - Al-A'raf", "8 - Al-Anfal", "9 - At-Tawbah", "10 - Yunus",
|
| 798 |
+
# "11 - Hud", "12 - Yusuf", "13 - Ar-Ra'd", "14 - Ibrahim", "15 - Al-Hijr",
|
| 799 |
+
# "16 - An-Nahl", "17 - Al-Isra", "18 - Al-Kahf", "19 - Maryam", "20 - Ta-Ha",
|
| 800 |
+
# "21 - Al-Anbiya", "22 - Al-Hajj", "23 - Al-Mu'minun", "24 - An-Nur", "25 - Al-Furqan",
|
| 801 |
+
# "26 - Ash-Shu'ara", "27 - An-Naml", "28 - Al-Qasas", "29 - Al-Ankabut", "30 - Ar-Rum",
|
| 802 |
+
# "31 - Luqman", "32 - As-Sajda", "33 - Al-Ahzab", "34 - Saba", "35 - Fatir",
|
| 803 |
+
# "36 - Ya-Sin", "37 - As-Saffat", "38 - Sad", "39 - Az-Zumar", "40 - Ghafir",
|
| 804 |
+
# "41 - Fussilat", "42 - Ash-Shura", "43 - Az-Zukhruf", "44 - Ad-Dukhan", "45 - Al-Jathiya",
|
| 805 |
+
# "46 - Al-Ahqaf", "47 - Muhammad", "48 - Al-Fath", "49 - Al-Hujurat", "50 - Qaf",
|
| 806 |
+
# "51 - Adh-Dhariyat", "52 - At-Tur", "53 - An-Najm", "54 - Al-Qamar", "55 - Ar-Rahman",
|
| 807 |
+
# "56 - Al-Waqi'a", "57 - Al-Hadid", "58 - Al-Mujadila", "59 - Al-Hashr", "60 - Al-Mumtahina",
|
| 808 |
+
# "61 - As-Saff", "62 - Al-Jumua", "63 - Al-Munafiqun", "64 - At-Taghabun", "65 - At-Talaq",
|
| 809 |
+
# "66 - At-Tahrim", "67 - Al-Mulk", "68 - Al-Qalam", "69 - Al-Haqqah", "70 - Al-Ma'arij",
|
| 810 |
+
# "71 - Nuh", "72 - Al-Jinn", "73 - Al-Muzzammil", "74 - Al-Muddaththir", "75 - Al-Qiyama",
|
| 811 |
+
# "76 - Al-Insan", "77 - Al-Mursalat", "78 - An-Naba", "79 - An-Nazi'at", "80 - Abasa",
|
| 812 |
+
# "81 - At-Takwir", "82 - Al-Infitar", "83 - Al-Mutaffifin", "84 - Al-Inshiqaq", "85 - Al-Buruj",
|
| 813 |
+
# "86 - At-Tariq", "87 - Al-Ala", "88 - Al-Ghashiyah", "89 - Al-Fajr", "90 - Al-Balad",
|
| 814 |
+
# "91 - Ash-Shams", "92 - Al-Lail", "93 - Ad-Duhaa", "94 - Ash-Sharh", "95 - At-Tin",
|
| 815 |
+
# "96 - Al-Alaq", "97 - Al-Qadr", "98 - Al-Bayyina", "99 - Az-Zalzala", "100 - Al-Adiyat",
|
| 816 |
+
# "101 - Al-Qari'a", "102 - At-Takathur", "103 - Al-Asr", "104 - Al-Humaza", "105 - Al-Fil",
|
| 817 |
+
# "106 - Quraish", "107 - Al-Ma'un", "108 - Al-Kawthar", "109 - Al-Kafiroon", "110 - An-Nasr",
|
| 818 |
+
# "111 - Al-Masad", "112 - Al-Ikhlas", "113 - Al-Falaq", "114 - An-Nas"
|
| 819 |
+
# ]
|
| 820 |
+
|
| 821 |
+
# # β
Extract number from dropdown
|
| 822 |
+
# def extract_number(surah_name):
|
| 823 |
+
# return int(surah_name.split(" - ")[0])
|
| 824 |
+
|
| 825 |
+
# # β
Gradio App (3 outputs now: Arabic, English, Urdu)
|
| 826 |
+
# gr.Interface(
|
| 827 |
+
# fn=lambda selected: get_surah(extract_number(selected)),
|
| 828 |
+
# inputs=gr.Dropdown(choices=surah_names, label="π Select a Surah"),
|
| 829 |
+
# outputs=[
|
| 830 |
+
# gr.Textbox(label="π Arabic Text", lines=15),
|
| 831 |
+
# gr.Textbox(label="π English Translation", lines=15),
|
| 832 |
+
# gr.Textbox(label="π Urdu Translation", lines=15)
|
| 833 |
+
# ],
|
| 834 |
+
# title="π Quran Surah Viewer (Arabic + English + Urdu)",
|
| 835 |
+
# description="Select a Surah to view Arabic text, English translation, and Urdu translation."
|
| 836 |
+
# ).launch()
|
| 837 |
+
|
| 838 |
import gradio as gr
|
| 839 |
import requests
|
| 840 |
|
| 841 |
+
# β
Get Surah or Ayah Text
|
| 842 |
+
def get_surah_ayah(surah_number, ayah_number):
|
| 843 |
try:
|
| 844 |
url = f"https://api.alquran.cloud/v1/surah/{surah_number}/editions/quran-simple,en.asad,ur.jalandhry"
|
| 845 |
response = requests.get(url)
|
|
|
|
| 847 |
data = response.json()
|
| 848 |
|
| 849 |
if 'data' in data and len(data['data']) == 3:
|
| 850 |
+
if ayah_number:
|
| 851 |
+
ayah_index = int(ayah_number) - 1
|
| 852 |
+
arabic = f"{ayah_number}. {data['data'][0]['ayahs'][ayah_index]['text']}"
|
| 853 |
+
english = f"{ayah_number}. {data['data'][1]['ayahs'][ayah_index]['text']}"
|
| 854 |
+
urdu = f"{ayah_number}. {data['data'][2]['ayahs'][ayah_index]['text']}"
|
| 855 |
+
else:
|
| 856 |
+
arabic = "\n\n".join(
|
| 857 |
+
[f"{i+1}. {a['text']}" for i, a in enumerate(data['data'][0]['ayahs'])]
|
| 858 |
+
)
|
| 859 |
+
english = "\n\n".join(
|
| 860 |
+
[f"{i+1}. {t['text']}" for i, t in enumerate(data['data'][1]['ayahs'])]
|
| 861 |
+
)
|
| 862 |
+
urdu = "\n\n".join(
|
| 863 |
+
[f"{i+1}. {u['text']}" for i, u in enumerate(data['data'][2]['ayahs'])]
|
| 864 |
+
)
|
| 865 |
return arabic, english, urdu
|
| 866 |
return "β Surah not found.", "β English not found.", "β Urdu not found."
|
| 867 |
except Exception as e:
|
|
|
|
| 894 |
"111 - Al-Masad", "112 - Al-Ikhlas", "113 - Al-Falaq", "114 - An-Nas"
|
| 895 |
]
|
| 896 |
|
| 897 |
+
# β
Extract Surah Number
|
| 898 |
def extract_number(surah_name):
|
| 899 |
return int(surah_name.split(" - ")[0])
|
| 900 |
|
| 901 |
+
# β
Gradio App (Surah + Ayah input)
|
| 902 |
gr.Interface(
|
| 903 |
+
fn=lambda surah, ayah: get_surah_ayah(extract_number(surah), ayah),
|
| 904 |
+
inputs=[
|
| 905 |
+
gr.Dropdown(choices=surah_names, label="π Select Surah"),
|
| 906 |
+
gr.Textbox(label="π’ Optional Ayah Number (e.g., 1, 5, 7)")
|
| 907 |
+
],
|
| 908 |
outputs=[
|
| 909 |
+
gr.Textbox(label="π Arabic", lines=10),
|
| 910 |
+
gr.Textbox(label="π English", lines=10),
|
| 911 |
+
gr.Textbox(label="π Urdu", lines=10)
|
| 912 |
],
|
| 913 |
+
title="π Quran Surah & Ayah Viewer (Arabic + English + Urdu)",
|
| 914 |
+
description="Select a Surah, optionally enter an Ayah number to view that verse only. Leave blank for full Surah."
|
| 915 |
).launch()
|
| 916 |
+
|