seawolf2357 commited on
Commit
2e2f7a9
ยท
verified ยท
1 Parent(s): e2255ea

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -86
app.py CHANGED
@@ -955,84 +955,6 @@ if __name__ == '__main__':
955
  }
956
  };
957
 
958
- // Random emoji list for 404 errors
959
- const randomEmojis = [
960
- '๐Ÿ™ˆ', '๐Ÿ™‰', '๐Ÿ™Š', '๐Ÿต', '๐Ÿ’', '๐Ÿฆ', '๐Ÿฆง', '๐Ÿถ', '๐Ÿ•', '๐Ÿฆฎ',
961
- '๐Ÿฉ', '๐Ÿบ', '๐ŸฆŠ', '๐Ÿฆ', '๐Ÿฑ', '๐Ÿˆ', '๐Ÿฆ', '๐Ÿฏ', '๐Ÿ…', '๐Ÿ†',
962
- '๐Ÿด', '๐ŸŽ', '๐Ÿฆ„', '๐Ÿฆ“', '๐ŸฆŒ', '๐Ÿฎ', '๐Ÿ‚', '๐Ÿƒ', '๐Ÿ„', '๐Ÿท',
963
- '๐Ÿ–', '๐Ÿ—', '๐Ÿ', '๐Ÿ‘', '๐Ÿ', '๐Ÿช', '๐Ÿซ', '๐Ÿฆ™', '๐Ÿฆ’', '๐Ÿ˜',
964
- '๐Ÿฆ', '๐Ÿฆ›', '๐Ÿญ', '๐Ÿ', '๐Ÿ€', '๐Ÿน', '๐Ÿฐ', '๐Ÿ‡', '๐Ÿฟ๏ธ', '๐Ÿฆ”',
965
- '๐Ÿฆ‡', '๐Ÿป', '๐Ÿจ', '๐Ÿผ', '๐Ÿฆฅ', '๐Ÿฆฆ', '๐Ÿฆจ', '๐Ÿฆ˜', '๐Ÿฆก', '๐Ÿพ',
966
- '๐Ÿฆƒ', '๐Ÿ”', '๐Ÿ“', '๐Ÿฃ', '๐Ÿค', '๐Ÿฅ', '๐Ÿฆ', '๐Ÿง', '๐Ÿ•Š๏ธ', '๐Ÿฆ…',
967
- '๐Ÿฆ†', '๐Ÿฆข', '๐Ÿฆ‰', '๐Ÿฆฉ', '๐Ÿฆš', '๐Ÿฆœ', '๐Ÿธ', '๐ŸŠ', '๐Ÿข', '๐ŸฆŽ',
968
- '๐Ÿ', '๐Ÿฒ', '๐Ÿ‰', '๐Ÿฆ•', '๐Ÿฆ–', '๐Ÿณ', '๐Ÿ‹', '๐Ÿฌ', '๐ŸŸ', '๐Ÿ ',
969
- '๐Ÿก', '๐Ÿฆˆ', '๐Ÿ™', '๐Ÿš', '๐ŸŒ', '๐Ÿฆ‹', '๐Ÿ›', '๐Ÿœ', '๐Ÿ', '๐Ÿž',
970
- '๐Ÿฆ—', '๐Ÿ•ท๏ธ', '๐Ÿ•ธ๏ธ', '๐Ÿฆ‚', '๐ŸฆŸ', '๐Ÿฆ ', '๐Ÿ’', '๐ŸŒธ', '๐Ÿ’ฎ', '๐Ÿต๏ธ',
971
- '๐ŸŒน', '๐Ÿฅ€', '๐ŸŒบ', '๐ŸŒป', '๐ŸŒผ', '๐ŸŒท', '๐ŸŒฑ', '๐ŸŒฒ', '๐ŸŒณ', '๐ŸŒด',
972
- '๐ŸŒต', '๐ŸŒพ', '๐ŸŒฟ', 'โ˜˜๏ธ', '๐Ÿ€', '๐Ÿ', '๐Ÿ‚', '๐Ÿƒ', '๐Ÿ‡', '๐Ÿˆ',
973
- '๐Ÿ‰', '๐ŸŠ', '๐Ÿ‹', '๐ŸŒ', '๐Ÿ', '๐Ÿฅญ', '๐ŸŽ', '๐Ÿ', '๐Ÿ', '๐Ÿ‘',
974
- '๐Ÿ’', '๐Ÿ“', '๐Ÿฅ', '๐Ÿ…', '๐Ÿฅฅ', '๐Ÿฅ‘', '๐Ÿ†', '๐Ÿฅ”', '๐Ÿฅ•', '๐ŸŒฝ',
975
- '๐ŸŒถ๏ธ', '๐Ÿฅ’', '๐Ÿฅฌ', '๐Ÿฅฆ', '๐Ÿง„', '๐Ÿง…', '๐Ÿ„', '๐Ÿฅœ', '๐ŸŒฐ', '๐Ÿž',
976
- '๐Ÿฅ', '๐Ÿฅ–', '๐Ÿฅจ', '๐Ÿฅฏ', '๐Ÿฅž', '๐Ÿง‡', '๐Ÿง€', '๐Ÿ–', '๐Ÿ—', '๐Ÿฅฉ',
977
- '๐Ÿฅ“', '๐Ÿ”', '๐ŸŸ', '๐Ÿ•', '๐ŸŒญ', '๐Ÿฅช', '๐ŸŒฎ', '๐ŸŒฏ', '๐Ÿฅ™', '๐Ÿง†',
978
- '๐Ÿฅš', '๐Ÿณ', '๐Ÿฅ˜', '๐Ÿฒ', '๐Ÿฅฃ', '๐Ÿฅ—', '๐Ÿฟ', '๐Ÿงˆ', '๐Ÿง‚', '๐Ÿฅซ',
979
- '๐Ÿฑ', '๐Ÿ˜', '๐Ÿ™', '๐Ÿš', '๐Ÿ›', '๐Ÿœ', '๐Ÿ', '๐Ÿ ', '๐Ÿข', '๐Ÿฃ',
980
- '๐Ÿค', '๐Ÿฅ', '๐Ÿฅฎ', '๐Ÿก', '๐ŸฅŸ', '๐Ÿฅ ', '๐Ÿฅก', '๐Ÿฆ€', '๐Ÿฆž', '๐Ÿฆ',
981
- '๐Ÿฆ‘', '๐Ÿฆช', '๐Ÿฆ', '๐Ÿง', '๐Ÿจ', '๐Ÿฉ', '๐Ÿช', '๐ŸŽ‚', '๐Ÿฐ', '๐Ÿง',
982
- '๐Ÿฅง', '๐Ÿซ', '๐Ÿฌ', '๐Ÿญ', '๐Ÿฎ', '๐Ÿฏ', '๐Ÿผ', '๐Ÿฅ›', 'โ˜•', '๐Ÿต'
983
- ];
984
-
985
- // Display loading indicator
986
- function setLoading(isLoading) {
987
- state.isLoading = isLoading;
988
- elements.loadingIndicator.style.display = isLoading ? 'flex' : 'none';
989
-
990
- if (isLoading) {
991
- elements.refreshButton.classList.add('refreshing');
992
- // Show error message if loading takes too long
993
- clearTimeout(state.loadingTimeout);
994
- state.loadingTimeout = setTimeout(() => {
995
- elements.loadingError.style.display = 'block';
996
- }, 10000); // Show error message after 10 seconds
997
- } else {
998
- elements.refreshButton.classList.remove('refreshing');
999
- clearTimeout(state.loadingTimeout);
1000
- elements.loadingError.style.display = 'none';
1001
- }
1002
- }
1003
-
1004
- // API error handling
1005
- async function handleApiResponse(response) {
1006
- if (!response.ok) {
1007
- const errorText = await response.text();
1008
- throw new Error(`API Error (${response.status}): ${errorText}`);
1009
- }
1010
- return response.json();
1011
- }
1012
-
1013
- // Create direct URL function with fixes for static sites
1014
- function createDirectUrl(owner, name) {
1015
- try {
1016
- // 1. Replace '.' characters with '-'
1017
- name = name.replace(/\./g, '-');
1018
- // 2. Replace '_' characters with '-'
1019
- name = name.replace(/_/g, '-');
1020
- // 3. Convert everything to lowercase
1021
- owner = owner.toLowerCase();
1022
- name = name.toLowerCase();
1023
-
1024
- return `https://${owner}-${name}.hf.space`;
1025
- } catch (error) {
1026
- console.error('URL creation error:', error);
1027
- return 'https://huggingface.co';
1028
- }
1029
- }
1030
-
1031
- // Get random emoji for 404 errors
1032
- function getRandomEmoji() {
1033
- return randomEmojis[Math.floor(Math.random() * randomEmojis.length)];
1034
- }
1035
-
1036
  // Toggle stats display
