Spaces:
Running
Running
Update simple_app.py
Browse files- simple_app.py +16 -16
simple_app.py
CHANGED
|
@@ -11,21 +11,20 @@ snapshot_download(
|
|
| 11 |
)
|
| 12 |
|
| 13 |
def infer(prompt, progress=gr.Progress(track_tqdm=True)):
|
| 14 |
-
|
| 15 |
-
total_process_steps =
|
| 16 |
irrelevant_steps = 4
|
| 17 |
-
|
| 18 |
-
relevant_steps = total_process_steps - irrelevant_steps # 8 steps
|
| 19 |
|
| 20 |
-
# Overall progress bar for
|
| 21 |
overall_bar = tqdm(total=relevant_steps, desc="Overall Process", position=1, dynamic_ncols=True, leave=True)
|
| 22 |
processed_steps = 0
|
| 23 |
|
| 24 |
-
# Regex to extract the INFO message
|
| 25 |
-
info_pattern = re.compile(r"
|
| 26 |
-
# Regex to capture progress lines
|
| 27 |
progress_pattern = re.compile(r"(\d+)%\|.*\| (\d+)/(\d+)")
|
| 28 |
-
|
| 29 |
gen_progress_bar = None
|
| 30 |
|
| 31 |
command = [
|
|
@@ -53,31 +52,32 @@ def infer(prompt, progress=gr.Progress(track_tqdm=True)):
|
|
| 53 |
if not stripped_line:
|
| 54 |
continue
|
| 55 |
|
| 56 |
-
# Check for
|
| 57 |
progress_match = progress_pattern.search(stripped_line)
|
| 58 |
if progress_match:
|
| 59 |
current = int(progress_match.group(2))
|
| 60 |
total = int(progress_match.group(3))
|
| 61 |
if gen_progress_bar is None:
|
| 62 |
gen_progress_bar = tqdm(total=total, desc="Video Generation", position=0, dynamic_ncols=True, leave=True)
|
| 63 |
-
# Update the video generation progress bar
|
| 64 |
gen_progress_bar.update(current - gen_progress_bar.n)
|
| 65 |
gen_progress_bar.refresh()
|
| 66 |
-
continue
|
| 67 |
|
| 68 |
-
# Check for an INFO log line
|
| 69 |
info_match = info_pattern.search(stripped_line)
|
| 70 |
if info_match:
|
| 71 |
msg = info_match.group(1)
|
| 72 |
-
# Skip the first three INFO messages
|
| 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 |
overall_bar.set_description(f"Overall Process - {percentage:.1f}% | {msg}")
|
| 79 |
-
|
| 80 |
-
|
|
|
|
| 81 |
else:
|
| 82 |
tqdm.write(stripped_line)
|
| 83 |
|
|
|
|
| 11 |
)
|
| 12 |
|
| 13 |
def infer(prompt, progress=gr.Progress(track_tqdm=True)):
|
| 14 |
+
|
| 15 |
+
total_process_steps = 11
|
| 16 |
irrelevant_steps = 4
|
| 17 |
+
relevant_steps = total_process_steps - irrelevant_steps # 7 steps
|
|
|
|
| 18 |
|
| 19 |
+
# Overall progress bar for relevant steps (position=1 so it appears below the generation bar)
|
| 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 (like "10%|...| 5/50")
|
| 26 |
progress_pattern = re.compile(r"(\d+)%\|.*\| (\d+)/(\d+)")
|
| 27 |
+
|
| 28 |
gen_progress_bar = None
|
| 29 |
|
| 30 |
command = [
|
|
|
|
| 52 |
if not stripped_line:
|
| 53 |
continue
|
| 54 |
|
| 55 |
+
# Check for video generation progress lines
|
| 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 for an INFO log line
|
| 67 |
info_match = info_pattern.search(stripped_line)
|
| 68 |
if info_match:
|
| 69 |
msg = info_match.group(1)
|
| 70 |
+
# Skip the first three INFO messages
|
| 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 |
|