Update simple_app.py
Browse files- simple_app.py +5 -10
simple_app.py
CHANGED
|
@@ -19,7 +19,7 @@ def infer(prompt, progress=gr.Progress(track_tqdm=True)):
|
|
| 19 |
irrelevant_steps = 4 # First 4 INFO messages are ignored
|
| 20 |
relevant_steps = total_process_steps - irrelevant_steps # 7 overall steps
|
| 21 |
|
| 22 |
-
# Create overall
|
| 23 |
overall_bar = tqdm(total=relevant_steps, desc="Overall Process", position=1,
|
| 24 |
ncols=120, dynamic_ncols=False, leave=True)
|
| 25 |
processed_steps = 0
|
|
@@ -29,10 +29,10 @@ def infer(prompt, progress=gr.Progress(track_tqdm=True)):
|
|
| 29 |
video_progress_bar = None
|
| 30 |
|
| 31 |
# Variables for sub-step progress bar (Level 2)
|
| 32 |
-
#
|
| 33 |
sub_bar = None
|
| 34 |
sub_ticks = 0
|
| 35 |
-
sub_tick_total =
|
| 36 |
video_phase = False
|
| 37 |
|
| 38 |
command = [
|
|
@@ -52,7 +52,6 @@ def infer(prompt, progress=gr.Progress(track_tqdm=True)):
|
|
| 52 |
text=True,
|
| 53 |
bufsize=1)
|
| 54 |
|
| 55 |
-
# Main polling loop
|
| 56 |
while True:
|
| 57 |
# Poll stdout with a 40ms timeout.
|
| 58 |
rlist, _, _ = select.select([process.stdout], [], [], 0.04)
|
|
@@ -76,7 +75,6 @@ def infer(prompt, progress=gr.Progress(track_tqdm=True)):
|
|
| 76 |
overall_bar.refresh()
|
| 77 |
sub_bar = None
|
| 78 |
sub_ticks = 0
|
| 79 |
-
waiting_for_first_relevant = False
|
| 80 |
video_phase = True
|
| 81 |
current = int(progress_match.group(2))
|
| 82 |
total = int(progress_match.group(3))
|
|
@@ -102,8 +100,6 @@ def infer(prompt, progress=gr.Progress(track_tqdm=True)):
|
|
| 102 |
# For the first 4 INFO messages, simply count them.
|
| 103 |
if processed_steps < irrelevant_steps:
|
| 104 |
processed_steps += 1
|
| 105 |
-
# Optionally, you could start a waiting bar here if desired.
|
| 106 |
-
# But if not, just continue.
|
| 107 |
continue
|
| 108 |
else:
|
| 109 |
# A new relevant INFO message has arrived.
|
|
@@ -116,7 +112,7 @@ def infer(prompt, progress=gr.Progress(track_tqdm=True)):
|
|
| 116 |
overall_bar.refresh()
|
| 117 |
sub_bar = None
|
| 118 |
sub_ticks = 0
|
| 119 |
-
# Start a new sub-step bar
|
| 120 |
sub_bar = tqdm(total=sub_tick_total, desc=msg, position=2,
|
| 121 |
ncols=120, dynamic_ncols=False, leave=True)
|
| 122 |
sub_ticks = 0
|
|
@@ -126,12 +122,11 @@ def infer(prompt, progress=gr.Progress(track_tqdm=True)):
|
|
| 126 |
else:
|
| 127 |
# No new data within 40ms.
|
| 128 |
if sub_bar is not None:
|
| 129 |
-
# Only update the sub-bar if it hasn't yet reached its maximum.
|
| 130 |
if sub_ticks < sub_tick_total:
|
| 131 |
sub_bar.update(1)
|
| 132 |
sub_ticks += 1
|
| 133 |
sub_bar.refresh()
|
| 134 |
-
# If
|
| 135 |
if process.poll() is not None:
|
| 136 |
break
|
| 137 |
|
|
|
|
| 19 |
irrelevant_steps = 4 # First 4 INFO messages are ignored
|
| 20 |
relevant_steps = total_process_steps - irrelevant_steps # 7 overall steps
|
| 21 |
|
| 22 |
+
# Create overall progress bar (Level 1)
|
| 23 |
overall_bar = tqdm(total=relevant_steps, desc="Overall Process", position=1,
|
| 24 |
ncols=120, dynamic_ncols=False, leave=True)
|
| 25 |
processed_steps = 0
|
|
|
|
| 29 |
video_progress_bar = None
|
| 30 |
|
| 31 |
# Variables for sub-step progress bar (Level 2)
|
| 32 |
+
# Now using 1000 ticks to represent 40 seconds (each tick = 40 ms)
|
| 33 |
sub_bar = None
|
| 34 |
sub_ticks = 0
|
| 35 |
+
sub_tick_total = 1000
|
| 36 |
video_phase = False
|
| 37 |
|
| 38 |
command = [
|
|
|
|
| 52 |
text=True,
|
| 53 |
bufsize=1)
|
| 54 |
|
|
|
|
| 55 |
while True:
|
| 56 |
# Poll stdout with a 40ms timeout.
|
| 57 |
rlist, _, _ = select.select([process.stdout], [], [], 0.04)
|
|
|
|
| 75 |
overall_bar.refresh()
|
| 76 |
sub_bar = None
|
| 77 |
sub_ticks = 0
|
|
|
|
| 78 |
video_phase = True
|
| 79 |
current = int(progress_match.group(2))
|
| 80 |
total = int(progress_match.group(3))
|
|
|
|
| 100 |
# For the first 4 INFO messages, simply count them.
|
| 101 |
if processed_steps < irrelevant_steps:
|
| 102 |
processed_steps += 1
|
|
|
|
|
|
|
| 103 |
continue
|
| 104 |
else:
|
| 105 |
# A new relevant INFO message has arrived.
|
|
|
|
| 112 |
overall_bar.refresh()
|
| 113 |
sub_bar = None
|
| 114 |
sub_ticks = 0
|
| 115 |
+
# Start a new sub-step bar for the current INFO message.
|
| 116 |
sub_bar = tqdm(total=sub_tick_total, desc=msg, position=2,
|
| 117 |
ncols=120, dynamic_ncols=False, leave=True)
|
| 118 |
sub_ticks = 0
|
|
|
|
| 122 |
else:
|
| 123 |
# No new data within 40ms.
|
| 124 |
if sub_bar is not None:
|
|
|
|
| 125 |
if sub_ticks < sub_tick_total:
|
| 126 |
sub_bar.update(1)
|
| 127 |
sub_ticks += 1
|
| 128 |
sub_bar.refresh()
|
| 129 |
+
# If full (40 seconds reached), do not advance overall step—just remain waiting.
|
| 130 |
if process.poll() is not None:
|
| 131 |
break
|
| 132 |
|