Update simple_app.py
Browse files- simple_app.py +11 -10
simple_app.py
CHANGED
@@ -20,9 +20,9 @@ def infer(prompt, progress=gr.Progress(track_tqdm=True)):
|
|
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 extract the INFO message
|
24 |
-
info_pattern = re.compile(r"INFO:\s
|
25 |
-
# Regex to capture video generation progress lines (
|
26 |
progress_pattern = re.compile(r"(\d+)%\|.*\| (\d+)/(\d+)")
|
27 |
|
28 |
gen_progress_bar = None
|
@@ -52,33 +52,34 @@ def infer(prompt, progress=gr.Progress(track_tqdm=True)):
|
|
52 |
if not stripped_line:
|
53 |
continue
|
54 |
|
55 |
-
# Check
|
56 |
progress_match = progress_pattern.search(stripped_line)
|
57 |
if progress_match:
|
58 |
current = int(progress_match.group(2))
|
59 |
total = int(progress_match.group(3))
|
60 |
if gen_progress_bar is None:
|
61 |
gen_progress_bar = tqdm(total=total, desc="Video Generation", position=0, dynamic_ncols=True, leave=True)
|
|
|
62 |
gen_progress_bar.update(current - gen_progress_bar.n)
|
63 |
gen_progress_bar.refresh()
|
64 |
-
continue
|
65 |
|
66 |
-
# Check
|
67 |
info_match = info_pattern.search(stripped_line)
|
68 |
if info_match:
|
69 |
msg = info_match.group(1)
|
70 |
-
#
|
|
|
|
|
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 |
-
# Set the overall bar description with both percentage and INFO message
|
77 |
overall_bar.set_description(f"Overall Process - {percentage:.1f}% | {msg}")
|
78 |
overall_bar.refresh()
|
79 |
-
# (Optional) If you don't want duplicate printing, omit printing the INFO line
|
80 |
-
# Otherwise, you could also print it separately with tqdm.write(stripped_line)
|
81 |
else:
|
|
|
82 |
tqdm.write(stripped_line)
|
83 |
|
84 |
process.wait()
|
|
|
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 extract the INFO message (everything after "INFO:")
|
24 |
+
info_pattern = re.compile(r"\[.*?\]\s+INFO:\s+(.*)")
|
25 |
+
# Regex to capture video generation progress lines (e.g. " 10%|...| 5/50")
|
26 |
progress_pattern = re.compile(r"(\d+)%\|.*\| (\d+)/(\d+)")
|
27 |
|
28 |
gen_progress_bar = None
|
|
|
52 |
if not stripped_line:
|
53 |
continue
|
54 |
|
55 |
+
# Check if this is a video generation progress line.
|
56 |
progress_match = progress_pattern.search(stripped_line)
|
57 |
if progress_match:
|
58 |
current = int(progress_match.group(2))
|
59 |
total = int(progress_match.group(3))
|
60 |
if gen_progress_bar is None:
|
61 |
gen_progress_bar = tqdm(total=total, desc="Video Generation", position=0, dynamic_ncols=True, leave=True)
|
62 |
+
# Update video generation progress.
|
63 |
gen_progress_bar.update(current - gen_progress_bar.n)
|
64 |
gen_progress_bar.refresh()
|
65 |
+
continue # Skip further processing for progress lines
|
66 |
|
67 |
+
# Check if this is an INFO log line.
|
68 |
info_match = info_pattern.search(stripped_line)
|
69 |
if info_match:
|
70 |
msg = info_match.group(1)
|
71 |
+
# Always print the log line.
|
72 |
+
tqdm.write(stripped_line)
|
73 |
+
# For relevant steps (i.e. after the first three), update the overall progress.
|
74 |
if processed_steps < irrelevant_steps:
|
75 |
processed_steps += 1
|
76 |
else:
|
77 |
overall_bar.update(1)
|
78 |
percentage = (overall_bar.n / overall_bar.total) * 100
|
|
|
79 |
overall_bar.set_description(f"Overall Process - {percentage:.1f}% | {msg}")
|
80 |
overall_bar.refresh()
|
|
|
|
|
81 |
else:
|
82 |
+
# For any other line, print it.
|
83 |
tqdm.write(stripped_line)
|
84 |
|
85 |
process.wait()
|