Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -459,13 +459,12 @@ def execute_workflow(workflow: dict[str, Any]) -> list[str]:
|
|
| 459 |
import sys
|
| 460 |
global _timing_store, _terminal_html
|
| 461 |
|
| 462 |
-
#
|
| 463 |
class CustomTqdm(tqdm.std.tqdm):
|
| 464 |
def __init__(self, *args, **kwargs):
|
| 465 |
super().__init__(*args, **kwargs)
|
| 466 |
-
# 只要它是 KSampler 的进度条(总步数大于 1),且 T1 还没记录,立刻打点
|
| 467 |
if not "T1" in _timing_store and self.total and self.total > 1:
|
| 468 |
-
_timing_store["T1"] = time.time()
|
| 469 |
_terminal_html = ""
|
| 470 |
_append_log("SYS ", "blue", "🎨 Running KSampler... (Elapsed: 0s)")
|
| 471 |
|
|
@@ -485,16 +484,9 @@ def execute_workflow(workflow: dict[str, Any]) -> list[str]:
|
|
| 485 |
prompt_id = str(uuid.uuid4())
|
| 486 |
save_id = next(k for k, v in workflow.items() if v.get("class_type") == "SaveImage")
|
| 487 |
|
| 488 |
-
# 记录开始
|
| 489 |
-
comfy_start = time.time()
|
| 490 |
executor.execute(workflow, prompt_id, extra_data={}, execute_outputs=[save_id])
|
| 491 |
|
| 492 |
_timing_store["T2"] = time.time()
|
| 493 |
-
_timing_store["comfy_total"] = _timing_store["T2"] - comfy_start
|
| 494 |
-
|
| 495 |
-
# 兜底:如果拦截器没抓到 T1
|
| 496 |
-
if "T1" not in _timing_store:
|
| 497 |
-
_timing_store["T1"] = _timing_store["T2"] - _timing_store["comfy_total"]
|
| 498 |
|
| 499 |
if not executor.success:
|
| 500 |
message = executor.status_messages[-1] if executor.status_messages else "ComfyUI execution failed"
|
|
@@ -629,27 +621,27 @@ def generate_workflow(
|
|
| 629 |
# 执行(阻塞)
|
| 630 |
final_images = execute_workflow(workflow)
|
| 631 |
|
| 632 |
-
#
|
| 633 |
-
_timing_store["T2"] = time.time()
|
| 634 |
-
|
| 635 |
-
# 👇 重点:如果 T1 没有被拦截器抓取,说明拦截失效了
|
| 636 |
-
# 我们用总时间减去真实跑图时间来反推
|
| 637 |
-
|
| 638 |
yield None, _terminal_html, gr.update()
|
| 639 |
|
|
|
|
| 640 |
dl_time = _timing_store.get("download_end", _timing_store["T0"]) - _timing_store["T0"]
|
| 641 |
-
|
| 642 |
-
pure_compute = _timing_store["T2"] - _timing_store["T1"]
|
| 643 |
-
total_time = _timing_store["T2"] - _timing_store["T0"]
|
| 644 |
|
| 645 |
_append_log("DONE", "green", "Generation successful!")
|
| 646 |
_append_log("----", "normal", "----------------------------------------")
|
| 647 |
_append_log("METR", "blue", "📊 [Timing Metrics]")
|
| 648 |
|
| 649 |
_append_log("METR", "normal", f" ⬇️ Resource Download: {dl_time:.2f}s")
|
| 650 |
-
_append_log("METR", "normal", f" 📦 Model Loading & Prep: {load_time:.2f}s")
|
| 651 |
-
_append_log("METR", "normal", f" 🎨 Pure Compute (Sampler & Decode): {pure_compute:.2f}s")
|
| 652 |
_append_log("METR", "normal", f" ⏱️ Total Time (Post-GPU): {total_time:.2f}s")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 653 |
_append_log("----", "normal", "----------------------------------------")
|
| 654 |
|
| 655 |
# 👇 最终出图并恢复按钮
|
|
|
|
| 459 |
import sys
|
| 460 |
global _timing_store, _terminal_html
|
| 461 |
|
| 462 |
+
# 不用劫持了
|
| 463 |
class CustomTqdm(tqdm.std.tqdm):
|
| 464 |
def __init__(self, *args, **kwargs):
|
| 465 |
super().__init__(*args, **kwargs)
|
|
|
|
| 466 |
if not "T1" in _timing_store and self.total and self.total > 1:
|
| 467 |
+
_timing_store["T1"] = time.time() # 如果抓到了最好,抓不到就算了
|
| 468 |
_terminal_html = ""
|
| 469 |
_append_log("SYS ", "blue", "🎨 Running KSampler... (Elapsed: 0s)")
|
| 470 |
|
|
|
|
| 484 |
prompt_id = str(uuid.uuid4())
|
| 485 |
save_id = next(k for k, v in workflow.items() if v.get("class_type") == "SaveImage")
|
| 486 |
|
|
|
|
|
|
|
| 487 |
executor.execute(workflow, prompt_id, extra_data={}, execute_outputs=[save_id])
|
| 488 |
|
| 489 |
_timing_store["T2"] = time.time()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 490 |
|
| 491 |
if not executor.success:
|
| 492 |
message = executor.status_messages[-1] if executor.status_messages else "ComfyUI execution failed"
|
|
|
|
| 621 |
# 执行(阻塞)
|
| 622 |
final_images = execute_workflow(workflow)
|
| 623 |
|
| 624 |
+
# 强制刷新出最后一帧日志
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 625 |
yield None, _terminal_html, gr.update()
|
| 626 |
|
| 627 |
+
# 计算各项耗时
|
| 628 |
dl_time = _timing_store.get("download_end", _timing_store["T0"]) - _timing_store["T0"]
|
| 629 |
+
total_time = _timing_store.get("T2", time.time()) - _timing_store["T0"]
|
|
|
|
|
|
|
| 630 |
|
| 631 |
_append_log("DONE", "green", "Generation successful!")
|
| 632 |
_append_log("----", "normal", "----------------------------------------")
|
| 633 |
_append_log("METR", "blue", "📊 [Timing Metrics]")
|
| 634 |
|
| 635 |
_append_log("METR", "normal", f" ⬇️ Resource Download: {dl_time:.2f}s")
|
|
|
|
|
|
|
| 636 |
_append_log("METR", "normal", f" ⏱️ Total Time (Post-GPU): {total_time:.2f}s")
|
| 637 |
+
|
| 638 |
+
# 如果你能抓到 T1,那就把纯算图加上,抓不到就只显示总时间
|
| 639 |
+
if "T1" in _timing_store and "T2" in _timing_store:
|
| 640 |
+
pure_compute = _timing_store["T2"] - _timing_store["T1"]
|
| 641 |
+
load_time = _timing_store["T1"] - _timing_store.get("load_start", _timing_store["T1"])
|
| 642 |
+
_append_log("METR", "normal", f" 📦 Model Loading & Prep: {load_time:.2f}s")
|
| 643 |
+
_append_log("METR", "normal", f" 🎨 Pure Compute: {pure_compute:.2f}s")
|
| 644 |
+
|
| 645 |
_append_log("----", "normal", "----------------------------------------")
|
| 646 |
|
| 647 |
# 👇 最终出图并恢复按钮
|