multimodalart HF Staff commited on
Commit
f3731c8
·
verified ·
1 Parent(s): d42e408

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +18 -1
app.py CHANGED
@@ -27,7 +27,24 @@ model = IntegralForConditionalGeneration.from_pretrained(
27
  processor = IntegralProcessor.from_pretrained(MODEL_ID)
28
 
29
 
30
- @spaces.GPU(duration=180)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  def generate(
32
  prompt: str,
33
  seed: int = 42,
 
27
  processor = IntegralProcessor.from_pretrained(MODEL_ID)
28
 
29
 
30
+ def _estimate_gpu_duration(*args, **kwargs):
31
+ """Reserve ZeroGPU time from the inputs: measured 4.9s at 50 steps/512x512
32
+ and 31.5s at 100 steps/1024x1024, so ~2s fixed + 0.075s per step per 512^2
33
+ of pixels, with 40% margin and a floor for cold-worker weight streaming."""
34
+ def pick(index, name, fallback):
35
+ value = args[index] if len(args) > index else kwargs.get(name, fallback)
36
+ try:
37
+ return int(value)
38
+ except (TypeError, ValueError):
39
+ return fallback
40
+ steps = min(100, max(2, pick(3, "steps", DEFAULT_STEPS)))
41
+ height = min(1024, max(256, pick(6, "height", DEFAULT_SIZE)))
42
+ width = min(1024, max(256, pick(7, "width", DEFAULT_SIZE)))
43
+ scale = (height * width) / (DEFAULT_SIZE * DEFAULT_SIZE)
44
+ return min(60, max(25, int(1.4 * (2.0 + 0.075 * steps * scale)) + 5))
45
+
46
+
47
+ @spaces.GPU(duration=_estimate_gpu_duration)
48
  def generate(
49
  prompt: str,
50
  seed: int = 42,