1037
  function toggleStats() {
1038
  state.statsVisible = !state.statsVisible;
@@ -1142,7 +1064,7 @@ if __name__ == '__main__':
1142
 
1143
  // Use the first Promise that completes
1144
  const response = await Promise.race([fetchPromise, timeoutPromise]);
1145
- const data = await handleApiResponse(response);
1146
 
1147
  // Update state on successful load
1148
  state.spaces = data.spaces;
@@ -1235,7 +1157,7 @@ if __name__ == '__main__':
1235
  elements.pagination.appendChild(nextButton);
1236
  }
1237
 
1238
- // Handle iframe error and provide static site fallback with random emoji
1239
  function handleIframeError(iframe, owner, name, title) {
1240
  const container = iframe.parentNode;
1241
 
@@ -1243,12 +1165,6 @@ if __name__ == '__main__':
1243
  const errorPlaceholder = document.createElement('div');
1244
  errorPlaceholder.className = 'error-placeholder';
1245
 
1246
- // Random emoji instead of error icon
1247
- const errorEmoji = document.createElement('div');
1248
- errorEmoji.className = 'error-emoji';
1249
- errorEmoji.textContent = getRandomEmoji();
1250
- errorPlaceholder.appendChild(errorEmoji);
1251
-
1252
  // Error message
1253
  const errorMessage = document.createElement('p');
1254
  errorMessage.textContent = `"${title}" space couldn't be loaded`;
@@ -1472,6 +1388,43 @@ if __name__ == '__main__':
1472
 
1473
  // Start loading immediately - dual call with window.load for reliability
1474
  loadSpaces(0);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1475
  </script>
1476
  </body>
1477
  </html>
 
955
  }
