import gradio as gr import requests def load_gradio_docs(): """ Get Gradio's full documentation, example demos, and useful context before answering questions or generating code. Should be used for general questions about core concepts and features of Gradio. Returns: str: Gradio's full documentation, example demos, and useful context. """ try: response = requests.get("https://gradio.app/llms.txt") text = response.text return text except Exception as error: print(f"Error fetching document: {error}") return f"Error fetching document: {str(error)}" def search_gradio_docs(query): """ Run embedding search on Gradio's documentation, guides and demos and return the most relevant useful context before answering questions or generating code. This tool should be used when the user's question is specific to a Gradio demo, docs, or guide. The query should be concise and straightforward, ie: 'how to use the image component' or 'audio component demo', and should not include the word 'Gradio'. Args: query (str): The query to search for Returns: str: The search results """ response = requests.post( "https://playground-worker.pages.dev/api/prompt", headers={ "Content-Type": "application/json", "Origin": "https://gradio.app" }, json={ "prompt_to_embed": query, "SYSTEM_PROMPT": "$INSERT_GUIDES_DOCS_DEMOS", "FALLBACK_PROMPT": "No results found" } ) res = response.json() return res["SYS_PROMPT"] css = """ #search_results { background-color: #ffebc3; padding: 10px; border-radius: 5px; } """ with gr.Blocks(css=css) as demo: gr.HTML("