4

I have created a Space on Hugging Face that runs my custom machine-learning model using Gradio. It works perfectly in the web interface, but now I want to convert this Space into an API endpoint that I can call from my application.

Could someone guide me through the process of converting my Hugging Face Space to an API endpoint? Specifically, I am looking for:

Steps to set up an Inference Endpoint from my existing Space. How to handle authentication and API keys for accessing the endpoint? Any best practices or tips for optimizing the performance of the endpoint.

1 Answer 1

-1

Hugging Face Gradio Spaces has a built-in RESTful API.

On the bottom of your Space, there will be a link "Use via API" which you can click on that will provide instructions to access the space via API.

Alternatively you can access the API via HTTP requests (replacing the content within {{ }} with your actual HF info):

POST: https://{{your-hf-account-name}}-{{your-space-name}}.hf.space/gradio_api/call/predict

header: {Content-Type": "application/json"}

body:

{
  "data": ["{{your-input-prompt}}"]
}

Which will return an event ID

Then plug the event ID into:

GET: https://{{your-hf-account-name}}-{{your-space-name}}.hf.space/gradio_api/call/predict/dbb5d1d58e6b40f09ad07788f89efa6a{{EVENT-ID}}

header: {Content-Type": "application/json"}

Which will return the output.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.