I’ve created a simple space using gradio at VectorAPI - a Hugging Face Space by summerstay
I want to be able to use this as an API.
Some similar pages have a “view API” link at the bottom of the page.
I don’t know why my page doesn’t have one. What do I need to change?
hello @summerstay
Please update your Gradio to 3.0.13
, the latest version has the API feature re-enabled. The view API link it’s not yet there, but you can still use it.
For the Interface Class the default endpoint will be /api/predict/
here is an example using Javascript.
ps. I’ve also send you a PR suggestion summerstay/vectorAPI · upgrade your gradio for API support
fetch("https://hf.space/embed/summerstay/vectorAPI/api/predict", {
method: "POST",
body: JSON.stringify({ data: [" Hello World"] }),
headers: { "Content-Type": "application/json" },
})
.then(function (response) {
return response.json();
})
.then(function (json_response) {
console.log(json_response);
});
Hi.
Is it possible to have this API when using blocks? I guess not but just want to make sure.
I think this API is quite useful in some use cases.
hi @mikeee , yes in the latest Gradio version the API is enabled for blocks! it’s not well documented yet but here is a functional example gradio/run.py at main · gradio-app/gradio · GitHub
You can have multiple api endpoints, for instance, for each click associated to an processing function you can have an api_name
xray_run.click(
xray_model,
inputs=[disease, xray_scan],
outputs=xray_results,
status_tracker=xray_progress,
api_name="xray_model"
)
or
ct_run.click(
ct_model,
inputs=[disease, ct_scan],
outputs=ct_results,
status_tracker=ct_progress,
api_name="ct_model"
)
then your API ends points will be
localhost:7860/api/xray_model
localhost:7860/api/ct_model
Very cool thanks for the reply. I’ll give blocks a spin.