Spaces:
Sleeping
Sleeping
Implement dynamic GPU duration based on pipeline settings
Browse files- Add get_dynamic_duration() function with benchmark-based calculations
- Standard: 512+anim=12s, 832+anim=24s, 1024=48s (with 20% safety margin)
- Artistic: 640+anim=28s, 832+anim=54s, 1024+anim+upscale=120s (capped)
- Duration adjusts based on pipeline, image size, animation, and upscaling
- All durations capped at 120s (unauthenticated user limit)
- Add critical warning about upscaling impact on large resolutions (832px+)
- Update GPU quota notice with specific guidance
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
app.py
CHANGED
|
@@ -577,7 +577,53 @@ def compile_models_with_aoti():
|
|
| 577 |
return False
|
| 578 |
|
| 579 |
|
| 580 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 581 |
def generate_qr_code_unified(
|
| 582 |
prompt: str,
|
| 583 |
negative_prompt: str = "ugly, tiling, poorly drawn hands, poorly drawn feet, poorly drawn face, out of frame, extra limbs, body out of frame, blurry, bad anatomy, blurred, watermark, grainy, signature, cut off, draft, closed eyes, text, logo",
|
|
@@ -2517,8 +2563,9 @@ if __name__ == "__main__" and not os.environ.get("QR_TESTING_MODE"):
|
|
| 2517 |
**GPU Quota Notice:**
|
| 2518 |
- **Unauthenticated users**: 120 seconds daily quota (~1 generation). Please log in for more usage.
|
| 2519 |
- **Free authenticated users**: 210 seconds daily quota (~3-5 generations depending on settings).
|
| 2520 |
-
- **⚠️ Warning**: Large image sizes (1024px)
|
| 2521 |
-
- **💡
|
|
|
|
| 2522 |
|
| 2523 |
### Tips:
|
| 2524 |
- Use detailed prompts for better results
|
|
|
|
| 577 |
return False
|
| 578 |
|
| 579 |
|
| 580 |
+
def get_dynamic_duration(
|
| 581 |
+
pipeline: str,
|
| 582 |
+
image_size: int,
|
| 583 |
+
enable_animation: bool,
|
| 584 |
+
enable_upscale: bool,
|
| 585 |
+
):
|
| 586 |
+
"""
|
| 587 |
+
Calculate GPU duration based on benchmarks with 20% safety margin.
|
| 588 |
+
Max duration capped at 120s (unauthenticated user limit).
|
| 589 |
+
|
| 590 |
+
Benchmarks (actual measured times):
|
| 591 |
+
Standard: 512+anim=10s, 512-anim=7s, 832+anim=20s, 1024=40s
|
| 592 |
+
Artistic: 640+anim=23s, 832+anim=45s, 832+anim+upscale=57s, 1024+anim+upscale=124s
|
| 593 |
+
"""
|
| 594 |
+
if pipeline == "standard":
|
| 595 |
+
# Standard pipeline benchmarks (with 20% safety margin)
|
| 596 |
+
if image_size <= 512:
|
| 597 |
+
duration = 12 if enable_animation else 9
|
| 598 |
+
elif image_size <= 640:
|
| 599 |
+
duration = 18 if enable_animation else 13
|
| 600 |
+
elif image_size <= 768:
|
| 601 |
+
duration = 21 if enable_animation else 15
|
| 602 |
+
elif image_size <= 832:
|
| 603 |
+
duration = 24 if enable_animation else 17
|
| 604 |
+
else: # 1024
|
| 605 |
+
duration = 48 if enable_animation else 34
|
| 606 |
+
else: # artistic
|
| 607 |
+
# Artistic pipeline benchmarks (with 20% safety margin)
|
| 608 |
+
if image_size <= 512:
|
| 609 |
+
# Extrapolated from 640 benchmark
|
| 610 |
+
duration = 22 if not enable_upscale else 35
|
| 611 |
+
elif image_size <= 640:
|
| 612 |
+
duration = 28 if not enable_upscale else 48
|
| 613 |
+
elif image_size <= 768:
|
| 614 |
+
# Interpolated between 640 and 832
|
| 615 |
+
duration = 40 if not enable_upscale else 58
|
| 616 |
+
elif image_size <= 832:
|
| 617 |
+
duration = 54 if not enable_upscale else 69
|
| 618 |
+
else: # 1024
|
| 619 |
+
# Extrapolated from 832
|
| 620 |
+
duration = 72 if not enable_upscale else 120 # Worst case measured at 124s
|
| 621 |
+
|
| 622 |
+
# Cap at 120 seconds (unauthenticated user limit)
|
| 623 |
+
return min(duration, 120)
|
| 624 |
+
|
| 625 |
+
|
| 626 |
+
@spaces.GPU(duration=get_dynamic_duration) # Dynamic duration based on settings
|
| 627 |
def generate_qr_code_unified(
|
| 628 |
prompt: str,
|
| 629 |
negative_prompt: str = "ugly, tiling, poorly drawn hands, poorly drawn feet, poorly drawn face, out of frame, extra limbs, body out of frame, blurry, bad anatomy, blurred, watermark, grainy, signature, cut off, draft, closed eyes, text, logo",
|
|
|
|
| 2563 |
**GPU Quota Notice:**
|
| 2564 |
- **Unauthenticated users**: 120 seconds daily quota (~1 generation). Please log in for more usage.
|
| 2565 |
- **Free authenticated users**: 210 seconds daily quota (~3-5 generations depending on settings).
|
| 2566 |
+
- **⚠️ Warning**: Large image sizes (1024px) with upscaling can take 120+ seconds! Use smaller sizes (512-768px) for better quota management.
|
| 2567 |
+
- **💡 Critical**: For large resolutions (832px+), **disable upscaling** to avoid exceeding quota. Upscaling has tremendous impact on GPU time.
|
| 2568 |
+
- **💡 Tip**: Disable animation to save additional GPU time and maximize your quota.
|
| 2569 |
|
| 2570 |
### Tips:
|
| 2571 |
- Use detailed prompts for better results
|