LeafCat79 commited on
Commit
902a9ad
·
verified ·
1 Parent(s): 8fba8aa

Scale ZeroGPU duration by asset count

Browse files
Files changed (2) hide show
  1. README.md +2 -0
  2. app.py +16 -3
README.md CHANGED
@@ -70,6 +70,8 @@ The deployed Space is fail-closed: if the primary neural model cannot run, gener
70
 
71
  ZeroGPU is free for eligible personal accounts, but it is quota-limited rather than unlimited: free accounts currently receive five minutes of GPU time per day. Queueing or a quota message is therefore possible even though no inference credits or payment are required.
72
 
 
 
73
  The primary pipeline can be configured with:
74
 
75
  ```text
 
70
 
71
  ZeroGPU is free for eligible personal accounts, but it is quota-limited rather than unlimited: free accounts currently receive five minutes of GPU time per day. Queueing or a quota message is therefore possible even though no inference credits or payment are required.
72
 
73
+ Initial generation uses a dynamic ZeroGPU duration estimate based on the number of separate asset roles, while one-role regeneration reserves a smaller fixed window. This changes only scheduler reservation and queue priority; it does not reduce diffusion steps or image quality. The estimator avoids rejecting short jobs merely because an unnecessarily large fixed duration exceeds the visitor's remaining quota.
74
+
75
  The primary pipeline can be configured with:
76
 
77
  ```text
app.py CHANGED
@@ -158,7 +158,7 @@ PRIMARY_TEXT_PIPE = None
158
  PRIMARY_MODEL_ERROR = None
159
 
160
 
161
- def gpu_task(duration: int):
162
  """Use a real ZeroGPU allocation on Hugging Face and remain importable in local tests."""
163
  if hf_spaces is not None:
164
  return hf_spaces.GPU(duration=duration)
@@ -2402,7 +2402,20 @@ def empty_generation_result(message: str, html_code: str = ""):
2402
  )
2403
 
2404
 
2405
- @gpu_task(duration=120)
 
 
 
 
 
 
 
 
 
 
 
 
 
2406
  def generate_images_and_game(
2407
  html_code: str,
2408
  roles: str,
@@ -2475,7 +2488,7 @@ def generate_images_and_game(
2475
  )
2476
 
2477
 
2478
- @gpu_task(duration=90)
2479
  def regenerate_selected_asset(state: dict, selected_role: str, approved_roles: list[str]):
2480
  if not state or not selected_role:
2481
  return (
 
158
  PRIMARY_MODEL_ERROR = None
159
 
160
 
161
+ def gpu_task(duration):
162
  """Use a real ZeroGPU allocation on Hugging Face and remain importable in local tests."""
163
  if hf_spaces is not None:
164
  return hf_spaces.GPU(duration=duration)
 
2402
  )
2403
 
2404
 
2405
+ def estimate_generation_gpu_duration(
2406
+ html_code: str,
2407
+ roles: str,
2408
+ game_type: str,
2409
+ perspective: str,
2410
+ theme: str,
2411
+ ) -> int:
2412
+ """Reserve realistic ZeroGPU time based on the number of independent assets."""
2413
+ del game_type, perspective, theme
2414
+ role_count = max(1, len(resolve_role_lines(html_code or "", roles or "")[0]))
2415
+ return min(120, 30 + role_count * 18)
2416
+
2417
+
2418
+ @gpu_task(duration=estimate_generation_gpu_duration)
2419
  def generate_images_and_game(
2420
  html_code: str,
2421
  roles: str,
 
2488
  )
2489
 
2490
 
2491
+ @gpu_task(duration=45)
2492
  def regenerate_selected_asset(state: dict, selected_role: str, approved_roles: list[str]):
2493
  if not state or not selected_role:
2494
  return (