Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -235,10 +235,11 @@ def infer(
|
|
| 235 |
return result, seed, get_success_html("تصویر با موفقیت ویرایش شد.")
|
| 236 |
|
| 237 |
except Exception as e:
|
|
|
|
|
|
|
| 238 |
error_str = str(e)
|
| 239 |
if "quota" in error_str.lower() or "exceeded" in error_str.lower():
|
| 240 |
-
|
| 241 |
-
raise gr.Error("You have exceeded your GPU quota")
|
| 242 |
return None, seed, get_error_html(f"خطا در پردازش: {error_str}")
|
| 243 |
|
| 244 |
@spaces.GPU(duration=30)
|
|
@@ -266,8 +267,7 @@ async (image) => {
|
|
| 266 |
}
|
| 267 |
"""
|
| 268 |
|
| 269 |
-
# --- جاوااسکریپت سراسری (
|
| 270 |
-
# در اینجا منطق Regex برنامه قبلی برای محاسبه زمان باقیمانده و نمایش کارت زیبا ادغام شده است
|
| 271 |
js_global_content = """
|
| 272 |
<script>
|
| 273 |
document.addEventListener('DOMContentLoaded', () => {
|
|
@@ -284,32 +284,32 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
| 284 |
forceLight();
|
| 285 |
setInterval(forceLight, 1000);
|
| 286 |
|
| 287 |
-
// 2. GPU Quota Replacer (
|
| 288 |
const observer = new MutationObserver((mutations) => {
|
| 289 |
mutations.forEach((mutation) => {
|
| 290 |
if (mutation.addedNodes.length) {
|
| 291 |
mutation.addedNodes.forEach((node) => {
|
| 292 |
-
//
|
| 293 |
-
if (node.nodeType === 1 && (node.classList.contains('toast-body') || node.classList.contains('error')
|
| 294 |
const originalText = node.innerText;
|
| 295 |
|
| 296 |
-
//
|
| 297 |
const regex = /(\d+)s requested vs. (\d+)s left/;
|
| 298 |
const match = originalText.match(regex);
|
| 299 |
|
| 300 |
-
// اگر خطا مربوط به Quota بود و قبلا ترجمه نشده بود
|
| 301 |
if (match && !node.dataset.translated) {
|
| 302 |
const requested = match[1];
|
| 303 |
const left = match[2];
|
| 304 |
|
| 305 |
-
//
|
| 306 |
const prettyHtml = `
|
| 307 |
-
<div style="display: flex; align-items: center; gap: 15px; font-family: '
|
| 308 |
<div style="font-size: 2.5em; color: #dc3545;">⏳</div>
|
| 309 |
<div>
|
| 310 |
<h4 style="margin: 0; color: #5a6268; font-weight: bold;">ظرفیت سرور تکمیل است!</h4>
|
| 311 |
<p style="margin: 5px 0 0 0; color: #6c757d; font-size: 0.9em;">
|
| 312 |
-
سهمیه رایگان GPU شما برای پردازش یک
|
| 313 |
</p>
|
| 314 |
<div style="background-color: #f8d7da; border: 1px solid #f5c6cb; border-radius: 5px; padding: 5px 8px; margin-top: 10px; font-size: 0.85em;">
|
| 315 |
اعتبار باقیمانده: <b>${left} ثانیه</b>
|
|
@@ -318,16 +318,11 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
| 318 |
</div>
|
| 319 |
`;
|
| 320 |
|
|
|
|
| 321 |
node.innerHTML = prettyHtml;
|
| 322 |
-
node.dataset.translated = 'true';
|
| 323 |
|
| 324 |
-
//
|
| 325 |
-
|
| 326 |
-
if(parent) {
|
| 327 |
-
parent.style.backgroundColor = "white";
|
| 328 |
-
parent.style.border = "1px solid #ddd";
|
| 329 |
-
parent.style.boxShadow = "0 2px 10px rgba(0,0,0,0.1)";
|
| 330 |
-
}
|
| 331 |
}
|
| 332 |
}
|
| 333 |
});
|
|
|
|
| 235 |
return result, seed, get_success_html("تصویر با موفقیت ویرایش شد.")
|
| 236 |
|
| 237 |
except Exception as e:
|
| 238 |
+
# اگر خطا مربوط به Quota باشد، اجازه میدهیم خود سیستم خطا را تولید کند تا JS آن را بگیرد
|
| 239 |
+
# یا اگر Exception معمولی باشد آن را نشان میدهیم
|
| 240 |
error_str = str(e)
|
| 241 |
if "quota" in error_str.lower() or "exceeded" in error_str.lower():
|
| 242 |
+
raise e # اجازه میدهیم خطای اصلی بالا برود تا شامل اعداد زمان باشد
|
|
|
|
| 243 |
return None, seed, get_error_html(f"خطا در پردازش: {error_str}")
|
| 244 |
|
| 245 |
@spaces.GPU(duration=30)
|
|
|
|
| 267 |
}
|
| 268 |
"""
|
| 269 |
|
| 270 |
+
# --- جاوااسکریپت سراسری (تزریق پیام خطای جدید و تم روشن) ---
|
|
|
|
| 271 |
js_global_content = """
|
| 272 |
<script>
|
| 273 |
document.addEventListener('DOMContentLoaded', () => {
|
|
|
|
| 284 |
forceLight();
|
| 285 |
setInterval(forceLight, 1000);
|
| 286 |
|
| 287 |
+
// 2. NEW GPU Quota Replacer (Hourglass Style)
|
| 288 |
const observer = new MutationObserver((mutations) => {
|
| 289 |
mutations.forEach((mutation) => {
|
| 290 |
if (mutation.addedNodes.length) {
|
| 291 |
mutation.addedNodes.forEach((node) => {
|
| 292 |
+
// فقط روی المانهای مربوط به خطای گرادیو کار کن
|
| 293 |
+
if (node.nodeType === 1 && (node.classList.contains('toast-body') || node.classList.contains('error'))) {
|
| 294 |
const originalText = node.innerText;
|
| 295 |
|
| 296 |
+
// Regex برای پیدا کردن اعداد زمان
|
| 297 |
const regex = /(\d+)s requested vs. (\d+)s left/;
|
| 298 |
const match = originalText.match(regex);
|
| 299 |
|
| 300 |
+
// اگر متن خطا مربوط به Quota بود و قبلا ترجمه نشده بود
|
| 301 |
if (match && !node.dataset.translated) {
|
| 302 |
const requested = match[1];
|
| 303 |
const left = match[2];
|
| 304 |
|
| 305 |
+
// **ساخت کارت HTML زیبا**
|
| 306 |
const prettyHtml = `
|
| 307 |
+
<div style="display: flex; align-items: center; gap: 15px; font-family: 'Tahoma', sans-serif; direction: rtl; padding: 10px;">
|
| 308 |
<div style="font-size: 2.5em; color: #dc3545;">⏳</div>
|
| 309 |
<div>
|
| 310 |
<h4 style="margin: 0; color: #5a6268; font-weight: bold;">ظرفیت سرور تکمیل است!</h4>
|
| 311 |
<p style="margin: 5px 0 0 0; color: #6c757d; font-size: 0.9em;">
|
| 312 |
+
سهمیه رایگان GPU شما برای پردازش یک ویدیوی <b>${requested} ثانیهای</b> کافی نیست.
|
| 313 |
</p>
|
| 314 |
<div style="background-color: #f8d7da; border: 1px solid #f5c6cb; border-radius: 5px; padding: 5px 8px; margin-top: 10px; font-size: 0.85em;">
|
| 315 |
اعتبار باقیمانده: <b>${left} ثانیه</b>
|
|
|
|
| 318 |
</div>
|
| 319 |
`;
|
| 320 |
|
| 321 |
+
// جایگزینی محتوای قدیمی با کارت جدید
|
| 322 |
node.innerHTML = prettyHtml;
|
|
|
|
| 323 |
|
| 324 |
+
// جلوگیری از ترجمه مجدد
|
| 325 |
+
node.dataset.translated = 'true';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 326 |
}
|
| 327 |
}
|
| 328 |
});
|