Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -194,11 +194,17 @@ def load_scheduler(scheduler_dir):
|
|
| 194 |
scheduler_config = RectifiedFlowScheduler.load_config(scheduler_config_path)
|
| 195 |
return RectifiedFlowScheduler.from_config(scheduler_config)
|
| 196 |
|
| 197 |
-
# Helper function for image processing
|
| 198 |
def center_crop_and_resize(frame, target_height, target_width):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 199 |
h, w, _ = frame.shape
|
| 200 |
aspect_ratio_target = target_width / target_height
|
| 201 |
aspect_ratio_frame = w / h
|
|
|
|
| 202 |
if aspect_ratio_frame > aspect_ratio_target:
|
| 203 |
new_width = int(h * aspect_ratio_target)
|
| 204 |
x_start = (w - new_width) // 2
|
|
@@ -207,8 +213,11 @@ def center_crop_and_resize(frame, target_height, target_width):
|
|
| 207 |
new_height = int(w / aspect_ratio_target)
|
| 208 |
y_start = (h - new_height) // 2
|
| 209 |
frame_cropped = frame[y_start : y_start + new_height, :]
|
|
|
|
| 210 |
frame_resized = cv2.resize(frame_cropped, (target_width, target_height))
|
| 211 |
return frame_resized
|
|
|
|
|
|
|
| 212 |
|
| 213 |
def load_image_to_tensor_with_resize(image_path, target_height=512, target_width=768):
|
| 214 |
image = Image.open(image_path).convert("RGB")
|
|
@@ -381,6 +390,11 @@ def generate_video_from_image(
|
|
| 381 |
num_frames,
|
| 382 |
progress=gr.Progress(),
|
| 383 |
):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 384 |
if not image_path:
|
| 385 |
raise gr.Error("입력 이미지를 제공해주세요.", duration=5)
|
| 386 |
|
|
|
|
| 194 |
scheduler_config = RectifiedFlowScheduler.load_config(scheduler_config_path)
|
| 195 |
return RectifiedFlowScheduler.from_config(scheduler_config)
|
| 196 |
|
|
|
|
| 197 |
def center_crop_and_resize(frame, target_height, target_width):
|
| 198 |
+
# State 객체인 경우 value 값을 가져옴
|
| 199 |
+
if isinstance(target_height, gr.State):
|
| 200 |
+
target_height = target_height.value
|
| 201 |
+
if isinstance(target_width, gr.State):
|
| 202 |
+
target_width = target_width.value
|
| 203 |
+
|
| 204 |
h, w, _ = frame.shape
|
| 205 |
aspect_ratio_target = target_width / target_height
|
| 206 |
aspect_ratio_frame = w / h
|
| 207 |
+
|
| 208 |
if aspect_ratio_frame > aspect_ratio_target:
|
| 209 |
new_width = int(h * aspect_ratio_target)
|
| 210 |
x_start = (w - new_width) // 2
|
|
|
|
| 213 |
new_height = int(w / aspect_ratio_target)
|
| 214 |
y_start = (h - new_height) // 2
|
| 215 |
frame_cropped = frame[y_start : y_start + new_height, :]
|
| 216 |
+
|
| 217 |
frame_resized = cv2.resize(frame_cropped, (target_width, target_height))
|
| 218 |
return frame_resized
|
| 219 |
+
|
| 220 |
+
|
| 221 |
|
| 222 |
def load_image_to_tensor_with_resize(image_path, target_height=512, target_width=768):
|
| 223 |
image = Image.open(image_path).convert("RGB")
|
|
|
|
| 390 |
num_frames,
|
| 391 |
progress=gr.Progress(),
|
| 392 |
):
|
| 393 |
+
# State 객체의 value 값을 가져옴
|
| 394 |
+
height = height.value if isinstance(height, gr.State) else height
|
| 395 |
+
width = width.value if isinstance(width, gr.State) else width
|
| 396 |
+
num_frames = num_frames.value if isinstance(num_frames, gr.State) else num_frames
|
| 397 |
+
|
| 398 |
if not image_path:
|
| 399 |
raise gr.Error("입력 이미지를 제공해주세요.", duration=5)
|
| 400 |
|