Missing CORS header 'Access-Control-Allow-Origin'

Hugging Face Spaces provides an API for access via Curl, Python or JavaScript. The course provides https://github.com/fastai/tinypets to implement a JavaScript example.

If we run the example on https://fastai.github.io/tinypets/1single.html it does not work and gives an error:
Request from another origin blocked: Same-origin policy prevents reading the remote resource at https://jph00-pets.hf.space/api/predict/ (reason: missing CORS header ‘Access-Control-Allow-Origin’). Status code: 410.

Apparently Gradio and Hugging have made modifications and it only works on the new models, so I’ve fixed it in the following way: I cloned the official repository to a repository of my own and modified the code to point to my own space instead of the fastai example space and apply the new API, so it looks like this:

Sorry if my English is not very good

2 Likes

This is a big help, thanks for posting!