question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CORs headers for model files

See original GitHub issue

Is your feature request related to a problem? Please describe. I’m porting some popular models to work in web browsers (using tfjs/onnx/tflite), and as part of doing this I’d like to host my model somewhere. If the model is small enough, I can just host the model in the Github repo itself, like I’ve done for this version of AnimeGANv2 that runs in the browser:

However, this doesn’t really work if the model is more than a dozen or so megabytes due to the way git/Github is designed. I’ve got a working JS port of OpenAI’s CLIP model that I’d like to share a web demo for, but I need to host the model somewhere. Huggingface seems like a perfect service for this, but I’m running into a problem: Huggingface doesn’t serve model files with the Access-Control-Allow-Origin: * header, and so the files can’t be downloaded from JavaScript that’s running on another website (such as josephrocca.github.io).

So, for example, if you run this on a website other than huggingface.co:

let onnxFile = await fetch("https://huggingface.co/rocca/openai-clip-js/resolve/main/clip-image-vit-32-float32.onnx").then(r => r.blob());

You’ll get an error like this: CORs error

Describe the solution you’d like If the Access-Control-Allow-Origin: * header could be added to the serving code for model files, that would allow Huggingface to be used for hosting web-based models (onnx, tfjs, tflite).

Describe alternatives you’ve considered I could host the model elsewhere, but I like Huggingface and want to host all my models there 😃

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
julien-ccommented, Nov 15, 2021

i think this is a reasonable request! cc @SBrandeis @Pierrci what do you think?

2reactions
josephroccacommented, Nov 17, 2021

Awesome!

Very bare-bones/proof-of-concept demo for OpenAI’s CLIP in the browser, served by HuggingFace🤗:

Thank you @Pierrci, @julien-c, and team 🎉🎉🙏 There are some exciting APIs currently being prototyped by the Chrome team which could bring at lot of maturity to browsers as platforms for deploying ML solutions. HuggingFace is going to be a great resource for the web ML ecosystem as it grows!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cross-Origin Resource Sharing (CORS) - MDN Web Docs
Cross-Origin Resource Sharing (CORS) is an HTTP-header based mechanism that allows a server to indicate any origins (domain, scheme, ...
Read more >
How to Set CORS Headers for Hosting Files - Lumeer
How to Set CORS Headers on Apache. Simply add the following policy to your .htaccess file in the directory from which you host...
Read more >
CORS Tutorial: A Guide to Cross-Origin Resource Sharing
When a server has been configured correctly to allow cross-origin resource sharing, some special headers will be included. Their presence can be ...
Read more >
django-cors-headers - PyPI
django-cors-headers is a Django application for handling the server headers required for Cross-Origin Resource Sharing (CORS).
Read more >
CORS headers for accessing a file on another domain
While browsers can access files on a different domain, it requires special CORS headers to read the frequencies within the audio.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found