Spaces:
Paused
Paused
Fix issues with a tool
Browse files
app.py
CHANGED
|
@@ -9,20 +9,21 @@ from Gradio_UI import GradioUI
|
|
| 9 |
|
| 10 |
@tool
|
| 11 |
def get_quran_ayah(surah_number: int, ayah_number: int) -> str:
|
| 12 |
-
"""Fetches a specific ayah
|
| 13 |
Args:
|
| 14 |
-
surah_number
|
| 15 |
-
ayah_number
|
| 16 |
"""
|
| 17 |
url = f"https://api.alquran.cloud/v1/ayah/{surah_number}:{ayah_number}/editions/quran-simple,en.asad"
|
| 18 |
|
| 19 |
try:
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
|
|
|
| 26 |
return f"Error fetching ayah {surah_number}:{ayah_number}: {e}"
|
| 27 |
|
| 28 |
@tool
|
|
|
|
| 9 |
|
| 10 |
@tool
|
| 11 |
def get_quran_ayah(surah_number: int, ayah_number: int) -> str:
|
| 12 |
+
"""Fetches a specific ayah from the Quran API for the specified surah and ayah numbers.
|
| 13 |
Args:
|
| 14 |
+
surah_number: The surah number.
|
| 15 |
+
ayah_number: The ayah number.
|
| 16 |
"""
|
| 17 |
url = f"https://api.alquran.cloud/v1/ayah/{surah_number}:{ayah_number}/editions/quran-simple,en.asad"
|
| 18 |
|
| 19 |
try:
|
| 20 |
+
response = requests.get(url)
|
| 21 |
+
response.raise_for_status() # Raises an HTTPError for bad responses
|
| 22 |
+
data = response.json()
|
| 23 |
+
arabic_text = data["data"][0]["text"]
|
| 24 |
+
english_text = data["data"][1]["text"]
|
| 25 |
+
return f"The text for ayah {surah_number}:{ayah_number} is:\nArabic: {arabic_text}\nEnglish: {english_text}"
|
| 26 |
+
except requests.RequestException as e:
|
| 27 |
return f"Error fetching ayah {surah_number}:{ayah_number}: {e}"
|
| 28 |
|
| 29 |
@tool
|