fffiloni commited on
Commit
3217fc0
·
verified ·
1 Parent(s): 935512c

Update simple_app.py

Browse files
Files changed (1) hide show
  1. simple_app.py +10 -10
simple_app.py CHANGED
@@ -12,18 +12,17 @@ snapshot_download(
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
@@ -53,7 +52,7 @@ def infer(prompt, progress=gr.Progress(track_tqdm=True)):
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))
@@ -69,21 +68,22 @@ def infer(prompt, progress=gr.Progress(track_tqdm=True)):
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
 
 
12
 
13
  def infer(prompt, progress=gr.Progress(track_tqdm=True)):
14
 
 
15
  total_process_steps = 12
16
  irrelevant_steps = 3
17
  relevant_steps = total_process_steps - irrelevant_steps # 9 steps
18
 
19
+ # Create an overall process bar for the 9 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 extract the INFO message from each log line.
24
  info_pattern = re.compile(r"\[.*?\]\s+INFO:\s+(.*)")
25
+ # Regex to capture progress lines from video generation (like " 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 line is a progress update for video generation.
56
  progress_match = progress_pattern.search(stripped_line)
57
  if progress_match:
58
  current = int(progress_match.group(2))
 
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
+ # Set the description to include both the percentage and the current info title.
79
+ overall_bar.set_description(f"Overall Process - {percentage:.0f}% | {msg}")
80
+ # Write the log line as well.
81
  tqdm.write(stripped_line)
82
  else:
 
83
  tqdm.write(stripped_line)
84
 
85
  process.wait()
86
+ if gen_progress_bar is not None:
87
  gen_progress_bar.close()
88
  overall_bar.close()
89