Opera8 commited on
Commit
4d3509e
·
verified ·
1 Parent(s): fed0785

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +104 -85
app.py CHANGED
@@ -265,7 +265,7 @@ async (image) => {
265
  }
266
  """
267
 
268
- # --- جاوااسکریپت سراسری ---
269
  js_global_content = """
270
  <script>
271
  document.addEventListener('DOMContentLoaded', () => {
@@ -282,101 +282,120 @@ document.addEventListener('DOMContentLoaded', () => {
282
  forceLight();
283
  setInterval(forceLight, 1000);
284
 
285
- // 2. NEW GPU Quota Replacer (Fixed Buttons)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
286
  const observer = new MutationObserver((mutations) => {
287
  mutations.forEach((mutation) => {
288
  if (mutation.addedNodes.length) {
289
  mutation.addedNodes.forEach((node) => {
290
- // Check for Gradio error toast
291
  if (node.nodeType === 1 && (node.classList.contains('toast-body') || node.classList.contains('error'))) {
292
- const originalText = node.innerText;
293
-
294
- // Check for Quota Exceeded pattern
295
- const regex = /(\d+)s requested vs. (\d+)s left/;
296
- const match = originalText.match(regex);
297
-
298
- if (match && !node.dataset.translated) {
299
-
300
- // HTML Template for the IP Reset Guide
301
- const prettyHtml = `
302
- <div class="ip-reset-guide-container">
303
- <div class="guide-header">
304
- <svg class="guide-header-icon" viewbox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
305
- <defs><lineargradient id="grad1" x1="0%" y1="0%" x2="100%" y2="100%"><stop offset="0%" style="stop-color: #667eea; stop-opacity: 1;"></stop><stop offset="100%" style="stop-color: #764ba2; stop-opacity: 1;"></stop></lineargradient></defs>
306
- <circle cx="50" cy="50" r="45" fill="url(#grad1)" opacity="0.1"></circle>
307
- <circle cx="50" cy="50" r="35" fill="none" stroke="url(#grad1)" stroke-width="2" opacity="0.3"></circle>
308
- <path d="M35 50 L45 60 L65 40" stroke="url(#grad1)" stroke-width="4" fill="none" stroke-linecap="round" stroke-linejoin="round"></path>
309
- <circle cx="65" cy="35" r="8" fill="#fee140"></circle>
310
- <path d="M62 35 L68 35 M65 32 L65 38" stroke="white" stroke-width="2" stroke-linecap="round"></path>
311
- </svg>
312
- <div>
313
- <h2>یک قدم تا ساخت تصاویر جدید</h2>
314
- <p>نیازمند تغییر نقطه دستیابی</p>
315
- </div>
316
- </div>
317
-
318
- <div class="guide-content">
319
- <div class="info-card">
320
- <div class="info-card-header">
321
- <svg class="info-card-icon" viewbox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M13 2L3 14h9l-1 8 10-12h-9l1-8z" fill="#667eea" opacity="0.2"></path><path d="M13 2L3 14h9l-1 8 10-12h-9l1-8z" stroke="#667eea" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path></svg>
322
- <span class="info-card-title">راه حل سریع</span>
323
- </div>
324
- <p>طبق ویدیو آموزشی پایین بین نقطه دستیابی جابجا شوید تلاش مجدد بزنید تا تصاویر مجدداً تولید بشه.</p>
325
- </div>
326
-
327
- <div class="summary-section">
328
- <div class="summary-header">
329
- <svg class="summary-icon" viewbox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><circle cx="12" cy="12" r="10" fill="#56ab2f" opacity="0.2"></circle><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2z" stroke="#56ab2f" stroke-width="2"></path><path d="M9 12l2 2 4-4" stroke="#56ab2f" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path></svg>
330
- <span class="summary-title">خلاصه راهنما</span>
331
- </div>
332
- <div class="summary-text">هربار که این صفحه را مشاهده کردید: از اینترنت سیم‌کارت استفاده کنید، VPN را خاموش کرده و طبق ویدیو آموزشی پایین نقطه دستیابی رو تغییر دهید. «تلاش مجدد» کلیک کنید. با این روش ساده می‌توانید به صورت نامحدود تصویر بسازید! ☘️</div>
333
- </div>
334
-
335
- <div class="video-button-container">
336
- <button onclick="parent.postMessage({ type: 'NAVIGATE_TO_URL', url: '#/nav/online/news/getSingle/1149635/eyJpdiI6IjhHVGhPQWJwb3E0cjRXbnFWTW5BaUE9PSIsInZhbHVlIjoiS1V0dTdvT21wbXAwSXZaK1RCTG1pVXZqdlFJa1hXV1RKa2FLem9zU3pXMjd5MmlVOGc2YWY0NVdNR3h3Smp1aSIsIm1hYyI6IjY1NTA5ZDYzMjAzMTJhMGQyMWQ4NjA4ZDgyNGZjZDVlY2MyNjdiMjA2NWYzOWRjY2M4ZmVjYWRlMWNlMWQ3ODEiLCJ0YWciOiIifQ==/21135210' }, '*')" class="elegant-video-button">
337
- <svg class="elegant-video-button-icon" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 24 24"><path d="M8 5v14l11-7z"></path></svg>
338
- <span>دیدن ویدیو آموزشی استفاده نامحدود</span>
339
- </button>
340
- </div>
341
- </div>
342
-
343
- <div class="guide-actions">
344
- <button class="action-button back-button" onclick="this.closest('.toast-wrap').remove()">
345
- <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>
346
- <span>بازگشت</span>
347
- </button>
348
- <button class="action-button retry-button" onclick="
349
- const runBtn = document.getElementById('run-btn');
350
- if(runBtn) runBtn.click();
351
- this.closest('.toast-wrap').remove();
352
- ">
353
- <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>
354
- <span>تلاش مجدد</span>
355
- </button>
356
- </div>
357
- </div>
358
- `;
359
-
360
- // Set content
361
- node.innerHTML = prettyHtml;
362
- node.dataset.translated = 'true';
363
-
364
- // Style adjustment for the container to fit nicely
365
- node.style.padding = '0';
366
- node.style.backgroundColor = 'transparent';
367
- }
368
  }
369
  });
370
  }
371
  });
372
  });
373
-
374
  observer.observe(document.body, { childList: true, subtree: true });
 
 
 
 
 
 
 
 
 
 
 
375
  });
376
  </script>
377
  """
378
 
379
- # --- CSS Updated for Beautiful Buttons ---
380
  css_code = """
381
  <style>
382
  @import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@300;400;500;700&display=swap');
@@ -460,13 +479,13 @@ css_code = """
460
  .summary-title { font-weight: 600; color: #2f5a33; font-size: 0.95rem; }
461
  .summary-text { color: #2f5a33; font-size: 0.85rem; line-height: 1.6; }
462
 
463
- /* Tutorial Button Styles */
464
  .video-button-container { text-align: center; margin: 25px 0 15px 0; width: 100%; }
465
  .elegant-video-button {
466
  display: inline-flex !important;
467
  align-items: center;
468
  justify-content: center;
469
- padding: 10px 20px !important;
470
  background-color: #fff !important;
471
  color: var(--guide-accent) !important;
472
  border: 1px solid #e2e8f0 !important;
@@ -489,7 +508,7 @@ css_code = """
489
  }
490
  .elegant-video-button-icon { width: 18px; height: 18px; margin-left: 8px; fill: currentColor; }
491
 
492
- /* Action Buttons Styles (Back & Retry) */
493
  .guide-actions {
494
  display: flex !important;
495
  gap: 12px !important;
@@ -679,7 +698,7 @@ textarea:focus, input[type="text"]:focus {
679
  footer { display: none !important; }
680
  .flagging { display: none !important; }
681
 
682
- /* General Toast Override */
683
  .toast-body {
684
  direction: rtl !important;
685
  text-align: right !important;
 
265
  }
266
  """
267
 
268
+ # --- جاوااسکریپت سراسری (بهینه شده برای رفع مشکل عدم نمایش بار دوم) ---
269
  js_global_content = """
270
  <script>
271
  document.addEventListener('DOMContentLoaded', () => {
 
282
  forceLight();
283
  setInterval(forceLight, 1000);
284
 
285
+ // 2. NEW GPU Quota Replacer (ROBUST VERSION)
286
+ // This function handles the replacement logic
287
+ const replaceError = (node) => {
288
+ if (!node || node.dataset.translated) return;
289
+
290
+ const originalText = node.innerText || "";
291
+ // Regex to catch Quota Exceeded error
292
+ const regex = /(\d+)s requested vs. (\d+)s left/;
293
+ const match = originalText.match(regex);
294
+
295
+ // Also check if it's a generic error that might have been caused by quota but lost details
296
+ if (match || originalText.includes("GPU quota") || originalText.includes("exceeded")) {
297
+
298
+ const prettyHtml = `
299
+ <div class="ip-reset-guide-container">
300
+ <div class="guide-header">
301
+ <svg class="guide-header-icon" viewbox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
302
+ <defs><lineargradient id="grad1" x1="0%" y1="0%" x2="100%" y2="100%"><stop offset="0%" style="stop-color: #667eea; stop-opacity: 1;"></stop><stop offset="100%" style="stop-color: #764ba2; stop-opacity: 1;"></stop></lineargradient></defs>
303
+ <circle cx="50" cy="50" r="45" fill="url(#grad1)" opacity="0.1"></circle>
304
+ <circle cx="50" cy="50" r="35" fill="none" stroke="url(#grad1)" stroke-width="2" opacity="0.3"></circle>
305
+ <path d="M35 50 L45 60 L65 40" stroke="url(#grad1)" stroke-width="4" fill="none" stroke-linecap="round" stroke-linejoin="round"></path>
306
+ <circle cx="65" cy="35" r="8" fill="#fee140"></circle>
307
+ <path d="M62 35 L68 35 M65 32 L65 38" stroke="white" stroke-width="2" stroke-linecap="round"></path>
308
+ </svg>
309
+ <div>
310
+ <h2>یک قدم تا ساخت تصاویر جدید</h2>
311
+ <p>نیازمند تغییر نقطه دستیابی</p>
312
+ </div>
313
+ </div>
314
+
315
+ <div class="guide-content">
316
+ <div class="info-card">
317
+ <div class="info-card-header">
318
+ <svg class="info-card-icon" viewbox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M13 2L3 14h9l-1 8 10-12h-9l1-8z" fill="#667eea" opacity="0.2"></path><path d="M13 2L3 14h9l-1 8 10-12h-9l1-8z" stroke="#667eea" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path></svg>
319
+ <span class="info-card-title">راه حل سریع</span>
320
+ </div>
321
+ <p>طبق ویدیو آموزشی پایین بین نقطه دستیابی جابجا شوید تلاش مجدد بزنید تا تصاویر مجدداً تولید بشه.</p>
322
+ </div>
323
+
324
+ <div class="summary-section">
325
+ <div class="summary-header">
326
+ <svg class="summary-icon" viewbox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><circle cx="12" cy="12" r="10" fill="#56ab2f" opacity="0.2"></circle><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2z" stroke="#56ab2f" stroke-width="2"></path><path d="M9 12l2 2 4-4" stroke="#56ab2f" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path></svg>
327
+ <span class="summary-title">خلاصه راهنما</span>
328
+ </div>
329
+ <div class="summary-text">هربار که این صفحه را مشاهده کردید: از اینترنت سیم‌کارت استفاده کنید، VPN را خاموش کرده و طبق ویدیو آموزشی پایین نقطه دستیابی رو تغییر دهید. «تلاش مجدد» کلیک کنید. با این روش ساده می‌توانید به صورت نامحدود تصویر بسازید! ☘️</div>
330
+ </div>
331
+
332
+ <div class="video-button-container">
333
+ <button onclick="parent.postMessage({ type: 'NAVIGATE_TO_URL', url: '#/nav/online/news/getSingle/1149635/eyJpdiI6IjhHVGhPQWJwb3E0cjRXbnFWTW5BaUE9PSIsInZhbHVlIjoiS1V0dTdvT21wbXAwSXZaK1RCTG1pVXZqdlFJa1hXV1RKa2FLem9zU3pXMjd5MmlVOGc2YWY0NVdNR3h3Smp1aSIsIm1hYyI6IjY1NTA5ZDYzMjAzMTJhMGQyMWQ4NjA4ZDgyNGZjZDVlY2MyNjdiMjA2NWYzOWRjY2M4ZmVjYWRlMWNlMWQ3ODEiLCJ0YWciOiIifQ==/21135210' }, '*')" class="elegant-video-button">
334
+ <svg class="elegant-video-button-icon" xmlns="http://www.w3.org/2000/svg" viewbox="0 0 24 24"><path d="M8 5v14l11-7z"></path></svg>
335
+ <span>دیدن ویدیو آموزشی استفاده نامحدود</span>
336
+ </button>
337
+ </div>
338
+ </div>
339
+
340
+ <div class="guide-actions">
341
+ <button class="action-button back-button" onclick="this.closest('.toast-wrap').remove()">
342
+ <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>
343
+ <span>بازگشت</span>
344
+ </button>
345
+ <button class="action-button retry-button" onclick="
346
+ const runBtn = document.getElementById('run-btn');
347
+ if(runBtn) runBtn.click();
348
+ // Optional: Close current toast, though clicking run usually clears it
349
+ try { this.closest('.toast-wrap').remove(); } catch(e){}
350
+ ">
351
+ <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>
352
+ <span>تلاش مجدد</span>
353
+ </button>
354
+ </div>
355
+ </div>
356
+ `;
357
+
358
+ node.innerHTML = prettyHtml;
359
+ node.dataset.translated = 'true';
360
+ node.style.padding = '0';
361
+ node.style.backgroundColor = 'transparent';
362
+ }
363
+ };
364
+
365
+ // Method A: Mutation Observer (Fast reaction)
366
  const observer = new MutationObserver((mutations) => {
367
  mutations.forEach((mutation) => {
368
  if (mutation.addedNodes.length) {
369
  mutation.addedNodes.forEach((node) => {
 
370
  if (node.nodeType === 1 && (node.classList.contains('toast-body') || node.classList.contains('error'))) {
371
+ replaceError(node);
372
+ }
373
+ // Also check children just in case
374
+ if (node.nodeType === 1 && node.querySelector) {
375
+ const childError = node.querySelector('.toast-body, .error');
376
+ if (childError) replaceError(childError);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
377
  }
378
  });
379
  }
380
  });
381
  });
 
382
  observer.observe(document.body, { childList: true, subtree: true });
383
+
384
+ // Method B: Interval Scanner (Backup for missed events/re-renders)
385
+ // This fixes the issue where the second error doesn't show
386
+ setInterval(() => {
387
+ const errorNodes = document.querySelectorAll('.toast-body, .error');
388
+ errorNodes.forEach(node => {
389
+ if (!node.dataset.translated) {
390
+ replaceError(node);
391
+ }
392
+ });
393
+ }, 500);
394
  });
395
  </script>
396
  """
397
 
398
+ # --- CSS Updated ---
399
  css_code = """
400
  <style>
401
  @import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@300;400;500;700&display=swap');
 
479
  .summary-title { font-weight: 600; color: #2f5a33; font-size: 0.95rem; }
480
  .summary-text { color: #2f5a33; font-size: 0.85rem; line-height: 1.6; }
481
 
482
+ /* Tutorial Button Styles - BEAUTIFIED */
483
  .video-button-container { text-align: center; margin: 25px 0 15px 0; width: 100%; }
484
  .elegant-video-button {
485
  display: inline-flex !important;
486
  align-items: center;
487
  justify-content: center;
488
+ padding: 10px 24px !important;
489
  background-color: #fff !important;
490
  color: var(--guide-accent) !important;
491
  border: 1px solid #e2e8f0 !important;
 
508
  }
509
  .elegant-video-button-icon { width: 18px; height: 18px; margin-left: 8px; fill: currentColor; }
510
 
511
+ /* Action Buttons Styles (Back & Retry) - FIXED */
512
  .guide-actions {
513
  display: flex !important;
514
  gap: 12px !important;
 
698
  footer { display: none !important; }
699
  .flagging { display: none !important; }
700
 
701
+ /* General Toast Override - Forces transparency so our card looks good */
702
  .toast-body {
703
  direction: rtl !important;
704
  text-align: right !important;