956
  };
957
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
958
  // Toggle stats display
959
  function toggleStats() {
960
  state.statsVisible = !state.statsVisible;
 
1064
 
1065
  // Use the first Promise that completes
1066
  const response = await Promise.race([fetchPromise, timeoutPromise]);
1067
+ const data = await response.json();
1068
 
1069
  // Update state on successful load
1070
  state.spaces = data.spaces;
 
1157
  elements.pagination.appendChild(nextButton);
1158
  }
1159
 
1160
+ // Handle iframe error and provide fallback error message
1161
  function handleIframeError(iframe, owner, name, title) {
1162
  const container = iframe.parentNode;
1163
 
 
1165
  const errorPlaceholder = document.createElement('div');
1166
  errorPlaceholder.className = 'error-placeholder';
1167
 
 
 
 
 
 
 
1168
  // Error message
1169
  const errorMessage = document.createElement('p');
1170
  errorMessage.textContent = `"${title}" space couldn't be loaded`;
 
1388
 
1389
  // Start loading immediately - dual call with window.load for reliability
1390
  loadSpaces(0);
1391
+
1392
+ // Display loading indicator control
1393
+ function setLoading(isLoading) {
1394
+ state.isLoading = isLoading;
1395
+ elements.loadingIndicator.style.display = isLoading ? 'flex' : 'none';
1396
+
1397
+ if (isLoading) {
1398
+ elements.refreshButton.classList.add('refreshing');
1399
+ // Show error message if loading takes too long
1400
+ clearTimeout(state.loadingTimeout);
1401
+ state.loadingTimeout = setTimeout(() => {
1402
+ elements.loadingError.style.display = 'block';
1403
+ }, 10000); // Show error message after 10 seconds
1404
+ } else {
1405
+ elements.refreshButton.classList.remove('refreshing');
1406
+ clearTimeout(state.loadingTimeout);
1407
+ elements.loadingError.style.display = 'none';
1408
+ }
1409
+ }
1410
+
1411
+ // Create direct URL function with fixes for static sites
1412
+ function createDirectUrl(owner, name) {
1413
+ try {
1414
+ // 1. Replace '.' characters with '-'
1415
+ name = name.replace(/\./g, '-');
1416
+ // 2. Replace '_' characters with '-'
1417
+ name = name.replace(/_/g, '-');
1418
+ // 3. Convert everything to lowercase
1419
+ owner = owner.toLowerCase();
1420
+ name = name.toLowerCase();
1421
+
1422
+ return `https://${owner}-${name}.hf.space`;
1423
+ } catch (error) {
1424
+ console.error('URL creation error:', error);
1425
+ return 'https://huggingface.co';
1426
+ }
1427
+ }
1428
  </script>
1429
  </body>
1430
  </html>