Spaces:
Running
Running
Update simple_app.py
Browse files- simple_app.py +11 -10
simple_app.py
CHANGED
|
@@ -16,11 +16,11 @@ def infer(prompt, progress=gr.Progress(track_tqdm=True)):
|
|
| 16 |
irrelevant_steps = 4
|
| 17 |
relevant_steps = total_process_steps - irrelevant_steps # 7 steps
|
| 18 |
|
| 19 |
-
# Create
|
| 20 |
overall_bar = tqdm(total=relevant_steps, desc="Overall Process", position=1, dynamic_ncols=True, leave=True)
|
| 21 |
processed_steps = 0
|
| 22 |
|
| 23 |
-
# Regex for progress lines (e.g
|
| 24 |
progress_pattern = re.compile(r"(\d+)%\|.*\| (\d+)/(\d+)")
|
| 25 |
gen_progress_bar = None
|
| 26 |
|
|
@@ -44,13 +44,12 @@ def infer(prompt, progress=gr.Progress(track_tqdm=True)):
|
|
| 44 |
bufsize=1 # line-buffered
|
| 45 |
)
|
| 46 |
|
| 47 |
-
last_msg = ""
|
| 48 |
for line in iter(process.stdout.readline, ''):
|
| 49 |
stripped_line = line.strip()
|
| 50 |
if not stripped_line:
|
| 51 |
continue
|
| 52 |
|
| 53 |
-
# Check
|
| 54 |
progress_match = progress_pattern.search(stripped_line)
|
| 55 |
if progress_match:
|
| 56 |
current = int(progress_match.group(2))
|
|
@@ -61,23 +60,25 @@ def infer(prompt, progress=gr.Progress(track_tqdm=True)):
|
|
| 61 |
gen_progress_bar.refresh()
|
| 62 |
continue
|
| 63 |
|
| 64 |
-
#
|
| 65 |
if "INFO:" in stripped_line:
|
|
|
|
| 66 |
parts = stripped_line.split("INFO:", 1)
|
| 67 |
msg = parts[1].strip() if len(parts) > 1 else ""
|
| 68 |
# Print the log line.
|
| 69 |
-
|
|
|
|
| 70 |
if processed_steps < irrelevant_steps:
|
| 71 |
processed_steps += 1
|
| 72 |
else:
|
| 73 |
overall_bar.update(1)
|
| 74 |
percentage = (overall_bar.n / overall_bar.total) * 100
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
overall_bar.set_description_str(f"Overall Process - {percentage:.1f}% | {last_msg}")
|
| 78 |
overall_bar.refresh()
|
| 79 |
else:
|
| 80 |
-
|
|
|
|
| 81 |
|
| 82 |
process.wait()
|
| 83 |
if gen_progress_bar:
|
|
|
|
| 16 |
irrelevant_steps = 4
|
| 17 |
relevant_steps = total_process_steps - irrelevant_steps # 7 steps
|
| 18 |
|
| 19 |
+
# Create the overall progress bar for the process steps.
|
| 20 |
overall_bar = tqdm(total=relevant_steps, desc="Overall Process", position=1, dynamic_ncols=True, leave=True)
|
| 21 |
processed_steps = 0
|
| 22 |
|
| 23 |
+
# Regex for detecting video generation progress lines (e.g., "10%|...| 5/50")
|
| 24 |
progress_pattern = re.compile(r"(\d+)%\|.*\| (\d+)/(\d+)")
|
| 25 |
gen_progress_bar = None
|
| 26 |
|
|
|
|
| 44 |
bufsize=1 # line-buffered
|
| 45 |
)
|
| 46 |
|
|
|
|
| 47 |
for line in iter(process.stdout.readline, ''):
|
| 48 |
stripped_line = line.strip()
|
| 49 |
if not stripped_line:
|
| 50 |
continue
|
| 51 |
|
| 52 |
+
# Check if this is a video generation progress line.
|
| 53 |
progress_match = progress_pattern.search(stripped_line)
|
| 54 |
if progress_match:
|
| 55 |
current = int(progress_match.group(2))
|
|
|
|
| 60 |
gen_progress_bar.refresh()
|
| 61 |
continue
|
| 62 |
|
| 63 |
+
# Check for INFO lines.
|
| 64 |
if "INFO:" in stripped_line:
|
| 65 |
+
# Split the line at "INFO:" to extract the message.
|
| 66 |
parts = stripped_line.split("INFO:", 1)
|
| 67 |
msg = parts[1].strip() if len(parts) > 1 else ""
|
| 68 |
# Print the log line.
|
| 69 |
+
print(stripped_line)
|
| 70 |
+
# Skip updating the overall bar for the first three (irrelevant) steps.
|
| 71 |
if processed_steps < irrelevant_steps:
|
| 72 |
processed_steps += 1
|
| 73 |
else:
|
| 74 |
overall_bar.update(1)
|
| 75 |
percentage = (overall_bar.n / overall_bar.total) * 100
|
| 76 |
+
# Directly assign to the description property.
|
| 77 |
+
overall_bar.desc = f"Overall Process - {percentage:.1f}% | {msg}"
|
|
|
|
| 78 |
overall_bar.refresh()
|
| 79 |
else:
|
| 80 |
+
# Print any other lines.
|
| 81 |
+
print(stripped_line)
|
| 82 |
|
| 83 |
process.wait()
|
| 84 |
if gen_progress_bar:
|