Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -242,7 +242,7 @@ def infer_example(input_image, prompt, lora_adapter):
|
|
| 242 |
res, s, status = infer(input_image, prompt, lora_adapter, 0, True, 1.0, 4, "خودکار (پیشفرض)", 1024, 1024)
|
| 243 |
return res, s, status
|
| 244 |
|
| 245 |
-
# --- جاوااسکریپت برای دکمه دانلود
|
| 246 |
js_download_func = """
|
| 247 |
async (image) => {
|
| 248 |
if (!image) {
|
|
@@ -263,69 +263,7 @@ async (image) => {
|
|
| 263 |
}
|
| 264 |
"""
|
| 265 |
|
| 266 |
-
# --- جاوااسکریپت
|
| 267 |
-
js_global_func = """
|
| 268 |
-
function() {
|
| 269 |
-
// 1. اجبار حالت روشن (Light Mode)
|
| 270 |
-
const forceLight = () => {
|
| 271 |
-
const body = document.querySelector('body');
|
| 272 |
-
if (body) {
|
| 273 |
-
body.classList.remove('dark');
|
| 274 |
-
body.style.backgroundColor = '#f5f7fa';
|
| 275 |
-
body.style.color = '#333333';
|
| 276 |
-
}
|
| 277 |
-
document.querySelectorAll('.dark').forEach(el => el.classList.remove('dark'));
|
| 278 |
-
};
|
| 279 |
-
forceLight();
|
| 280 |
-
setInterval(forceLight, 1000);
|
| 281 |
-
|
| 282 |
-
// 2. ناظر خطا برای تغییر پیام GPU Quota
|
| 283 |
-
const observer = new MutationObserver((mutations) => {
|
| 284 |
-
mutations.forEach((mutation) => {
|
| 285 |
-
if (mutation.addedNodes.length) {
|
| 286 |
-
mutation.addedNodes.forEach((node) => {
|
| 287 |
-
// بررسی اگر المان اضافه شده یک Toast خطا باشد
|
| 288 |
-
if (node.nodeType === 1 && (node.classList.contains('toast-body') || node.classList.contains('error'))) {
|
| 289 |
-
const originalText = node.innerText || "";
|
| 290 |
-
|
| 291 |
-
// شناسایی خطای GPU Quota
|
| 292 |
-
if (originalText.includes('exceeded your GPU quota') || originalText.includes('GPU quota')) {
|
| 293 |
-
|
| 294 |
-
// اگر قبلاً تغییر نکرده باشد
|
| 295 |
-
if (!node.dataset.translated) {
|
| 296 |
-
node.innerHTML = `
|
| 297 |
-
<div style="font-family: 'Vazirmatn', sans-serif; direction: rtl; text-align: right; padding: 5px;">
|
| 298 |
-
<div style="display: flex; align-items: center; gap: 10px; margin-bottom: 8px;">
|
| 299 |
-
<span style="font-size: 28px;">✈️</span>
|
| 300 |
-
<h3 style="margin: 0; color: #c0392b; font-size: 16px;">ظرفیت سرور تکمیل شد</h3>
|
| 301 |
-
</div>
|
| 302 |
-
<p style="margin: 0; color: #333; font-size: 13px; line-height: 1.6;">
|
| 303 |
-
متأسفانه سهمیه رایگان پردازش تمام شده است.
|
| 304 |
-
</p>
|
| 305 |
-
<div style="background-color: #e0f2f1; border: 1px solid #80cbc4; border-radius: 8px; padding: 8px; margin-top: 10px;">
|
| 306 |
-
<p style="margin: 0; color: #00695c; font-weight: bold; font-size: 12px;">💡 راه حل سریع:</p>
|
| 307 |
-
<p style="margin: 4px 0 0 0; font-size: 12px; color: #004d40;">
|
| 308 |
-
لطفاً <b>حالت هواپیما (Airplane Mode)</b> گوشی خود را روشن و سپس خاموش کنید و دوباره تلاش کنید.
|
| 309 |
-
</p>
|
| 310 |
-
</div>
|
| 311 |
-
</div>
|
| 312 |
-
`;
|
| 313 |
-
node.dataset.translated = 'true';
|
| 314 |
-
node.style.border = '2px solid #e74c3c';
|
| 315 |
-
node.style.backgroundColor = '#fff';
|
| 316 |
-
}
|
| 317 |
-
}
|
| 318 |
-
}
|
| 319 |
-
});
|
| 320 |
-
}
|
| 321 |
-
});
|
| 322 |
-
});
|
| 323 |
-
|
| 324 |
-
observer.observe(document.body, { childList: true, subtree: true });
|
| 325 |
-
}
|
| 326 |
-
"""
|
| 327 |
-
|
| 328 |
-
# --- تنظیمات HTML/CSS ---
|
| 329 |
html_code = """
|
| 330 |
<style>
|
| 331 |
@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@300;400;500;700&display=swap');
|
|
@@ -429,6 +367,10 @@ textarea:focus, input[type="text"]:focus {
|
|
| 429 |
box-shadow: 0 8px 25px rgba(16, 185, 129, 0.45) !important;
|
| 430 |
}
|
| 431 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 432 |
#download-btn {
|
| 433 |
background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%) !important;
|
| 434 |
box-shadow: 0 4px 15px rgba(59, 130, 246, 0.3) !important;
|
|
@@ -480,7 +422,7 @@ textarea:focus, input[type="text"]:focus {
|
|
| 480 |
footer { display: none !important; }
|
| 481 |
.flagging { display: none !important; }
|
| 482 |
|
| 483 |
-
/* استایل برای Toast های گرادیو
|
| 484 |
.toast-body {
|
| 485 |
direction: rtl !important;
|
| 486 |
text-align: right !important;
|
|
@@ -493,9 +435,67 @@ footer { display: none !important; }
|
|
| 493 |
}
|
| 494 |
}
|
| 495 |
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 496 |
"""
|
| 497 |
|
| 498 |
-
with gr.Blocks(
|
| 499 |
gr.HTML(html_code)
|
| 500 |
|
| 501 |
with gr.Column(elem_id="col-container"):
|
|
|
|
| 242 |
res, s, status = infer(input_image, prompt, lora_adapter, 0, True, 1.0, 4, "خودکار (پیشفرض)", 1024, 1024)
|
| 243 |
return res, s, status
|
| 244 |
|
| 245 |
+
# --- جاوااسکریپت برای دکمه دانلود ---
|
| 246 |
js_download_func = """
|
| 247 |
async (image) => {
|
| 248 |
if (!image) {
|
|
|
|
| 263 |
}
|
| 264 |
"""
|
| 265 |
|
| 266 |
+
# --- تنظیمات HTML/CSS و جاوااسکریپت سراسری (شامل مدیریت خطا) ---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 267 |
html_code = """
|
| 268 |
<style>
|
| 269 |
@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@300;400;500;700&display=swap');
|
|
|
|
| 367 |
box-shadow: 0 8px 25px rgba(16, 185, 129, 0.45) !important;
|
| 368 |
}
|
| 369 |
|
| 370 |
+
.primary-btn:active, button.primary:active {
|
| 371 |
+
transform: translateY(1px);
|
| 372 |
+
}
|
| 373 |
+
|
| 374 |
#download-btn {
|
| 375 |
background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%) !important;
|
| 376 |
box-shadow: 0 4px 15px rgba(59, 130, 246, 0.3) !important;
|
|
|
|
| 422 |
footer { display: none !important; }
|
| 423 |
.flagging { display: none !important; }
|
| 424 |
|
| 425 |
+
/* استایل برای Toast های گرادیو */
|
| 426 |
.toast-body {
|
| 427 |
direction: rtl !important;
|
| 428 |
text-align: right !important;
|
|
|
|
| 435 |
}
|
| 436 |
}
|
| 437 |
</style>
|
| 438 |
+
|
| 439 |
+
<script>
|
| 440 |
+
// 1. اجبار تم روشن
|
| 441 |
+
function forceLightMode() {
|
| 442 |
+
const body = document.querySelector('body');
|
| 443 |
+
if (body) {
|
| 444 |
+
body.classList.remove('dark');
|
| 445 |
+
body.style.backgroundColor = '#f5f7fa';
|
| 446 |
+
body.style.color = '#333333';
|
| 447 |
+
}
|
| 448 |
+
document.querySelectorAll('.dark').forEach(el => {
|
| 449 |
+
el.classList.remove('dark');
|
| 450 |
+
});
|
| 451 |
+
}
|
| 452 |
+
forceLightMode();
|
| 453 |
+
setInterval(forceLightMode, 1000);
|
| 454 |
+
|
| 455 |
+
// 2. شناسایی و تغییر پیام خطای GPU Quota
|
| 456 |
+
const observer = new MutationObserver((mutations) => {
|
| 457 |
+
mutations.forEach((mutation) => {
|
| 458 |
+
if (mutation.addedNodes.length) {
|
| 459 |
+
mutation.addedNodes.forEach((node) => {
|
| 460 |
+
if (node.nodeType === 1 && (node.classList.contains('toast-body') || node.classList.contains('error'))) {
|
| 461 |
+
const originalText = node.innerText || "";
|
| 462 |
+
|
| 463 |
+
// اگر پیام خطا شامل کلمات کلیدی سهمیه GPU بود
|
| 464 |
+
if (originalText.includes('exceeded your GPU quota') || originalText.includes('GPU quota')) {
|
| 465 |
+
if (!node.dataset.translated) {
|
| 466 |
+
node.innerHTML = `
|
| 467 |
+
<div style="font-family: 'Vazirmatn', sans-serif; direction: rtl; text-align: right; padding: 5px;">
|
| 468 |
+
<div style="display: flex; align-items: center; gap: 10px; margin-bottom: 8px;">
|
| 469 |
+
<span style="font-size: 28px;">✈️</span>
|
| 470 |
+
<h3 style="margin: 0; color: #c0392b; font-size: 16px;">ظرفیت سرور تکمیل شد</h3>
|
| 471 |
+
</div>
|
| 472 |
+
<p style="margin: 0; color: #333; font-size: 13px; line-height: 1.6;">
|
| 473 |
+
متأسفانه سهمیه رایگان پردازش تمام شده است.
|
| 474 |
+
</p>
|
| 475 |
+
<div style="background-color: #e0f2f1; border: 1px solid #80cbc4; border-radius: 8px; padding: 8px; margin-top: 10px;">
|
| 476 |
+
<p style="margin: 0; color: #00695c; font-weight: bold; font-size: 12px;">💡 راه حل سریع:</p>
|
| 477 |
+
<p style="margin: 4px 0 0 0; font-size: 12px; color: #004d40;">
|
| 478 |
+
لطفاً <b>حالت هواپیما (Airplane Mode)</b> گوشی خود را روشن و سپس خاموش کنید و دوباره تلاش کنید.
|
| 479 |
+
</p>
|
| 480 |
+
</div>
|
| 481 |
+
</div>
|
| 482 |
+
`;
|
| 483 |
+
node.dataset.translated = 'true';
|
| 484 |
+
node.style.border = '2px solid #e74c3c';
|
| 485 |
+
node.style.backgroundColor = '#fff';
|
| 486 |
+
}
|
| 487 |
+
}
|
| 488 |
+
}
|
| 489 |
+
});
|
| 490 |
+
}
|
| 491 |
+
});
|
| 492 |
+
});
|
| 493 |
+
|
| 494 |
+
observer.observe(document.body, { childList: true, subtree: true });
|
| 495 |
+
</script>
|
| 496 |
"""
|
| 497 |
|
| 498 |
+
with gr.Blocks() as demo:
|
| 499 |
gr.HTML(html_code)
|
| 500 |
|
| 501 |
with gr.Column(elem_id="col-container"):
|