Spaces:
Running
Running
use ms instead of seconds for fake track
Browse files- simple_app.py +26 -31
simple_app.py
CHANGED
|
@@ -14,7 +14,7 @@ snapshot_download(
|
|
| 14 |
|
| 15 |
def infer(prompt, progress=gr.Progress(track_tqdm=True)):
|
| 16 |
|
| 17 |
-
# Configuration:
|
| 18 |
total_process_steps = 11 # Total steps (including irrelevant ones)
|
| 19 |
irrelevant_steps = 4 # First 4 INFO messages are skipped
|
| 20 |
relevant_steps = total_process_steps - irrelevant_steps # 7 overall steps
|
|
@@ -30,11 +30,12 @@ def infer(prompt, progress=gr.Progress(track_tqdm=True)):
|
|
| 30 |
|
| 31 |
# Variables for sub-step progress bar (level 2)
|
| 32 |
sub_bar = None
|
| 33 |
-
|
| 34 |
-
|
|
|
|
| 35 |
|
| 36 |
command = [
|
| 37 |
-
"python", "-u", "-m", "generate", # -u
|
| 38 |
"--task", "t2v-1.3B",
|
| 39 |
"--size", "832*480",
|
| 40 |
"--ckpt_dir", "./Wan2.1-T2V-1.3B",
|
|
@@ -50,12 +51,10 @@ def infer(prompt, progress=gr.Progress(track_tqdm=True)):
|
|
| 50 |
text=True,
|
| 51 |
bufsize=1)
|
| 52 |
|
| 53 |
-
# Poll the process's stdout in a loop.
|
| 54 |
while True:
|
| 55 |
-
#
|
| 56 |
-
rlist, _, _ = select.select([process.stdout], [], [],
|
| 57 |
if rlist:
|
| 58 |
-
# New line is available.
|
| 59 |
line = process.stdout.readline()
|
| 60 |
if not line:
|
| 61 |
break
|
|
@@ -63,18 +62,18 @@ def infer(prompt, progress=gr.Progress(track_tqdm=True)):
|
|
| 63 |
if not stripped_line:
|
| 64 |
continue
|
| 65 |
|
| 66 |
-
# Check
|
| 67 |
progress_match = progress_pattern.search(stripped_line)
|
| 68 |
if progress_match:
|
| 69 |
-
#
|
| 70 |
if sub_bar is not None:
|
| 71 |
-
if
|
| 72 |
-
sub_bar.update(
|
| 73 |
sub_bar.close()
|
| 74 |
overall_bar.update(1)
|
| 75 |
overall_bar.refresh()
|
| 76 |
sub_bar = None
|
| 77 |
-
|
| 78 |
video_phase = True
|
| 79 |
current = int(progress_match.group(2))
|
| 80 |
total = int(progress_match.group(3))
|
|
@@ -83,7 +82,6 @@ def infer(prompt, progress=gr.Progress(track_tqdm=True)):
|
|
| 83 |
ncols=120, dynamic_ncols=True, leave=True)
|
| 84 |
video_progress_bar.update(current - video_progress_bar.n)
|
| 85 |
video_progress_bar.refresh()
|
| 86 |
-
# When video progress is complete, finish the video phase.
|
| 87 |
if video_progress_bar.n >= video_progress_bar.total:
|
| 88 |
video_phase = False
|
| 89 |
overall_bar.update(1)
|
|
@@ -92,57 +90,54 @@ def infer(prompt, progress=gr.Progress(track_tqdm=True)):
|
|
| 92 |
video_progress_bar = None
|
| 93 |
continue
|
| 94 |
|
| 95 |
-
# Process INFO messages.
|
| 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
|
| 100 |
-
print(stripped_line)
|
| 101 |
|
| 102 |
if processed_steps < irrelevant_steps:
|
| 103 |
processed_steps += 1
|
| 104 |
else:
|
| 105 |
-
# If
|
| 106 |
if video_phase:
|
| 107 |
continue
|
| 108 |
# If a sub-step is already active, finish it.
|
| 109 |
if sub_bar is not None:
|
| 110 |
-
if
|
| 111 |
-
sub_bar.update(
|
| 112 |
sub_bar.close()
|
| 113 |
overall_bar.update(1)
|
| 114 |
overall_bar.refresh()
|
| 115 |
sub_bar = None
|
| 116 |
-
|
| 117 |
-
# Start a new sub-step progress bar.
|
| 118 |
-
sub_bar = tqdm(total=
|
| 119 |
ncols=120, dynamic_ncols=False, leave=True)
|
| 120 |
-
|
| 121 |
continue
|
| 122 |
else:
|
| 123 |
print(stripped_line)
|
| 124 |
else:
|
| 125 |
-
# No new data
|
| 126 |
if sub_bar is not None:
|
| 127 |
sub_bar.update(1)
|
| 128 |
-
|
| 129 |
sub_bar.refresh()
|
| 130 |
-
if
|
| 131 |
-
#
|
| 132 |
sub_bar.close()
|
| 133 |
overall_bar.update(1)
|
| 134 |
overall_bar.refresh()
|
| 135 |
sub_bar = None
|
| 136 |
-
|
| 137 |
|
| 138 |
-
# Exit loop if the process is finished.
|
| 139 |
if process.poll() is not None:
|
| 140 |
break
|
| 141 |
|
| 142 |
# Drain any remaining output.
|
| 143 |
for line in process.stdout:
|
| 144 |
print(line.strip())
|
| 145 |
-
|
| 146 |
process.wait()
|
| 147 |
if video_progress_bar is not None:
|
| 148 |
video_progress_bar.close()
|
|
|
|
| 14 |
|
| 15 |
def infer(prompt, progress=gr.Progress(track_tqdm=True)):
|
| 16 |
|
| 17 |
+
# Configuration:
|
| 18 |
total_process_steps = 11 # Total steps (including irrelevant ones)
|
| 19 |
irrelevant_steps = 4 # First 4 INFO messages are skipped
|
| 20 |
relevant_steps = total_process_steps - irrelevant_steps # 7 overall steps
|
|
|
|
| 30 |
|
| 31 |
# Variables for sub-step progress bar (level 2)
|
| 32 |
sub_bar = None
|
| 33 |
+
sub_ticks = 0 # Each tick represents 40ms
|
| 34 |
+
sub_tick_total = 500 # 500 ticks * 0.04 sec = 20 seconds
|
| 35 |
+
video_phase = False
|
| 36 |
|
| 37 |
command = [
|
| 38 |
+
"python", "-u", "-m", "generate", # using -u for unbuffered output
|
| 39 |
"--task", "t2v-1.3B",
|
| 40 |
"--size", "832*480",
|
| 41 |
"--ckpt_dir", "./Wan2.1-T2V-1.3B",
|
|
|
|
| 51 |
text=True,
|
| 52 |
bufsize=1)
|
| 53 |
|
|
|
|
| 54 |
while True:
|
| 55 |
+
# Poll for new stdout data with a 40 ms timeout.
|
| 56 |
+
rlist, _, _ = select.select([process.stdout], [], [], 0.04)
|
| 57 |
if rlist:
|
|
|
|
| 58 |
line = process.stdout.readline()
|
| 59 |
if not line:
|
| 60 |
break
|
|
|
|
| 62 |
if not stripped_line:
|
| 63 |
continue
|
| 64 |
|
| 65 |
+
# Check for video generation progress (level 3).
|
| 66 |
progress_match = progress_pattern.search(stripped_line)
|
| 67 |
if progress_match:
|
| 68 |
+
# If a sub-step bar is active, finish it before entering video phase.
|
| 69 |
if sub_bar is not None:
|
| 70 |
+
if sub_ticks < sub_tick_total:
|
| 71 |
+
sub_bar.update(sub_tick_total - sub_ticks)
|
| 72 |
sub_bar.close()
|
| 73 |
overall_bar.update(1)
|
| 74 |
overall_bar.refresh()
|
| 75 |
sub_bar = None
|
| 76 |
+
sub_ticks = 0
|
| 77 |
video_phase = True
|
| 78 |
current = int(progress_match.group(2))
|
| 79 |
total = int(progress_match.group(3))
|
|
|
|
| 82 |
ncols=120, dynamic_ncols=True, leave=True)
|
| 83 |
video_progress_bar.update(current - video_progress_bar.n)
|
| 84 |
video_progress_bar.refresh()
|
|
|
|
| 85 |
if video_progress_bar.n >= video_progress_bar.total:
|
| 86 |
video_phase = False
|
| 87 |
overall_bar.update(1)
|
|
|
|
| 90 |
video_progress_bar = None
|
| 91 |
continue
|
| 92 |
|
| 93 |
+
# Process INFO messages (level 2 sub-step).
|
| 94 |
if "INFO:" in stripped_line:
|
| 95 |
parts = stripped_line.split("INFO:", 1)
|
| 96 |
msg = parts[1].strip() if len(parts) > 1 else ""
|
| 97 |
+
print(stripped_line) # Print log line
|
|
|
|
| 98 |
|
| 99 |
if processed_steps < irrelevant_steps:
|
| 100 |
processed_steps += 1
|
| 101 |
else:
|
| 102 |
+
# If in video phase, ignore new INFO messages.
|
| 103 |
if video_phase:
|
| 104 |
continue
|
| 105 |
# If a sub-step is already active, finish it.
|
| 106 |
if sub_bar is not None:
|
| 107 |
+
if sub_ticks < sub_tick_total:
|
| 108 |
+
sub_bar.update(sub_tick_total - sub_ticks)
|
| 109 |
sub_bar.close()
|
| 110 |
overall_bar.update(1)
|
| 111 |
overall_bar.refresh()
|
| 112 |
sub_bar = None
|
| 113 |
+
sub_ticks = 0
|
| 114 |
+
# Start a new sub-step progress bar with total=500 ticks.
|
| 115 |
+
sub_bar = tqdm(total=sub_tick_total, desc=msg, position=2,
|
| 116 |
ncols=120, dynamic_ncols=False, leave=True)
|
| 117 |
+
sub_ticks = 0
|
| 118 |
continue
|
| 119 |
else:
|
| 120 |
print(stripped_line)
|
| 121 |
else:
|
| 122 |
+
# No new data within 40ms; update the sub-step progress bar.
|
| 123 |
if sub_bar is not None:
|
| 124 |
sub_bar.update(1)
|
| 125 |
+
sub_ticks += 1
|
| 126 |
sub_bar.refresh()
|
| 127 |
+
if sub_ticks >= sub_tick_total:
|
| 128 |
+
# 20 seconds have elapsed; complete this sub-step.
|
| 129 |
sub_bar.close()
|
| 130 |
overall_bar.update(1)
|
| 131 |
overall_bar.refresh()
|
| 132 |
sub_bar = None
|
| 133 |
+
sub_ticks = 0
|
| 134 |
|
|
|
|
| 135 |
if process.poll() is not None:
|
| 136 |
break
|
| 137 |
|
| 138 |
# Drain any remaining output.
|
| 139 |
for line in process.stdout:
|
| 140 |
print(line.strip())
|
|
|
|
| 141 |
process.wait()
|
| 142 |
if video_progress_bar is not None:
|
| 143 |
video_progress_bar.close()
|