Spaces:
Running
Running
Update simple_app.py
Browse files- simple_app.py +33 -54
simple_app.py
CHANGED
@@ -16,10 +16,10 @@ 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,16 +29,14 @@ 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 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
|
42 |
"--task", "t2v-1.3B",
|
43 |
"--size", "832*480",
|
44 |
"--ckpt_dir", "./Wan2.1-T2V-1.3B",
|
@@ -54,8 +52,9 @@ def infer(prompt, progress=gr.Progress(track_tqdm=True)):
|
|
54 |
text=True,
|
55 |
bufsize=1)
|
56 |
|
|
|
57 |
while True:
|
58 |
-
# Poll stdout with a timeout
|
59 |
rlist, _, _ = select.select([process.stdout], [], [], 0.04)
|
60 |
if rlist:
|
61 |
line = process.stdout.readline()
|
@@ -65,7 +64,7 @@ def infer(prompt, progress=gr.Progress(track_tqdm=True)):
|
|
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.
|
@@ -78,6 +77,7 @@ def infer(prompt, progress=gr.Progress(track_tqdm=True)):
|
|
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:
|
@@ -86,50 +86,37 @@ def infer(prompt, progress=gr.Progress(track_tqdm=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()
|
91 |
video_progress_bar.close()
|
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(stripped_line) # Log the message
|
100 |
|
|
|
101 |
if processed_steps < irrelevant_steps:
|
102 |
processed_steps += 1
|
103 |
-
#
|
104 |
-
|
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 |
-
#
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
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,26 +124,18 @@ def infer(prompt, progress=gr.Progress(track_tqdm=True)):
|
|
137 |
else:
|
138 |
print(stripped_line)
|
139 |
else:
|
140 |
-
# No new
|
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 |
-
|
148 |
-
sub_ticks
|
149 |
-
|
150 |
-
|
151 |
-
sub_bar.
|
152 |
-
|
153 |
-
overall_bar.refresh()
|
154 |
-
sub_bar = None
|
155 |
-
sub_ticks = 0
|
156 |
if process.poll() is not None:
|
157 |
break
|
158 |
|
159 |
-
# Drain remaining output.
|
160 |
for line in process.stdout:
|
161 |
print(line.strip())
|
162 |
process.wait()
|
|
|
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 process 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'll 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 |
+
video_phase = False
|
|
|
|
|
37 |
|
38 |
command = [
|
39 |
+
"python", "-u", "-m", "generate", # using -u for unbuffered output
|
40 |
"--task", "t2v-1.3B",
|
41 |
"--size", "832*480",
|
42 |
"--ckpt_dir", "./Wan2.1-T2V-1.3B",
|
|
|
52 |
text=True,
|
53 |
bufsize=1)
|
54 |
|
55 |
+
# Main polling loop
|
56 |
while True:
|
57 |
+
# Poll stdout with a 40ms timeout.
|
58 |
rlist, _, _ = select.select([process.stdout], [], [], 0.04)
|
59 |
if rlist:
|
60 |
line = process.stdout.readline()
|
|
|
64 |
if not stripped_line:
|
65 |
continue
|
66 |
|
67 |
+
# Check for video generation progress (Level 3)
|
68 |
progress_match = progress_pattern.search(stripped_line)
|
69 |
if progress_match:
|
70 |
# If a sub-step bar is active, finish it before entering video phase.
|
|
|
77 |
sub_bar = None
|
78 |
sub_ticks = 0
|
79 |
waiting_for_first_relevant = False
|
80 |
+
video_phase = True
|
81 |
current = int(progress_match.group(2))
|
82 |
total = int(progress_match.group(3))
|
83 |
if video_progress_bar is None:
|
|
|
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 |
+
video_phase = False
|
90 |
overall_bar.update(1)
|
91 |
overall_bar.refresh()
|
92 |
video_progress_bar.close()
|
93 |
video_progress_bar = None
|
94 |
continue
|
95 |
|
96 |
+
# Process INFO messages (Level 2 sub-step)
|
97 |
if "INFO:" in stripped_line:
|
98 |
parts = stripped_line.split("INFO:", 1)
|
99 |
msg = parts[1].strip() if len(parts) > 1 else ""
|
100 |
print(stripped_line) # Log the message
|
101 |
|
102 |
+
# For the first 4 INFO messages, simply count them.
|
103 |
if processed_steps < irrelevant_steps:
|
104 |
processed_steps += 1
|
105 |
+
# Optionally, you could start a waiting bar here if desired.
|
106 |
+
# But if not, just continue.
|
|
|
|
|
|
|
107 |
continue
|
108 |
else:
|
109 |
+
# A new relevant INFO message has arrived.
|
110 |
+
# If a sub-bar exists (whether full or not), finish it now.
|
111 |
+
if sub_bar is not None:
|
112 |
+
if sub_ticks < sub_tick_total:
|
113 |
+
sub_bar.update(sub_tick_total - sub_ticks)
|
114 |
+
sub_bar.close()
|
115 |
+
overall_bar.update(1)
|
116 |
+
overall_bar.refresh()
|
117 |
+
sub_bar = None
|
118 |
+
sub_ticks = 0
|
119 |
+
# Start a new sub-step bar with the current INFO message.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
120 |
sub_bar = tqdm(total=sub_tick_total, desc=msg, position=2,
|
121 |
ncols=120, dynamic_ncols=False, leave=True)
|
122 |
sub_ticks = 0
|
|
|
124 |
else:
|
125 |
print(stripped_line)
|
126 |
else:
|
127 |
+
# No new data within 40ms.
|
|
|
|
|
|
|
|
|
|
|
128 |
if sub_bar is not None:
|
129 |
+
# Only update the sub-bar if it hasn't yet reached its maximum.
|
130 |
+
if sub_ticks < sub_tick_total:
|
131 |
+
sub_bar.update(1)
|
132 |
+
sub_ticks += 1
|
133 |
+
sub_bar.refresh()
|
134 |
+
# If it is full, do nothing; just wait for the next INFO message.
|
|
|
|
|
|
|
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()
|