\n\t\tNo API Routes found for\n\t\t\n\t\t\t{root}\n\t\t
\n\t
\n\t\tTo expose an API endpoint of your app in this page, set the \n\t\t\tapi_name\n\t\t
\n\t\tparameter of the event listener.\n\t\t
\n\t\tFor more information, visit the\n\t\t\n\t\t\tAPI Page guide\n\t\t\n\t\t. To hide the API documentation button and this page, set\n\t\tshow_api=False
\n\t\tin the\n\t\tBlocks.launch()
\n\t\tmethod.\n\t
API Recorder
\n\t\t\n\t\t\t{api_count} API endpoint{#if api_count > 1}s{/if}
\n\t\t
\n\t\t\t\t{current_language !== \"bash\" && parameter_name\n\t\t\t\t\t\t? parameter_name\n\t\t\t\t\t\t: \"[\" + i + \"]\"}\n\t\t\t\t{#if current_language === \"python\"}{python_type.type}{#if parameter_has_default && parameter_default === null} |\n\t\t\t\t\t\t\tNone{/if}{:else}{js_returns[i].type || \"any\"}{/if}\n\t\t\t\t{#if !parameter_has_default || current_language == \"bash\"}Required{:else} Default: {represent_value(parameter_default, python_type.type, \"py\")}{/if}\n\t\t\t
\n\t\t\t\n\t\t\t\tThe input value that is provided in the \"{label}\" {component}\n\t\t\t\tcomponent.\n\t\t\t
\n\t\t\n\t\t{#if current_language === \"python\"}\n\t\t\t\n\t\t\t\t \n\t\t\t\n\t\t\t\n\t\t\t\t$ {py_install}
\n\t\t\t\n\t\t{:else if current_language === \"javascript\"}\n\t\t\t\n\t\t\t\t \n\t\t\t\n\t\t\t\n\t\t\t\t$ {js_install}
\n\t\t\t\n\t\t{:else if current_language === \"bash\"}\n\t\t\t\n\t\t\t\t \n\t\t\t\n\t\t\t\n\t\t\t\t$ {bash_install}
\n\t\t\t\n\t\t{/if}\n\t
\n\n\t\t\t\t\n\t\t\t\t\t \n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\tfrom gradio_client import Client{#if has_file_path}, handle_file{/if}\n\nclient = Client(\"{space_id || root}\"{#if username !== null}, auth=(\"{username}\", **password**){/if})\nresult = client.predict({#each endpoint_parameters as { python_type, example_input, parameter_name, parameter_has_default, parameter_default }, i}\n\t\t{parameter_name\n\t\t\t\t\t\t\t\t? parameter_name + \"=\"\n\t\t\t\t\t\t\t\t: \"\"}{represent_value(\n\t\t\t\t\t\t\t\t\tparameter_has_default ? parameter_default : example_input,\n\t\t\t\t\t\t\t\t\tpython_type.type,\n\t\t\t\t\t\t\t\t\t\"py\"\n\t\t\t\t\t\t\t\t)},{/each}\n\t\tapi_name=\"/{dependency.api_name}\"\n)\nprint(result)
\n\t\t\t\t\n\t\t\t
\n\t\t\n\t\t\t\t\n\t\t\t\t\t \n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\timport { Client } from \"@gradio/client\";\n{#each blob_examples as { component, example_input }, i}\nconst response_{i} = await fetch(\"{example_input.url}\");\nconst example{component} = await response_{i}.blob();\n\t\t\t\t\t\t{/each}\nconst client = await Client.connect(\"{space_id || root}\"{#if username !== null}, {auth: [\"{username}\", **password**]}{/if});\nconst result = await client.predict({#if named}\"/{dependency.api_name}\"{:else}{dependency_index}{/if}, { {#each endpoint_parameters as { label, parameter_name, type, python_type, component, example_input, serializer }, i}{#if blob_components.includes(component)}\n\t\t\t\t{parameter_name}: example{component}, {:else}\t\t\n\t\t{parameter_name}: {represent_value(\n\t\t\t\t\t\t\t\t\t\texample_input,\n\t\t\t\t\t\t\t\t\t\tpython_type.type,\n\t\t\t\t\t\t\t\t\t\t\"js\"\n\t\t\t\t\t\t\t\t\t)}, {/if}\n\t\t\t\t\t\t{/each}\n});\n\nconsole.log(result.data);\n
\n\t\t\t\t\n\t\t\t
\n\t\t\n\t\t\t\t\n\t\t\t\t\t \n\t\t\t\t\n\n\t\t\t\t\n\t\t\t\t\tcurl -X POST {root}call/{dependency.api_name} -s -H \"Content-Type: application/json\" -d '{\"{\"}\n \"data\": [{#each endpoint_parameters as { label, parameter_name, type, python_type, component, example_input, serializer }, i}\n\t\t\t\t\t\t\t{represent_value(\n\t\t\t\t\t\t\t\texample_input,\n\t\t\t\t\t\t\t\tpython_type.type,\n\t\t\t\t\t\t\t\t\"bash\"\n\t\t\t\t\t\t\t)}{#if i < endpoint_parameters.length - 1},\n\t\t\t\t\t\t\t{/if}\n\t\t\t\t\t\t{/each}\n]{\"}\"}' \\\n | awk -F'\"' '{\"{\"} print $4{\"}\"}' \\\n | read EVENT_ID; curl -N {root}call/{dependency.api_name}/$EVENT_ID
\n\t\t\t\t\n\t\t\t
\n\t\t\n\t\t\t\t\n\t\t\t\t\t \n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\tfrom gradio_client import Client, file\n\nclient = Client(\"{short_root}\"{#if username !== null}, auth=(\"{username}\", **password**){/if})\n{#each py_zipped as { call, api_name }}\nclient.predict(\n{call} api_name=\"/{api_name}\"\n)\n{/each}
\n\t\t\t\t\n\t\t\t
\n\t\t{:else if current_language === \"javascript\"}\n\t\t\t\n\t\t\t\t\n\t\t\t\t\t \n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\timport { Client } from \"@gradio/client\";\n\nconst app = await Client.connect(\"{short_root}\"{#if username !== null}, {auth: [\"{username}\", **password**]}{/if});\n\t\t\t\t\t{#each js_zipped as { call, api_name }}\nawait client.predict(\n \"/{api_name}\"{#if call},\n\t\t\t\t\t\t\t{/if}{call});\n\t\t\t\t\t\t{/each}
\n\t\t\t\t\n\t\t\t
\n\t\t{:else if current_language === \"bash\"}\n\t\t\t\n\t\t\t\t\n\t\t\t\t\t \n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t{#each bash_zipped as { call, api_name }}\n\t\t\t\t\t\tcurl -X POST {short_root}call/{api_name} -s -H \"Content-Type: application/json\" -d '{\"{\"} \n\t\"data\": [{call}]{\"}\"}' \\\n | awk -F'\"' '{\"{\"} print $4{\"}\"}' \\\n | read EVENT_ID; curl -N {short_root}call/{api_name}/$EVENT_ID
\n\t\t\t\t\t\t
\n\t\t\t\t\t{/each}\n\t\t\t\t\n\t\t\t
\n\t\t{/if}\n\t\n\t\t\t\t{#if endpoint_returns.length > 1}\n\t\t\t\t\t[{i}]\n\t\t\t\t{/if}\n\t\t\t\t{#if current_language === \"python\"}{python_type.type}{:else}{js_returns[\n\t\t\t\t\t\t\ti\n\t\t\t\t\t\t].type}{/if}\n\t\t\t
\n\t\t\t\n\t\t\t\tThe output value that appears in the \"{label}\" {component}\n\t\t\t\tcomponent.\n\t\t\t
\n\t\t\n\t\t\t\t\tChoose a language to see the code snippets for interacting with the\n\t\t\t\t\tAPI.\n\t\t\t\t
\n\t\t\t\n\t\t\t\t\t\t\t🪄 Recorded API Calls [{api_calls.length}]\n\t\t\t\t\t\t
\n\t\t\t\t\t\t\n\t\t\t\t\t\t\tHere is the code snippet to replay the most recently recorded API\n\t\t\t\t\t\t\tcalls using the {current_language}\n\t\t\t\t\t\t\tclient.\n\t\t\t\t\t\t
\n\n\t\t\t\t\t\t\n\t\t\t\t\t\t\tNote: Some API calls only affect the UI, so when using the\n\t\t\t\t\t\t\tclients, the desired result may be achieved with only a subset of\n\t\t\t\t\t\t\tthe recorded calls.\n\t\t\t\t\t\t
\n\t\t\t\t\t\n\t\t\t\t\t\tAPI Documentation\n\t\t\t\t\t
\n\t\t\t\t{:else}\n\t\t\t\t\t\n\t\t\t\t\t\t{#if current_language == \"python\" || current_language == \"javascript\"}\n\t\t\t\t\t\t\t1. Install the\n\t\t\t\t\t\t\t{current_language}\n\t\t\t\t\t\t\tclient (docs) if you don't already have it installed.\n\t\t\t\t\t\t{:else}\n\t\t\t\t\t\t\t1. Confirm that you have cURL installed on your system.\n\t\t\t\t\t\t{/if}\n\t\t\t\t\t
\n\n\t\t\t\t\t\n\t\t\t\t\t\t2. Find the API endpoint below corresponding to your desired\n\t\t\t\t\t\tfunction in the app. Copy the code snippet, replacing the\n\t\t\t\t\t\tplaceholder values with your own input data.\n\t\t\t\t\t\t{#if space_id}If this is a private Space, you may need to pass your\n\t\t\t\t\t\t\tHugging Face token as well (read more).{/if}\n\n\t\t\t\t\t\tOr use the\n\t\t\t\t\t\t\n\t\t\t\t\t\tto automatically generate your API requests.\n\t\t\t\t\t\t{#if current_language == \"bash\"}
Making a\n\t\t\t\t\t\t\tprediction and getting a result requires\n\t\t\t\t\t\t\t2 requests: a\n\t\t\t\t\t\t\tPOST
\n\t\t\t\t\t\t\tand a GET
request. The POST
request\n\t\t\t\t\t\t\treturns an EVENT_ID
, which is used in the second\n\t\t\t\t\t\t\tGET
request to fetch the results. In these snippets,\n\t\t\t\t\t\t\twe've used awk
and read
to parse the\n\t\t\t\t\t\t\tresults, combining these two requests into one command for ease of\n\t\t\t\t\t\t\tuse. {#if username !== null}\n\t\t\t\t\t\t\t\tNote: connecting to an authenticated app requires an additional\n\t\t\t\t\t\t\t\trequest.{/if} See\n\t\t\t\t\t\t\tcurl docs.\n\t\t\t\t\t\t{/if}\n\n\t\t\t\t\t\t\n\t\t\t\t\t