tensorflow / hub

A library for transfer learning by reusing parts of TensorFlow models.
https://tensorflow.org/hub
Apache License 2.0
3.49k stars 1.67k forks source link

Bug: Intermittent CORS issues on qna model fetch #913

Open lnsy-dev opened 6 months ago

lnsy-dev commented 6 months ago

What happened?

When looking at the demo:

https://storage.googleapis.com/tfjs-models/demos/mobilebert-qna/index.html

I get the below error intermittently.

This error is replicated when I implement the demo code found here also: https://github.com/tensorflow/tfjs-models/tree/master/qna

This error might be related to https://discuss.tensorflow.org/t/tensorflow-model-cors-issues/18503

Relevant code

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- Load TensorFlow.js. This is required to use the qna model. -->
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs"> </script>
<!-- Load the qna model. -->
<script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/qna"> </script>

<!-- Place your code in the script tag below. You can also use an external .js file -->
<script>
  // Notice there is no 'import' statement. 'qna' and 'tf' is
  // available on the index-page because of the script tag above.

  // Load the model.
  qna.load().then(model => {
    // Find the answers
    model.findAnswers(question, passage).then(answers => {
      console.log('Answers: ', answers);
    });
  });
</script>

Relevant log output

Access to fetch at 'https://www.kaggle.com/models/tensorflow/mobilebert/tfJs/mobilebert/1/model.json?tfjs-format=file&tfhub-redirect=true' (redirected from 'https://tfhub.dev/tensorflow/tfjs-model/mobilebert/1/model.json?tfjs-format=file') from origin 'https://storage.googleapis.com' has been blocked by CORS policy: The 'Access-Control-Allow-Origin' header has a value 'https://storage.googleapis.com' that is not equal to the supplied origin. Have the server send the header with a valid value, or, if an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

tensorflow_hub Version

0.13.0.dev (unstable development build)

TensorFlow Version

2.8 (latest stable release)

Other libraries

No response

Python Version

3.x

OS

macOS