Spaces:
Running
Running
Update simple_app.py
Browse files- simple_app.py +25 -13
simple_app.py
CHANGED
|
@@ -32,31 +32,43 @@ def infer(prompt, progress=gr.Progress(track_tqdm=True)):
|
|
| 32 |
bufsize=1 # line-buffered
|
| 33 |
)
|
| 34 |
|
| 35 |
-
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
progress_pattern = re.compile(r"(\d+)%\|.*\| (\d+)/(\d+)")
|
| 38 |
|
| 39 |
for line in iter(process.stdout.readline, ''):
|
| 40 |
-
# Remove
|
| 41 |
stripped_line = line.strip()
|
| 42 |
-
# Skip empty lines
|
| 43 |
if not stripped_line:
|
| 44 |
continue
|
| 45 |
-
|
|
|
|
| 46 |
match = progress_pattern.search(stripped_line)
|
| 47 |
if match:
|
|
|
|
| 48 |
current = int(match.group(2))
|
| 49 |
total = int(match.group(3))
|
| 50 |
-
if
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
|
|
|
| 54 |
else:
|
| 55 |
-
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
process.wait()
|
| 58 |
-
if
|
| 59 |
-
|
|
|
|
| 60 |
|
| 61 |
if process.returncode == 0:
|
| 62 |
print("Command executed successfully.")
|
|
|
|
| 32 |
bufsize=1 # line-buffered
|
| 33 |
)
|
| 34 |
|
| 35 |
+
# This bar will track the generation progress (extracted from the stdout progress lines)
|
| 36 |
+
gen_progress_bar = None
|
| 37 |
+
# This bar will "simulate" a progress update for each log line (non-progress messages).
|
| 38 |
+
# We start with a total of 0 and update its total dynamically.
|
| 39 |
+
log_progress_bar = tqdm(total=0, desc="Logs", position=1, dynamic_ncols=True, leave=True)
|
| 40 |
+
|
| 41 |
progress_pattern = re.compile(r"(\d+)%\|.*\| (\d+)/(\d+)")
|
| 42 |
|
| 43 |
for line in iter(process.stdout.readline, ''):
|
| 44 |
+
# Remove whitespace so we can check for empty lines.
|
| 45 |
stripped_line = line.strip()
|
|
|
|
| 46 |
if not stripped_line:
|
| 47 |
continue
|
| 48 |
+
|
| 49 |
+
# Check if the line matches the progress bar format from the external process.
|
| 50 |
match = progress_pattern.search(stripped_line)
|
| 51 |
if match:
|
| 52 |
+
# Extract current step and total from the match.
|
| 53 |
current = int(match.group(2))
|
| 54 |
total = int(match.group(3))
|
| 55 |
+
if gen_progress_bar is None:
|
| 56 |
+
gen_progress_bar = tqdm(total=total, desc="Video Generation Progress", position=0, dynamic_ncols=True, leave=True)
|
| 57 |
+
# Update generation progress (ensuring we only advance by the difference)
|
| 58 |
+
gen_progress_bar.update(current - gen_progress_bar.n)
|
| 59 |
+
gen_progress_bar.refresh()
|
| 60 |
else:
|
| 61 |
+
# For any log line that is not part of the progress output, update the fake log track.
|
| 62 |
+
# Increase the total count by one and update one step.
|
| 63 |
+
log_progress_bar.total += 1
|
| 64 |
+
log_progress_bar.update(1)
|
| 65 |
+
# Write the log line so it appears in order above the progress bars.
|
| 66 |
+
tqdm.write(stripped_line)
|
| 67 |
+
|
| 68 |
process.wait()
|
| 69 |
+
if gen_progress_bar is not None:
|
| 70 |
+
gen_progress_bar.close()
|
| 71 |
+
log_progress_bar.close()
|
| 72 |
|
| 73 |
if process.returncode == 0:
|
| 74 |
print("Command executed successfully.")
|