Spaces:
Paused
Paused
Update simple_app.py
Browse files- simple_app.py +9 -12
simple_app.py
CHANGED
@@ -16,11 +16,10 @@ 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 an overall progress bar for the relevant 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 to capture video generation progress lines (e.g., "
|
24 |
progress_pattern = re.compile(r"(\d+)%\|.*\| (\d+)/(\d+)")
|
25 |
|
26 |
gen_progress_bar = None
|
@@ -50,36 +49,34 @@ def infer(prompt, progress=gr.Progress(track_tqdm=True)):
|
|
50 |
if not stripped_line:
|
51 |
continue
|
52 |
|
53 |
-
#
|
54 |
progress_match = progress_pattern.search(stripped_line)
|
55 |
if progress_match:
|
56 |
current = int(progress_match.group(2))
|
57 |
total = int(progress_match.group(3))
|
58 |
if gen_progress_bar is None:
|
59 |
gen_progress_bar = tqdm(total=total, desc="Video Generation", position=0, dynamic_ncols=True, leave=True)
|
60 |
-
# Update video generation progress.
|
61 |
gen_progress_bar.update(current - gen_progress_bar.n)
|
62 |
gen_progress_bar.refresh()
|
63 |
-
continue
|
64 |
|
65 |
-
# Now check
|
66 |
-
if "
|
67 |
-
#
|
68 |
parts = stripped_line.split("INFO:", 1)
|
69 |
msg = parts[1].strip() if len(parts) > 1 else ""
|
70 |
-
# Print the
|
71 |
tqdm.write(stripped_line)
|
72 |
-
#
|
73 |
if processed_steps < irrelevant_steps:
|
74 |
processed_steps += 1
|
75 |
else:
|
76 |
overall_bar.update(1)
|
77 |
percentage = (overall_bar.n / overall_bar.total) * 100
|
78 |
-
#
|
79 |
overall_bar.set_description(f"Overall Process - {percentage:.1f}% | {msg}")
|
80 |
overall_bar.refresh()
|
81 |
else:
|
82 |
-
# For any other line, simply print it.
|
83 |
tqdm.write(stripped_line)
|
84 |
|
85 |
process.wait()
|
|
|
16 |
irrelevant_steps = 4
|
17 |
relevant_steps = total_process_steps - irrelevant_steps # 7 steps
|
18 |
|
|
|
19 |
overall_bar = tqdm(total=relevant_steps, desc="Overall Process", position=1, dynamic_ncols=True, leave=True)
|
20 |
processed_steps = 0
|
21 |
|
22 |
+
# Regex to capture video generation progress lines (e.g., "10%|...| 5/50")
|
23 |
progress_pattern = re.compile(r"(\d+)%\|.*\| (\d+)/(\d+)")
|
24 |
|
25 |
gen_progress_bar = None
|
|
|
49 |
if not stripped_line:
|
50 |
continue
|
51 |
|
52 |
+
# First, check for video generation progress lines.
|
53 |
progress_match = progress_pattern.search(stripped_line)
|
54 |
if progress_match:
|
55 |
current = int(progress_match.group(2))
|
56 |
total = int(progress_match.group(3))
|
57 |
if gen_progress_bar is None:
|
58 |
gen_progress_bar = tqdm(total=total, desc="Video Generation", position=0, dynamic_ncols=True, leave=True)
|
|
|
59 |
gen_progress_bar.update(current - gen_progress_bar.n)
|
60 |
gen_progress_bar.refresh()
|
61 |
+
continue
|
62 |
|
63 |
+
# Now, check for INFO lines in a case-insensitive way.
|
64 |
+
if "info:" in stripped_line.lower():
|
65 |
+
# Split on "INFO:" (in a case-insensitive manner) to get the text after it.
|
66 |
parts = stripped_line.split("INFO:", 1)
|
67 |
msg = parts[1].strip() if len(parts) > 1 else ""
|
68 |
+
# Print the log line.
|
69 |
tqdm.write(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 |
+
# Update the overall bar description with both the percentage and the extracted INFO message.
|
77 |
overall_bar.set_description(f"Overall Process - {percentage:.1f}% | {msg}")
|
78 |
overall_bar.refresh()
|
79 |
else:
|
|
|
80 |
tqdm.write(stripped_line)
|
81 |
|
82 |
process.wait()
|