nmago commited on
Commit
400607e
·
verified ·
1 Parent(s): 03c81db

Fix issues with a tool

Browse files
Files changed (1) hide show
  1. app.py +10 -9
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 text and translation from the Quran API.
13
  Args:
14
- surah_number (int): The surah number.
15
- ayah_number (int): 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
- with urllib.request.urlopen(url) as response:
21
- data = json.load(response)
22
- arabic_text = data["data"][0]["text"]
23
- english_text = data["data"][1]["text"]
24
- return f"The text for ayah {surah_number}:{ayah_number} is:\nArabic: {arabic_text}\nEnglish: {english_text}"
25
- except Exception as e:
 
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