Daankular commited on
Commit
e131563
·
1 Parent(s): 24a1162

Stream tqdm progress lines by reading chunks and splitting on \r

Browse files
Files changed (1) hide show
  1. app.py +22 -7
app.py CHANGED
@@ -130,13 +130,28 @@ def generate_video(image, prompt, resolution, steps, guidance_scale, frames, see
130
 
131
  log_lines = []
132
  proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
133
- text=True, bufsize=1, env=env)
134
-
135
- for line in proc.stdout:
136
- stripped = line.rstrip()
137
- log_lines.append(stripped)
138
- print(stripped)
139
- yield None, "\n".join(log_lines[-30:])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
 
141
  proc.wait()
142
  log = "\n".join(log_lines)
 
130
 
131
  log_lines = []
132
  proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
133
+ text=True, bufsize=0, env=env)
134
+
135
+ buf = ""
136
+ while True:
137
+ chunk = proc.stdout.read(256)
138
+ if not chunk:
139
+ break
140
+ buf += chunk
141
+ # Split on \r or \n — tqdm uses \r to overwrite progress lines
142
+ parts = buf.replace("\r", "\n").split("\n")
143
+ buf = parts[-1]
144
+ for part in parts[:-1]:
145
+ stripped = part.strip()
146
+ if not stripped:
147
+ continue
148
+ # Overwrite last line if it looks like a progress bar update
149
+ if log_lines and ("%" in stripped or "it/s" in stripped or "step" in stripped.lower()):
150
+ log_lines[-1] = stripped
151
+ else:
152
+ log_lines.append(stripped)
153
+ print(stripped)
154
+ yield None, "\n".join(log_lines[-30:])
155
 
156
  proc.wait()
157
  log = "\n".join(log_lines)