Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -265,7 +265,7 @@ async (image) => {
|
|
| 265 |
}
|
| 266 |
"""
|
| 267 |
|
| 268 |
-
# --- جاوااسکریپت سراسری (
|
| 269 |
js_global_content = """
|
| 270 |
<script>
|
| 271 |
document.addEventListener('DOMContentLoaded', () => {
|
|
@@ -282,31 +282,45 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
| 282 |
forceLight();
|
| 283 |
setInterval(forceLight, 1000);
|
| 284 |
|
| 285 |
-
// 2. HELPER:
|
| 286 |
-
// This
|
| 287 |
-
|
| 288 |
-
|
|
|
|
| 289 |
const toast = btn.closest('.toast-wrap') || btn.closest('.toast-body') || btn.closest('.error');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 290 |
if (toast) {
|
| 291 |
toast.remove();
|
| 292 |
-
// Just to be safe, hide parent container if empty
|
| 293 |
-
if (toast.parentElement && toast.parentElement.classList.contains('toast-container')) {
|
| 294 |
-
if(toast.parentElement.children.length <= 1) toast.parentElement.style.display = 'none';
|
| 295 |
-
}
|
| 296 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 297 |
};
|
| 298 |
|
| 299 |
// 3. LOGIC: Replace content logic
|
| 300 |
const replaceErrorContent = (node) => {
|
| 301 |
-
// Safety check: if already has our custom
|
| 302 |
if (node.querySelector('.ip-reset-guide-container')) return;
|
| 303 |
|
| 304 |
const text = node.innerText || "";
|
| 305 |
-
// Check
|
| 306 |
-
|
| 307 |
-
if (text.toLowerCase().includes('quota') || text.toLowerCase().includes('exceeded')) {
|
| 308 |
|
| 309 |
-
// Generate the HTML card
|
| 310 |
const prettyHtml = `
|
| 311 |
<div class="ip-reset-guide-container">
|
| 312 |
<div class="guide-header">
|
|
@@ -350,15 +364,11 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
| 350 |
</div>
|
| 351 |
|
| 352 |
<div class="guide-actions">
|
| 353 |
-
<button class="action-button back-button" onclick="window.
|
| 354 |
<svg class="action-button-icon" viewbox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M19 12H5M12 19l-7-7 7-7" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path></svg>
|
| 355 |
<span>بازگشت</span>
|
| 356 |
</button>
|
| 357 |
-
<button class="action-button retry-button" onclick="
|
| 358 |
-
const runBtn = document.getElementById('run-btn');
|
| 359 |
-
if(runBtn) runBtn.click();
|
| 360 |
-
window.removeErrorToast(this);
|
| 361 |
-
">
|
| 362 |
<svg class="action-button-icon" viewbox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M23 4v6h-6M1 20v-6h6" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path><path d="M20.49 9A9 9 0 0 0 5.64 5.64L1 10m22 4l-4.64 4.36A9 9 0 0 1 3.51 15" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path></svg>
|
| 363 |
<span>تلاش مجدد</span>
|
| 364 |
</button>
|
|
@@ -374,30 +384,24 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
| 374 |
node.style.border = 'none';
|
| 375 |
node.style.backgroundColor = 'transparent';
|
| 376 |
node.style.boxShadow = 'none';
|
| 377 |
-
|
| 378 |
-
// If parent wrapper exists, clean it too
|
| 379 |
-
if (node.parentElement && node.parentElement.classList.contains('toast-wrap')) {
|
| 380 |
-
node.parentElement.style.border = 'none';
|
| 381 |
-
node.parentElement.style.boxShadow = 'none';
|
| 382 |
-
node.parentElement.style.background = 'transparent';
|
| 383 |
-
}
|
| 384 |
}
|
| 385 |
};
|
| 386 |
|
| 387 |
-
// 4. SCANNER: Check
|
| 388 |
-
// This is the "Nuclear" option that fixes your issue.
|
| 389 |
-
// It doesn't rely on observers missing events. It checks everything, all the time.
|
| 390 |
setInterval(() => {
|
| 391 |
// Find all potential error containers
|
| 392 |
const potentialErrors = document.querySelectorAll('.toast-body, .error, .toast-wrap');
|
| 393 |
|
| 394 |
potentialErrors.forEach(el => {
|
| 395 |
// Only process if it has text and doesn't have our card yet
|
| 396 |
-
|
| 397 |
-
|
|
|
|
|
|
|
|
|
|
| 398 |
}
|
| 399 |
});
|
| 400 |
-
},
|
| 401 |
});
|
| 402 |
</script>
|
| 403 |
"""
|
|
|
|
| 265 |
}
|
| 266 |
"""
|
| 267 |
|
| 268 |
+
# --- جاوااسکریپت سراسری (استراتژی حذف کامل برای رفع مشکل رفرش) ---
|
| 269 |
js_global_content = """
|
| 270 |
<script>
|
| 271 |
document.addEventListener('DOMContentLoaded', () => {
|
|
|
|
| 282 |
forceLight();
|
| 283 |
setInterval(forceLight, 1000);
|
| 284 |
|
| 285 |
+
// 2. HELPER: Completely destroy the error element
|
| 286 |
+
// This is the key fix. By removing the element, Gradio is forced
|
| 287 |
+
// to render a completely new one next time, which our scanner will catch.
|
| 288 |
+
window.destroyErrorToast = function(btn) {
|
| 289 |
+
// Try to find the container
|
| 290 |
const toast = btn.closest('.toast-wrap') || btn.closest('.toast-body') || btn.closest('.error');
|
| 291 |
+
|
| 292 |
+
// Find the main run button and click it to retry
|
| 293 |
+
const runBtn = document.getElementById('run-btn');
|
| 294 |
+
if(runBtn) runBtn.click();
|
| 295 |
+
|
| 296 |
+
// Remove the error UI immediately
|
| 297 |
if (toast) {
|
| 298 |
toast.remove();
|
|
|
|
|
|
|
|
|
|
|
|
|
| 299 |
}
|
| 300 |
+
|
| 301 |
+
// Aggressive cleanup: remove ANY other error toasts visible
|
| 302 |
+
document.querySelectorAll('.toast-body, .toast-wrap, .error').forEach(el => {
|
| 303 |
+
if(el.innerText.includes("قدم تا ساخت") || el.innerText.includes("quota")) {
|
| 304 |
+
el.remove();
|
| 305 |
+
}
|
| 306 |
+
});
|
| 307 |
+
};
|
| 308 |
+
|
| 309 |
+
// Just remove toast (for Back button)
|
| 310 |
+
window.closeErrorToast = function(btn) {
|
| 311 |
+
const toast = btn.closest('.toast-wrap') || btn.closest('.toast-body') || btn.closest('.error');
|
| 312 |
+
if(toast) toast.remove();
|
| 313 |
};
|
| 314 |
|
| 315 |
// 3. LOGIC: Replace content logic
|
| 316 |
const replaceErrorContent = (node) => {
|
| 317 |
+
// Safety check: if already has our custom container, do nothing
|
| 318 |
if (node.querySelector('.ip-reset-guide-container')) return;
|
| 319 |
|
| 320 |
const text = node.innerText || "";
|
| 321 |
+
// Check triggers
|
| 322 |
+
if (text.toLowerCase().includes('quota') || text.toLowerCase().includes('exceeded') || text.includes('requested vs')) {
|
|
|
|
| 323 |
|
|
|
|
| 324 |
const prettyHtml = `
|
| 325 |
<div class="ip-reset-guide-container">
|
| 326 |
<div class="guide-header">
|
|
|
|
| 364 |
</div>
|
| 365 |
|
| 366 |
<div class="guide-actions">
|
| 367 |
+
<button class="action-button back-button" onclick="window.closeErrorToast(this)">
|
| 368 |
<svg class="action-button-icon" viewbox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M19 12H5M12 19l-7-7 7-7" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path></svg>
|
| 369 |
<span>بازگشت</span>
|
| 370 |
</button>
|
| 371 |
+
<button class="action-button retry-button" onclick="window.destroyErrorToast(this)">
|
|
|
|
|
|
|
|
|
|
|
|
|
| 372 |
<svg class="action-button-icon" viewbox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M23 4v6h-6M1 20v-6h6" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path><path d="M20.49 9A9 9 0 0 0 5.64 5.64L1 10m22 4l-4.64 4.36A9 9 0 0 1 3.51 15" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path></svg>
|
| 373 |
<span>تلاش مجدد</span>
|
| 374 |
</button>
|
|
|
|
| 384 |
node.style.border = 'none';
|
| 385 |
node.style.backgroundColor = 'transparent';
|
| 386 |
node.style.boxShadow = 'none';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 387 |
}
|
| 388 |
};
|
| 389 |
|
| 390 |
+
// 4. AGGRESSIVE SCANNER: Check frequently for errors
|
|
|
|
|
|
|
| 391 |
setInterval(() => {
|
| 392 |
// Find all potential error containers
|
| 393 |
const potentialErrors = document.querySelectorAll('.toast-body, .error, .toast-wrap');
|
| 394 |
|
| 395 |
potentialErrors.forEach(el => {
|
| 396 |
// Only process if it has text and doesn't have our card yet
|
| 397 |
+
// AND specifically checks for quota text
|
| 398 |
+
if (el.innerText && (el.innerText.includes('quota') || el.innerText.includes('exceeded'))) {
|
| 399 |
+
if (!el.querySelector('.ip-reset-guide-container')) {
|
| 400 |
+
replaceErrorContent(el);
|
| 401 |
+
}
|
| 402 |
}
|
| 403 |
});
|
| 404 |
+
}, 150); // Fast check
|
| 405 |
});
|
| 406 |
</script>
|
| 407 |
"""
|