Spaces:
Running
Running
adding fake step on start
Browse files- simple_app.py +42 -31
simple_app.py
CHANGED
|
@@ -14,12 +14,12 @@ snapshot_download(
|
|
| 14 |
|
| 15 |
def infer(prompt, progress=gr.Progress(track_tqdm=True)):
|
| 16 |
|
| 17 |
-
# Configuration
|
| 18 |
total_process_steps = 11 # Total INFO messages expected
|
| 19 |
irrelevant_steps = 4 # First 4 INFO messages are ignored
|
| 20 |
-
relevant_steps = total_process_steps - irrelevant_steps # 7 overall
|
| 21 |
|
| 22 |
-
# Create overall
|
| 23 |
overall_bar = tqdm(total=relevant_steps, desc="Overall Process", position=1,
|
| 24 |
ncols=120, dynamic_ncols=False, leave=True)
|
| 25 |
processed_steps = 0
|
|
@@ -29,15 +29,16 @@ def infer(prompt, progress=gr.Progress(track_tqdm=True)):
|
|
| 29 |
video_progress_bar = None
|
| 30 |
|
| 31 |
# Variables for sub-step progress bar (Level 2)
|
| 32 |
-
# We use
|
| 33 |
sub_bar = None
|
| 34 |
sub_ticks = 0
|
| 35 |
sub_tick_total = 500
|
| 36 |
-
|
|
|
|
| 37 |
waiting_for_first_relevant = True
|
| 38 |
|
| 39 |
command = [
|
| 40 |
-
"python", "-u", "-m", "generate", #
|
| 41 |
"--task", "t2v-1.3B",
|
| 42 |
"--size", "832*480",
|
| 43 |
"--ckpt_dir", "./Wan2.1-T2V-1.3B",
|
|
@@ -54,7 +55,7 @@ def infer(prompt, progress=gr.Progress(track_tqdm=True)):
|
|
| 54 |
bufsize=1)
|
| 55 |
|
| 56 |
while True:
|
| 57 |
-
# Poll stdout with a
|
| 58 |
rlist, _, _ = select.select([process.stdout], [], [], 0.04)
|
| 59 |
if rlist:
|
| 60 |
line = process.stdout.readline()
|
|
@@ -64,10 +65,10 @@ def infer(prompt, progress=gr.Progress(track_tqdm=True)):
|
|
| 64 |
if not stripped_line:
|
| 65 |
continue
|
| 66 |
|
| 67 |
-
# Check
|
| 68 |
progress_match = progress_pattern.search(stripped_line)
|
| 69 |
if progress_match:
|
| 70 |
-
#
|
| 71 |
if sub_bar is not None:
|
| 72 |
if sub_ticks < sub_tick_total:
|
| 73 |
sub_bar.update(sub_tick_total - sub_ticks)
|
|
@@ -76,7 +77,7 @@ def infer(prompt, progress=gr.Progress(track_tqdm=True)):
|
|
| 76 |
overall_bar.refresh()
|
| 77 |
sub_bar = None
|
| 78 |
sub_ticks = 0
|
| 79 |
-
|
| 80 |
current = int(progress_match.group(2))
|
| 81 |
total = int(progress_match.group(3))
|
| 82 |
if video_progress_bar is None:
|
|
@@ -84,7 +85,6 @@ def infer(prompt, progress=gr.Progress(track_tqdm=True)):
|
|
| 84 |
ncols=120, dynamic_ncols=True, leave=True)
|
| 85 |
video_progress_bar.update(current - video_progress_bar.n)
|
| 86 |
video_progress_bar.refresh()
|
| 87 |
-
# When video generation completes, update overall bar.
|
| 88 |
if video_progress_bar.n >= video_progress_bar.total:
|
| 89 |
overall_bar.update(1)
|
| 90 |
overall_bar.refresh()
|
|
@@ -96,31 +96,40 @@ def infer(prompt, progress=gr.Progress(track_tqdm=True)):
|
|
| 96 |
if "INFO:" in stripped_line:
|
| 97 |
parts = stripped_line.split("INFO:", 1)
|
| 98 |
msg = parts[1].strip() if len(parts) > 1 else ""
|
| 99 |
-
print(stripped_line)
|
| 100 |
|
| 101 |
-
# For the first 4 INFO messages, we simply increment processed_steps.
|
| 102 |
if processed_steps < irrelevant_steps:
|
| 103 |
processed_steps += 1
|
| 104 |
-
#
|
| 105 |
if waiting_for_first_relevant and sub_bar is None:
|
| 106 |
sub_bar = tqdm(total=sub_tick_total, desc="Waiting for first step...", position=2,
|
| 107 |
ncols=120, dynamic_ncols=False, leave=True)
|
| 108 |
sub_ticks = 0
|
| 109 |
-
# Continue reading logs.
|
| 110 |
continue
|
| 111 |
else:
|
| 112 |
-
#
|
| 113 |
-
waiting_for_first_relevant
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
if
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
sub_bar = tqdm(total=sub_tick_total, desc=msg, position=2,
|
| 125 |
ncols=120, dynamic_ncols=False, leave=True)
|
| 126 |
sub_ticks = 0
|
|
@@ -128,20 +137,22 @@ def infer(prompt, progress=gr.Progress(track_tqdm=True)):
|
|
| 128 |
else:
|
| 129 |
print(stripped_line)
|
| 130 |
else:
|
| 131 |
-
# No new data within
|
| 132 |
-
# If
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
if sub_bar is not None:
|
| 134 |
sub_bar.update(1)
|
| 135 |
sub_ticks += 1
|
| 136 |
sub_bar.refresh()
|
| 137 |
if sub_ticks >= sub_tick_total:
|
| 138 |
-
# 20 seconds have elapsed; finish this sub-step.
|
| 139 |
sub_bar.close()
|
| 140 |
overall_bar.update(1)
|
| 141 |
overall_bar.refresh()
|
| 142 |
sub_bar = None
|
| 143 |
sub_ticks = 0
|
| 144 |
-
|
| 145 |
if process.poll() is not None:
|
| 146 |
break
|
| 147 |
|
|
|
|
| 14 |
|
| 15 |
def infer(prompt, progress=gr.Progress(track_tqdm=True)):
|
| 16 |
|
| 17 |
+
# Configuration:
|
| 18 |
total_process_steps = 11 # Total INFO messages expected
|
| 19 |
irrelevant_steps = 4 # First 4 INFO messages are ignored
|
| 20 |
+
relevant_steps = total_process_steps - irrelevant_steps # 7 overall steps
|
| 21 |
|
| 22 |
+
# Create overall progress bar (Level 1)
|
| 23 |
overall_bar = tqdm(total=relevant_steps, desc="Overall Process", position=1,
|
| 24 |
ncols=120, dynamic_ncols=False, leave=True)
|
| 25 |
processed_steps = 0
|
|
|
|
| 29 |
video_progress_bar = None
|
| 30 |
|
| 31 |
# Variables for sub-step progress bar (Level 2)
|
| 32 |
+
# We use 500 ticks to represent 20 seconds (each tick = 40 ms)
|
| 33 |
sub_bar = None
|
| 34 |
sub_ticks = 0
|
| 35 |
sub_tick_total = 500
|
| 36 |
+
|
| 37 |
+
# Flag to indicate we're still waiting for the first relevant INFO message.
|
| 38 |
waiting_for_first_relevant = True
|
| 39 |
|
| 40 |
command = [
|
| 41 |
+
"python", "-u", "-m", "generate", # -u: unbuffered output
|
| 42 |
"--task", "t2v-1.3B",
|
| 43 |
"--size", "832*480",
|
| 44 |
"--ckpt_dir", "./Wan2.1-T2V-1.3B",
|
|
|
|
| 55 |
bufsize=1)
|
| 56 |
|
| 57 |
while True:
|
| 58 |
+
# Poll stdout with a timeout of 40 ms.
|
| 59 |
rlist, _, _ = select.select([process.stdout], [], [], 0.04)
|
| 60 |
if rlist:
|
| 61 |
line = process.stdout.readline()
|
|
|
|
| 65 |
if not stripped_line:
|
| 66 |
continue
|
| 67 |
|
| 68 |
+
# Check for video generation progress (Level 3).
|
| 69 |
progress_match = progress_pattern.search(stripped_line)
|
| 70 |
if progress_match:
|
| 71 |
+
# If a sub-step bar is active, finish it before entering video phase.
|
| 72 |
if sub_bar is not None:
|
| 73 |
if sub_ticks < sub_tick_total:
|
| 74 |
sub_bar.update(sub_tick_total - sub_ticks)
|
|
|
|
| 77 |
overall_bar.refresh()
|
| 78 |
sub_bar = None
|
| 79 |
sub_ticks = 0
|
| 80 |
+
waiting_for_first_relevant = False
|
| 81 |
current = int(progress_match.group(2))
|
| 82 |
total = int(progress_match.group(3))
|
| 83 |
if video_progress_bar is None:
|
|
|
|
| 85 |
ncols=120, dynamic_ncols=True, leave=True)
|
| 86 |
video_progress_bar.update(current - video_progress_bar.n)
|
| 87 |
video_progress_bar.refresh()
|
|
|
|
| 88 |
if video_progress_bar.n >= video_progress_bar.total:
|
| 89 |
overall_bar.update(1)
|
| 90 |
overall_bar.refresh()
|
|
|
|
| 96 |
if "INFO:" in stripped_line:
|
| 97 |
parts = stripped_line.split("INFO:", 1)
|
| 98 |
msg = parts[1].strip() if len(parts) > 1 else ""
|
| 99 |
+
print(stripped_line) # Log the message
|
| 100 |
|
|
|
|
| 101 |
if processed_steps < irrelevant_steps:
|
| 102 |
processed_steps += 1
|
| 103 |
+
# While waiting for the first relevant INFO, ensure a waiting sub-bar is running.
|
| 104 |
if waiting_for_first_relevant and sub_bar is None:
|
| 105 |
sub_bar = tqdm(total=sub_tick_total, desc="Waiting for first step...", position=2,
|
| 106 |
ncols=120, dynamic_ncols=False, leave=True)
|
| 107 |
sub_ticks = 0
|
|
|
|
| 108 |
continue
|
| 109 |
else:
|
| 110 |
+
# We have reached the first relevant INFO message.
|
| 111 |
+
if waiting_for_first_relevant:
|
| 112 |
+
waiting_for_first_relevant = False
|
| 113 |
+
# Cancel the waiting sub-bar.
|
| 114 |
+
if sub_bar is not None:
|
| 115 |
+
if sub_ticks < sub_tick_total:
|
| 116 |
+
sub_bar.update(sub_tick_total - sub_ticks)
|
| 117 |
+
sub_bar.close()
|
| 118 |
+
overall_bar.update(1)
|
| 119 |
+
overall_bar.refresh()
|
| 120 |
+
sub_bar = None
|
| 121 |
+
sub_ticks = 0
|
| 122 |
+
else:
|
| 123 |
+
# If a sub-bar is active from a previous step, finish it.
|
| 124 |
+
if sub_bar is not None:
|
| 125 |
+
if sub_ticks < sub_tick_total:
|
| 126 |
+
sub_bar.update(sub_tick_total - sub_ticks)
|
| 127 |
+
sub_bar.close()
|
| 128 |
+
overall_bar.update(1)
|
| 129 |
+
overall_bar.refresh()
|
| 130 |
+
sub_bar = None
|
| 131 |
+
sub_ticks = 0
|
| 132 |
+
# Now start a new sub-step bar for the current INFO message.
|
| 133 |
sub_bar = tqdm(total=sub_tick_total, desc=msg, position=2,
|
| 134 |
ncols=120, dynamic_ncols=False, leave=True)
|
| 135 |
sub_ticks = 0
|
|
|
|
| 137 |
else:
|
| 138 |
print(stripped_line)
|
| 139 |
else:
|
| 140 |
+
# No new stdout data within 40 ms.
|
| 141 |
+
# If we're waiting for the first relevant step and no sub-bar exists, create it.
|
| 142 |
+
if waiting_for_first_relevant and sub_bar is None:
|
| 143 |
+
sub_bar = tqdm(total=sub_tick_total, desc="Waiting for first step...", position=2,
|
| 144 |
+
ncols=120, dynamic_ncols=False, leave=True)
|
| 145 |
+
sub_ticks = 0
|
| 146 |
if sub_bar is not None:
|
| 147 |
sub_bar.update(1)
|
| 148 |
sub_ticks += 1
|
| 149 |
sub_bar.refresh()
|
| 150 |
if sub_ticks >= sub_tick_total:
|
|
|
|
| 151 |
sub_bar.close()
|
| 152 |
overall_bar.update(1)
|
| 153 |
overall_bar.refresh()
|
| 154 |
sub_bar = None
|
| 155 |
sub_ticks = 0
|
|
|
|
| 156 |
if process.poll() is not None:
|
| 157 |
break
|
| 158 |
|