Spaces:
Running
Running
Update simple_app.py
Browse files- simple_app.py +59 -74
simple_app.py
CHANGED
@@ -2,7 +2,6 @@ import gradio as gr
|
|
2 |
import re
|
3 |
import subprocess
|
4 |
import time
|
5 |
-
import select
|
6 |
from tqdm import tqdm
|
7 |
from huggingface_hub import snapshot_download
|
8 |
import torch
|
@@ -59,30 +58,58 @@ def infer(prompt, progress=gr.Progress(track_tqdm=True)):
|
|
59 |
text=True,
|
60 |
bufsize=1)
|
61 |
|
62 |
-
stdout, stderr = process.communicate()
|
63 |
-
|
64 |
# Print logs
|
65 |
-
print("🔹 Output Logs
|
66 |
-
|
67 |
-
|
68 |
-
print("Process started successfully.")
|
69 |
-
|
70 |
-
|
71 |
while True:
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
continue
|
81 |
-
|
82 |
-
|
83 |
-
progress_match = progress_pattern.search(stripped_line)
|
84 |
-
|
85 |
-
if progress_match:
|
86 |
if sub_bar is not None:
|
87 |
if sub_ticks < sub_tick_total:
|
88 |
sub_bar.update(sub_tick_total - sub_ticks)
|
@@ -91,63 +118,21 @@ def infer(prompt, progress=gr.Progress(track_tqdm=True)):
|
|
91 |
overall_bar.refresh()
|
92 |
sub_bar = None
|
93 |
sub_ticks = 0
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
ncols=120, dynamic_ncols=True, leave=True)
|
100 |
-
video_progress_bar.update(current - video_progress_bar.n)
|
101 |
-
video_progress_bar.refresh()
|
102 |
-
if video_progress_bar.n >= video_progress_bar.total:
|
103 |
-
video_phase = False
|
104 |
-
overall_bar.update(1)
|
105 |
-
overall_bar.refresh()
|
106 |
-
video_progress_bar.close()
|
107 |
-
video_progress_bar = None
|
108 |
-
continue
|
109 |
-
|
110 |
-
# Process INFO messages (Level 2 sub-step)
|
111 |
-
if "INFO:" in stripped_line:
|
112 |
-
parts = stripped_line.split("INFO:", 1)
|
113 |
-
msg = parts[1].strip() if len(parts) > 1 else ""
|
114 |
-
print(f"[INFO]: {msg}") # Log the message
|
115 |
-
|
116 |
-
# For the first 4 INFO messages, simply count them.
|
117 |
-
if processed_steps < irrelevant_steps:
|
118 |
-
processed_steps += 1
|
119 |
-
continue
|
120 |
-
else:
|
121 |
-
# A new relevant INFO message has arrived.
|
122 |
-
if sub_bar is not None:
|
123 |
-
if sub_ticks < sub_tick_total:
|
124 |
-
sub_bar.update(sub_tick_total - sub_ticks)
|
125 |
-
sub_bar.close()
|
126 |
-
overall_bar.update(1)
|
127 |
-
overall_bar.refresh()
|
128 |
-
sub_bar = None
|
129 |
-
sub_ticks = 0
|
130 |
-
# Start a new sub-step bar for the current INFO message.
|
131 |
-
sub_bar = tqdm(total=sub_tick_total, desc=msg, position=2,
|
132 |
-
ncols=120, dynamic_ncols=False, leave=True)
|
133 |
-
sub_ticks = 0
|
134 |
-
continue
|
135 |
-
else:
|
136 |
-
print(stripped_line)
|
137 |
else:
|
138 |
-
|
139 |
-
if sub_bar is not None:
|
140 |
-
if sub_ticks < sub_tick_total:
|
141 |
-
sub_bar.update(1)
|
142 |
-
sub_ticks += 1
|
143 |
-
sub_bar.refresh()
|
144 |
-
if process.poll() is not None:
|
145 |
-
break
|
146 |
|
147 |
-
# Drain any remaining output
|
148 |
for line in process.stdout:
|
149 |
print(line.strip())
|
|
|
150 |
process.wait()
|
|
|
|
|
151 |
if video_progress_bar is not None:
|
152 |
video_progress_bar.close()
|
153 |
if sub_bar is not None:
|
|
|
2 |
import re
|
3 |
import subprocess
|
4 |
import time
|
|
|
5 |
from tqdm import tqdm
|
6 |
from huggingface_hub import snapshot_download
|
7 |
import torch
|
|
|
58 |
text=True,
|
59 |
bufsize=1)
|
60 |
|
|
|
|
|
61 |
# Print logs
|
62 |
+
print("🔹 Output Logs:")
|
63 |
+
stdout = process.stdout
|
64 |
+
stderr = process.stderr
|
|
|
|
|
|
|
65 |
while True:
|
66 |
+
line = stdout.readline()
|
67 |
+
if not line:
|
68 |
+
break
|
69 |
+
stripped_line = line.strip()
|
70 |
+
if not stripped_line:
|
71 |
+
continue
|
72 |
+
|
73 |
+
# Check for video generation progress (Level 3)
|
74 |
+
progress_match = progress_pattern.search(stripped_line)
|
75 |
+
|
76 |
+
if progress_match:
|
77 |
+
if sub_bar is not None:
|
78 |
+
if sub_ticks < sub_tick_total:
|
79 |
+
sub_bar.update(sub_tick_total - sub_ticks)
|
80 |
+
sub_bar.close()
|
81 |
+
overall_bar.update(1)
|
82 |
+
overall_bar.refresh()
|
83 |
+
sub_bar = None
|
84 |
+
sub_ticks = 0
|
85 |
+
video_phase = True
|
86 |
+
current = int(progress_match.group(2))
|
87 |
+
total = int(progress_match.group(3))
|
88 |
+
if video_progress_bar is None:
|
89 |
+
video_progress_bar = tqdm(total=total, desc="Video Generation", position=0,
|
90 |
+
ncols=120, dynamic_ncols=True, leave=True)
|
91 |
+
video_progress_bar.update(current - video_progress_bar.n)
|
92 |
+
video_progress_bar.refresh()
|
93 |
+
if video_progress_bar.n >= video_progress_bar.total:
|
94 |
+
video_phase = False
|
95 |
+
overall_bar.update(1)
|
96 |
+
overall_bar.refresh()
|
97 |
+
video_progress_bar.close()
|
98 |
+
video_progress_bar = None
|
99 |
+
continue
|
100 |
+
|
101 |
+
# Process INFO messages (Level 2 sub-step)
|
102 |
+
if "INFO:" in stripped_line:
|
103 |
+
parts = stripped_line.split("INFO:", 1)
|
104 |
+
msg = parts[1].strip() if len(parts) > 1 else ""
|
105 |
+
print(f"[INFO]: {msg}") # Log the message
|
106 |
+
|
107 |
+
# For the first 4 INFO messages, simply count them.
|
108 |
+
if processed_steps < irrelevant_steps:
|
109 |
+
processed_steps += 1
|
110 |
continue
|
111 |
+
else:
|
112 |
+
# A new relevant INFO message has arrived.
|
|
|
|
|
|
|
113 |
if sub_bar is not None:
|
114 |
if sub_ticks < sub_tick_total:
|
115 |
sub_bar.update(sub_tick_total - sub_ticks)
|
|
|
118 |
overall_bar.refresh()
|
119 |
sub_bar = None
|
120 |
sub_ticks = 0
|
121 |
+
# Start a new sub-step bar for the current INFO message.
|
122 |
+
sub_bar = tqdm(total=sub_tick_total, desc=msg, position=2,
|
123 |
+
ncols=120, dynamic_ncols=False, leave=True)
|
124 |
+
sub_ticks = 0
|
125 |
+
continue
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
else:
|
127 |
+
print(stripped_line)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
128 |
|
129 |
+
# Drain any remaining output
|
130 |
for line in process.stdout:
|
131 |
print(line.strip())
|
132 |
+
|
133 |
process.wait()
|
134 |
+
|
135 |
+
# Finalize progress bars
|
136 |
if video_progress_bar is not None:
|
137 |
video_progress_bar.close()
|
138 |
if sub_bar is not None:
|