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>
|