Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -111,15 +111,17 @@ def load_control_lora(control_type, current_lora_state):
|
|
111 |
print(f"Error loading {control_type} LoRA: {e}")
|
112 |
raise
|
113 |
|
114 |
-
def process_video_for_canny(video):
|
115 |
"""
|
116 |
Process video for canny control.
|
117 |
"""
|
118 |
print("Processing video for canny control...")
|
119 |
canny_video = []
|
|
|
|
|
120 |
for frame in video:
|
121 |
# TODO: change resolution logic
|
122 |
-
canny_video.append(canny_processor(frame, low_threshold=50, high_threshold=200, detect_resolution=
|
123 |
|
124 |
return canny_video
|
125 |
|
@@ -169,7 +171,7 @@ def process_video_for_pose(video):
|
|
169 |
return pose_video
|
170 |
|
171 |
@spaces.GPU()
|
172 |
-
def process_input_video(reference_video):
|
173 |
"""
|
174 |
Process the input video for canny edges and return both processed video and preview.
|
175 |
"""
|
@@ -181,7 +183,7 @@ def process_input_video(reference_video):
|
|
181 |
video = load_video(reference_video)
|
182 |
|
183 |
# Process video for canny edges
|
184 |
-
processed_video = process_video_for_canny(video)
|
185 |
|
186 |
# Create a preview video file for display
|
187 |
fps = 24
|
@@ -195,13 +197,13 @@ def process_input_video(reference_video):
|
|
195 |
print(f"Error processing input video: {e}")
|
196 |
return None
|
197 |
|
198 |
-
def process_video_for_control(reference_video, control_type):
|
199 |
"""Process video based on the selected control type - now only used for non-canny types"""
|
200 |
video = load_video(reference_video)
|
201 |
|
202 |
if control_type == "canny":
|
203 |
# This should not be called for canny since it's pre-processed
|
204 |
-
processed_video = process_video_for_canny(video)
|
205 |
elif control_type == "depth":
|
206 |
processed_video = process_video_for_depth(video)
|
207 |
elif control_type == "pose":
|
@@ -256,7 +258,7 @@ def generate_video(
|
|
256 |
processed_video = load_video(control_video)
|
257 |
else:
|
258 |
# Fallback to processing on-demand for other control types
|
259 |
-
processed_video = process_video_for_control(reference_video, control_type)
|
260 |
|
261 |
# Convert to tensor
|
262 |
processed_video = read_video(processed_video)
|
@@ -345,8 +347,7 @@ with gr.Blocks() as demo:
|
|
345 |
)
|
346 |
|
347 |
# State variables
|
348 |
-
current_lora_state = gr.State(value=None)
|
349 |
-
processed_video_state = gr.State(value=None) # Store processed video frames
|
350 |
|
351 |
with gr.Row():
|
352 |
with gr.Column(scale=1):
|
@@ -475,7 +476,7 @@ with gr.Blocks() as demo:
|
|
475 |
# Auto-process video when uploaded
|
476 |
reference_video.upload(
|
477 |
fn=process_input_video,
|
478 |
-
inputs=[reference_video],
|
479 |
outputs=[control_video],
|
480 |
show_progress=True
|
481 |
)
|
|
|
111 |
print(f"Error loading {control_type} LoRA: {e}")
|
112 |
raise
|
113 |
|
114 |
+
def process_video_for_canny(video, width, height):
|
115 |
"""
|
116 |
Process video for canny control.
|
117 |
"""
|
118 |
print("Processing video for canny control...")
|
119 |
canny_video = []
|
120 |
+
detect_resolution = video[0].size()
|
121 |
+
|
122 |
for frame in video:
|
123 |
# TODO: change resolution logic
|
124 |
+
canny_video.append(canny_processor(frame, low_threshold=50, high_threshold=200, detect_resolution=detect_resolution, image_resolution=(width, height)))
|
125 |
|
126 |
return canny_video
|
127 |
|
|
|
171 |
return pose_video
|
172 |
|
173 |
@spaces.GPU()
|
174 |
+
def process_input_video(reference_video, width, height):
|
175 |
"""
|
176 |
Process the input video for canny edges and return both processed video and preview.
|
177 |
"""
|
|
|
183 |
video = load_video(reference_video)
|
184 |
|
185 |
# Process video for canny edges
|
186 |
+
processed_video = process_video_for_canny(video, width, height)
|
187 |
|
188 |
# Create a preview video file for display
|
189 |
fps = 24
|
|
|
197 |
print(f"Error processing input video: {e}")
|
198 |
return None
|
199 |
|
200 |
+
def process_video_for_control(reference_video, control_type, width, height):
|
201 |
"""Process video based on the selected control type - now only used for non-canny types"""
|
202 |
video = load_video(reference_video)
|
203 |
|
204 |
if control_type == "canny":
|
205 |
# This should not be called for canny since it's pre-processed
|
206 |
+
processed_video = process_video_for_canny(video, width, height)
|
207 |
elif control_type == "depth":
|
208 |
processed_video = process_video_for_depth(video)
|
209 |
elif control_type == "pose":
|
|
|
258 |
processed_video = load_video(control_video)
|
259 |
else:
|
260 |
# Fallback to processing on-demand for other control types
|
261 |
+
processed_video = process_video_for_control(reference_video, control_type, width, height)
|
262 |
|
263 |
# Convert to tensor
|
264 |
processed_video = read_video(processed_video)
|
|
|
347 |
)
|
348 |
|
349 |
# State variables
|
350 |
+
#current_lora_state = gr.State(value=None)
|
|
|
351 |
|
352 |
with gr.Row():
|
353 |
with gr.Column(scale=1):
|
|
|
476 |
# Auto-process video when uploaded
|
477 |
reference_video.upload(
|
478 |
fn=process_input_video,
|
479 |
+
inputs=[reference_video, width, height],
|
480 |
outputs=[control_video],
|
481 |
show_progress=True
|
482 |
)
|