Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -179,8 +179,50 @@ pipe = URSAPipeline.from_pretrained(args.model, **model_args).to(device)
|
|
| 179 |
|
| 180 |
# =========================
|
| 181 |
# ✅ 第 7 步:真正跑推理的函数加 @spaces.GPU
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
# =========================
|
| 183 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
def generate_image(
|
| 185 |
prompt,
|
| 186 |
negative_prompt,
|
|
@@ -197,7 +239,7 @@ def generate_image(
|
|
| 197 |
return [export_to_image(image, quality=95) for image in images] + [seed]
|
| 198 |
|
| 199 |
|
| 200 |
-
@spaces.GPU(duration=
|
| 201 |
def generate_video(
|
| 202 |
prompt,
|
| 203 |
negative_prompt,
|
|
@@ -274,7 +316,9 @@ if __name__ == "__main__":
|
|
| 274 |
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
| 275 |
guidance_scale = gr.Slider(label="Guidance scale", minimum=1, maximum=10.0, step=0.1, value=7.0)
|
| 276 |
with gr.Row():
|
| 277 |
-
|
|
|
|
|
|
|
| 278 |
options.__exit__(), input_col.__exit__()
|
| 279 |
|
| 280 |
# Results
|
|
@@ -316,4 +360,5 @@ if __name__ == "__main__":
|
|
| 316 |
)
|
| 317 |
# 限制并发,避免多个请求抢同一张卡
|
| 318 |
app.__exit__(), app.queue(default_concurrency_limit=1).launch(
|
| 319 |
-
share=False, ssr_mode=False, max_threads=1
|
|
|
|
|
|
| 179 |
|
| 180 |
# =========================
|
| 181 |
# ✅ 第 7 步:真正跑推理的函数加 @spaces.GPU
|
| 182 |
+
# ZeroGPU 对单次 duration 有两道独立检查:
|
| 183 |
+
# 1) 档位上限:超过 → 「illegal duration」(与剩余配额无关,直接拒绝)
|
| 184 |
+
# 2) 配额预扣:声明值 > 访客剩余配额 → 「quota exceeded」
|
| 185 |
+
# 两道都要求声明值越小越好,所以用【动态 duration】按实际步数估算。
|
| 186 |
# =========================
|
| 187 |
+
|
| 188 |
+
# 非 PRO 档位的单次上限。若仍报 illegal duration,逐级下调到 60 / 30 再试。
|
| 189 |
+
MAX_DURATION = 120
|
| 190 |
+
|
| 191 |
+
# 实测基准(half Blackwell, 512x320):T2I 25 步约 4s,其中首步含预热约 1.3s
|
| 192 |
+
IMAGE_OVERHEAD, IMAGE_PER_STEP = 15, 0.5
|
| 193 |
+
VIDEO_OVERHEAD, VIDEO_PER_STEP = 20, 2.0
|
| 194 |
+
|
| 195 |
+
|
| 196 |
+
def _clamped(value):
|
| 197 |
+
return int(max(20, min(value, MAX_DURATION)))
|
| 198 |
+
|
| 199 |
+
|
| 200 |
+
def estimate_image_duration(
|
| 201 |
+
prompt,
|
| 202 |
+
negative_prompt,
|
| 203 |
+
seed,
|
| 204 |
+
randomize_seed,
|
| 205 |
+
guidance_scale,
|
| 206 |
+
num_inference_steps=25,
|
| 207 |
+
):
|
| 208 |
+
return _clamped(IMAGE_OVERHEAD + num_inference_steps * IMAGE_PER_STEP)
|
| 209 |
+
|
| 210 |
+
|
| 211 |
+
def estimate_video_duration(
|
| 212 |
+
prompt,
|
| 213 |
+
negative_prompt,
|
| 214 |
+
image,
|
| 215 |
+
motion_score,
|
| 216 |
+
seed,
|
| 217 |
+
randomize_seed,
|
| 218 |
+
guidance_scale,
|
| 219 |
+
num_inference_steps,
|
| 220 |
+
output_type="np",
|
| 221 |
+
):
|
| 222 |
+
return _clamped(VIDEO_OVERHEAD + num_inference_steps * VIDEO_PER_STEP)
|
| 223 |
+
|
| 224 |
+
|
| 225 |
+
@spaces.GPU(duration=estimate_image_duration)
|
| 226 |
def generate_image(
|
| 227 |
prompt,
|
| 228 |
negative_prompt,
|
|
|
|
| 239 |
return [export_to_image(image, quality=95) for image in images] + [seed]
|
| 240 |
|
| 241 |
|
| 242 |
+
@spaces.GPU(duration=estimate_video_duration)
|
| 243 |
def generate_video(
|
| 244 |
prompt,
|
| 245 |
negative_prompt,
|
|
|
|
| 316 |
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
| 317 |
guidance_scale = gr.Slider(label="Guidance scale", minimum=1, maximum=10.0, step=0.1, value=7.0)
|
| 318 |
with gr.Row():
|
| 319 |
+
# 上限从 100 收到 50:与 estimate_video_duration 的估算保持自洽,
|
| 320 |
+
# 避免访客拉满步数后必然撞上档位上限而被直接拒绝
|
| 321 |
+
num_inference_steps = gr.Slider(label="Inference steps", minimum=1, maximum=50, step=1, value=30)
|
| 322 |
options.__exit__(), input_col.__exit__()
|
| 323 |
|
| 324 |
# Results
|
|
|
|
| 360 |
)
|
| 361 |
# 限制并发,避免多个请求抢同一张卡
|
| 362 |
app.__exit__(), app.queue(default_concurrency_limit=1).launch(
|
| 363 |
+
share=False, ssr_mode=False, max_threads=1
|
| 364 |
+
)
|