Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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
|
| 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
|
| 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>
|