Spaces:
Running
Running
Update simple_app.py
Browse files- simple_app.py +19 -16
simple_app.py
CHANGED
@@ -13,16 +13,17 @@ snapshot_download(
|
|
13 |
def infer(prompt, progress=gr.Progress(track_tqdm=True)):
|
14 |
|
15 |
total_process_steps = 12
|
16 |
-
irrelevant_steps =
|
17 |
-
|
|
|
18 |
|
19 |
-
#
|
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"\[.*?\]\s+INFO:\s+(.*)")
|
25 |
-
# Regex to capture progress lines
|
26 |
progress_pattern = re.compile(r"(\d+)%\|.*\| (\d+)/(\d+)")
|
27 |
|
28 |
gen_progress_bar = None
|
@@ -52,41 +53,43 @@ 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 |
-
# Update the generation progress bar
|
63 |
gen_progress_bar.update(current - gen_progress_bar.n)
|
64 |
gen_progress_bar.refresh()
|
65 |
-
continue # Skip further processing of this line
|
66 |
|
67 |
-
# Check for an INFO log line
|
68 |
info_match = info_pattern.search(stripped_line)
|
69 |
if info_match:
|
70 |
msg = info_match.group(1)
|
71 |
-
# Skip the first three INFO messages
|
72 |
if processed_steps < irrelevant_steps:
|
73 |
processed_steps += 1
|
74 |
else:
|
75 |
overall_bar.update(1)
|
76 |
-
# Compute the current percentage.
|
77 |
percentage = (overall_bar.n / overall_bar.total) * 100
|
78 |
-
#
|
79 |
-
overall_bar.set_description(f"Overall Process - {percentage:.
|
80 |
-
|
|
|
|
|
|
|
81 |
tqdm.write(stripped_line)
|
82 |
else:
|
83 |
tqdm.write(stripped_line)
|
84 |
|
85 |
process.wait()
|
86 |
-
if gen_progress_bar
|
87 |
gen_progress_bar.close()
|
88 |
overall_bar.close()
|
89 |
-
|
90 |
if process.returncode == 0:
|
91 |
print("Command executed successfully.")
|
92 |
return "generated_video.mp4"
|
|
|
13 |
def infer(prompt, progress=gr.Progress(track_tqdm=True)):
|
14 |
|
15 |
total_process_steps = 12
|
16 |
+
irrelevant_steps = 4
|
17 |
+
# Only the INFO messages from step 5 onward are relevant
|
18 |
+
relevant_steps = total_process_steps - irrelevant_steps # 8 steps
|
19 |
|
20 |
+
# Overall progress bar for the process steps (position=1 to appear below the generation bar)
|
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 (everything after "INFO:")
|
25 |
info_pattern = re.compile(r"\[.*?\]\s+INFO:\s+(.*)")
|
26 |
+
# Regex to capture progress lines for video generation (e.g., " 10%|...| 5/50")
|
27 |
progress_pattern = re.compile(r"(\d+)%\|.*\| (\d+)/(\d+)")
|
28 |
|
29 |
gen_progress_bar = None
|
|
|
53 |
if not stripped_line:
|
54 |
continue
|
55 |
|
56 |
+
# Check for a progress line (video generation progress)
|
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 # Skip further processing of this line
|
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 |
+
# Update overall progress: description shows the percentage
|
79 |
+
overall_bar.set_description(f"Overall Process - {percentage:.1f}%")
|
80 |
+
# Postfix displays the current INFO message title
|
81 |
+
overall_bar.set_postfix_str(msg)
|
82 |
+
overall_bar.refresh()
|
83 |
+
# Also print the raw log message if needed
|
84 |
tqdm.write(stripped_line)
|
85 |
else:
|
86 |
tqdm.write(stripped_line)
|
87 |
|
88 |
process.wait()
|
89 |
+
if gen_progress_bar:
|
90 |
gen_progress_bar.close()
|
91 |
overall_bar.close()
|
92 |
+
|
93 |
if process.returncode == 0:
|
94 |
print("Command executed successfully.")
|
95 |
return "generated_video.mp4"
|