Spaces:
Running
Running
Update simple_app.py
Browse files- simple_app.py +43 -26
simple_app.py
CHANGED
|
@@ -12,6 +12,22 @@ snapshot_download(
|
|
| 12 |
|
| 13 |
def infer(prompt, progress=gr.Progress(track_tqdm=True)):
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
command = [
|
| 16 |
"python", "-u", "-m", "generate", # using -u for unbuffered output and omitting .py extension
|
| 17 |
"--task", "t2v-1.3B",
|
|
@@ -32,43 +48,44 @@ def infer(prompt, progress=gr.Progress(track_tqdm=True)):
|
|
| 32 |
bufsize=1 # line-buffered
|
| 33 |
)
|
| 34 |
|
| 35 |
-
# This bar will track the generation progress (extracted from the stdout progress lines)
|
| 36 |
-
gen_progress_bar = None
|
| 37 |
-
# This bar will "simulate" a progress update for each log line (non-progress messages).
|
| 38 |
-
# We start with a total of 0 and update its total dynamically.
|
| 39 |
-
log_progress_bar = tqdm(total=0, desc="Logs", position=1, dynamic_ncols=True, leave=True)
|
| 40 |
-
|
| 41 |
-
progress_pattern = re.compile(r"(\d+)%\|.*\| (\d+)/(\d+)")
|
| 42 |
-
|
| 43 |
for line in iter(process.stdout.readline, ''):
|
| 44 |
-
# Remove whitespace so we can check for empty lines.
|
| 45 |
stripped_line = line.strip()
|
| 46 |
if not stripped_line:
|
| 47 |
continue
|
| 48 |
-
|
| 49 |
-
# Check
|
| 50 |
-
|
| 51 |
-
if
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
total = int(match.group(3))
|
| 55 |
if gen_progress_bar is None:
|
| 56 |
-
gen_progress_bar = tqdm(total=total, desc="Video Generation
|
| 57 |
-
# Update generation progress
|
| 58 |
gen_progress_bar.update(current - gen_progress_bar.n)
|
| 59 |
gen_progress_bar.refresh()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
else:
|
| 61 |
-
#
|
| 62 |
-
# Increase the total count by one and update one step.
|
| 63 |
-
log_progress_bar.total += 1
|
| 64 |
-
log_progress_bar.update(1)
|
| 65 |
-
# Write the log line so it appears in order above the progress bars.
|
| 66 |
tqdm.write(stripped_line)
|
| 67 |
-
|
| 68 |
process.wait()
|
| 69 |
-
if gen_progress_bar
|
| 70 |
gen_progress_bar.close()
|
| 71 |
-
|
| 72 |
|
| 73 |
if process.returncode == 0:
|
| 74 |
print("Command executed successfully.")
|
|
|
|
| 12 |
|
| 13 |
def infer(prompt, progress=gr.Progress(track_tqdm=True)):
|
| 14 |
|
| 15 |
+
# Total process steps is 12; the first three are irrelevant so we count 9 relevant steps.
|
| 16 |
+
total_process_steps = 12
|
| 17 |
+
irrelevant_steps = 3
|
| 18 |
+
relevant_steps = total_process_steps - irrelevant_steps # 9 steps
|
| 19 |
+
|
| 20 |
+
# This bar will track the overall process (steps 4 to 12)
|
| 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
|
| 30 |
+
|
| 31 |
command = [
|
| 32 |
"python", "-u", "-m", "generate", # using -u for unbuffered output and omitting .py extension
|
| 33 |
"--task", "t2v-1.3B",
|
|
|
|
| 48 |
bufsize=1 # line-buffered
|
| 49 |
)
|
| 50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
for line in iter(process.stdout.readline, ''):
|
|
|
|
| 52 |
stripped_line = line.strip()
|
| 53 |
if not stripped_line:
|
| 54 |
continue
|
| 55 |
+
|
| 56 |
+
# Check for a progress line from the video generation process.
|
| 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 generation progress bar by the difference.
|
| 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 |
+
|
| 73 |
+
# Skip the first three INFO messages.
|
| 74 |
+
if processed_steps < irrelevant_steps:
|
| 75 |
+
processed_steps += 1
|
| 76 |
+
else:
|
| 77 |
+
overall_bar.update(1)
|
| 78 |
+
overall_bar.set_description(f"Overall: {msg}")
|
| 79 |
+
# Print the log message.
|
| 80 |
+
tqdm.write(stripped_line)
|
| 81 |
else:
|
| 82 |
+
# Print any other lines.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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.")
|