How can I get the space REST API builded from gradio Block?

when the space was builded from gradio Interface, there is a view api option on the buttom of page, like this space Gradio Predict API Docs.

but when some space builded from gradio Block, there isn’t the view api option.

please help me how to solve this issue.
thanks.

1 Like

hi @zzzzzz not all Gradio apps have the API enabled, so there is not an easy way to use it. You could use the internal queue endpoint, but it’s not straightforward.

Hi @zzzzzz just wanted to add that the “view API” page will show up if you add the api_name parameter when you define the events in your gradio Blocks.

We’re working on making that easier to understand here: Show view api button even if there are no named api routes in the app by freddyaboulton · Pull Request #2250 · gradio-app/gradio · GitHub

wow, nice work :+1: look forword it.

@zzzzzz, as an alternative to the REST API, you can load an app via the load class method on gradio.Blocks and then treat it like a regular python function.

This behaves the same as the REST API but abstracts away the logic of writing the request yourself.

There’s a guide on that here: Using Blocks Like Functions

2 Likes