Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,22 +1,26 @@
|
|
1 |
import gradio as gr
|
2 |
-
# from textblob import TextBlob
|
3 |
import requests
|
4 |
|
5 |
-
def get_list_quran_chapters(
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
# Create the Gradio interface
|
12 |
demo = gr.Interface(
|
13 |
-
fn
|
14 |
-
inputs=gr.Button(
|
15 |
outputs=gr.JSON(),
|
16 |
-
title="List of
|
17 |
-
description="
|
18 |
)
|
19 |
|
20 |
-
# Launch the interface
|
21 |
if __name__ == "__main__":
|
22 |
-
demo.launch(
|
|
|
1 |
import gradio as gr
|
|
|
2 |
import requests
|
3 |
|
4 |
+
def get_list_quran_chapters() -> dict:
|
5 |
+
"""
|
6 |
+
Fetches the list of Quran chapters from the API.
|
7 |
+
"""
|
8 |
+
try:
|
9 |
+
list_of_chapters = requests.get("https://quranapi.pages.dev/api/surah.json")
|
10 |
+
list_of_chapters.raise_for_status() # Raise an exception for HTTP errors
|
11 |
+
return list_of_chapters.json()
|
12 |
+
except requests.exceptions.RequestException as e:
|
13 |
+
return {"error": f"Could not retrieve chapters: {e}"}
|
14 |
|
15 |
# Create the Gradio interface
|
16 |
demo = gr.Interface(
|
17 |
+
fn=get_list_quran_chapters,
|
18 |
+
inputs=gr.Button("Get Chapters"), # Use a button to trigger the API call
|
19 |
outputs=gr.JSON(),
|
20 |
+
title="List of Chapters from Quran",
|
21 |
+
description="Click the button to get a list of all chapters from the Quran."
|
22 |
)
|
23 |
|
24 |
+
# Launch the interface
|
25 |
if __name__ == "__main__":
|
26 |
+
demo.launch()
|