AlQuranChapters / app.py
captain-awesome's picture
Update app.py
a04c0e2 verified
raw
history blame contribute delete
859 Bytes
import gradio as gr
import requests
def get_list_quran_chapters() -> dict:
"""
Fetches the list of Quran chapters from the API.
"""
try:
list_of_chapters = requests.get("https://quranapi.pages.dev/api/surah.json")
list_of_chapters.raise_for_status() # Raise an exception for HTTP errors
return list_of_chapters.json()
except requests.exceptions.RequestException as e:
return {"error": f"Could not retrieve chapters: {e}"}
# Create the Gradio interface
demo = gr.Interface(
fn=get_list_quran_chapters,
inputs=None, # No user input; trigger only on button click
outputs=gr.JSON(),
title="List of Chapters from Quran",
description="Click the button below to retrieve the list of all Quran chapters."
)
# Launch the interface
if __name__ == "__main__":
demo.launch(mcp_server=True)