VISHAL18for4 commited on
Commit
419ffb3
Β·
verified Β·
1 Parent(s): 8d16d20

Update public/index.html

Browse files
Files changed (1) hide show
  1. public/index.html +65 -2
public/index.html CHANGED
@@ -37,8 +37,71 @@
37
  </footer>
38
  </div>
39
 
40
- <!-- MediaPipe Tasks Vision – using correct CDN -->
41
- <script src="https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@0.10.8/wasm/vision_bundle.js" crossorigin="anonymous">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  </script>
43
 
44
  <!-- Our application script -->
 
37
  </footer>
38
  </div>
39
 
40
+ <!-- MediaPipe Tasks Vision – using multiple CDN sources -->
41
+ <script>
42
+ // This script tries multiple CDN sources until one works
43
+ (function loadMediaPipe() {
44
+ const cdnUrls = [
45
+ 'https://cdnjs.cloudflare.com/ajax/libs/mediapipe/0.10.8/vision_bundle.js',
46
+ 'https://unpkg.com/@mediapipe/tasks-vision@0.10.8/wasm/vision_bundle.js',
47
+ 'https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@0.10.8/wasm/vision_bundle.js'
48
+ ];
49
+
50
+ let index = 0;
51
+
52
+ function tryLoad() {
53
+ if (index >= cdnUrls.length) {
54
+ // All CDNs failed – show error and try loading from local
55
+ console.error('All MediaPipe CDNs failed');
56
+ document.getElementById('status').textContent = '⚠️ CDN failed. Trying local...';
57
+ // Try loading from the Space itself (if you host the file)
58
+ const localScript = document.createElement('script');
59
+ localScript.src = '/vision_bundle.js';
60
+ localScript.onerror = () => {
61
+ document.getElementById('status').textContent = '❌ CDN load failed. Please refresh.';
62
+ };
63
+ localScript.onload = () => {
64
+ document.getElementById('status').textContent = 'βœ… Local MediaPipe loaded';
65
+ };
66
+ document.head.appendChild(localScript);
67
+ return;
68
+ }
69
+
70
+ const url = cdnUrls[index];
71
+ console.log(`Loading MediaPipe from: ${url}`);
72
+
73
+ const script = document.createElement('script');
74
+ script.src = url;
75
+ script.crossOrigin = 'anonymous';
76
+ script.onload = () => {
77
+ // Check if FilesetResolver is defined after a short delay
78
+ setTimeout(() => {
79
+ if (typeof FilesetResolver !== 'undefined') {
80
+ console.log('βœ… MediaPipe loaded successfully from:', url);
81
+ document.getElementById('status').textContent = 'βœ… MediaPipe ready';
82
+ } else {
83
+ console.warn('Script loaded but FilesetResolver not defined, trying next...');
84
+ index++;
85
+ tryLoad();
86
+ }
87
+ }, 1000);
88
+ };
89
+ script.onerror = () => {
90
+ console.warn('Failed to load from:', url);
91
+ index++;
92
+ tryLoad();
93
+ };
94
+ document.head.appendChild(script);
95
+ }
96
+
97
+ // Check if already loaded
98
+ if (typeof FilesetResolver !== 'undefined') {
99
+ console.log('βœ… MediaPipe already loaded');
100
+ return;
101
+ }
102
+
103
+ tryLoad();
104
+ })();
105
  </script>
106
 
107
  <!-- Our application script -->