Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -61,47 +61,47 @@ optimize_pipeline_(
|
|
| 61 |
MAX_SEED = np.iinfo(np.int32).max
|
| 62 |
|
| 63 |
|
| 64 |
-
def _generate_video_segment(
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
) -> str:
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
|
| 74 |
-
|
| 75 |
-
|
| 76 |
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
|
| 106 |
|
| 107 |
def build_camera_prompt(
|
|
@@ -266,58 +266,58 @@ def infer_camera_edit(
|
|
| 266 |
return result, seed, prompt
|
| 267 |
|
| 268 |
|
| 269 |
-
def create_video_between_images(
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
) -> str:
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
|
| 322 |
|
| 323 |
# --- UI ---
|
|
@@ -622,7 +622,7 @@ with gr.Blocks() as demo:
|
|
| 622 |
|
| 623 |
# run_event.then(lambda img, *_: img, inputs=[result], outputs=[prev_output])
|
| 624 |
|
| 625 |
-
gr.api(infer_camera_edit, api_name="infer_edit_camera_angles")
|
| 626 |
# gr.api(create_video_between_images, api_name="create_video_between_images")
|
| 627 |
|
| 628 |
-
demo.launch(mcp_server=True
|
|
|
|
| 61 |
MAX_SEED = np.iinfo(np.int32).max
|
| 62 |
|
| 63 |
|
| 64 |
+
# def _generate_video_segment(
|
| 65 |
+
# input_image_path: str,
|
| 66 |
+
# output_image_path: str,
|
| 67 |
+
# prompt: str,
|
| 68 |
+
# request: gr.Request
|
| 69 |
+
# ) -> str:
|
| 70 |
+
# """
|
| 71 |
+
# Generate a single video segment between two frames by calling an external
|
| 72 |
+
# Wan 2.2 image-to-video service hosted on Hugging Face Spaces.
|
| 73 |
|
| 74 |
+
# This helper function is used internally when the user asks to create
|
| 75 |
+
# a video between the input and output images.
|
| 76 |
|
| 77 |
+
# Args:
|
| 78 |
+
# input_image_path (str):
|
| 79 |
+
# Path to the starting frame image on disk.
|
| 80 |
+
# output_image_path (str):
|
| 81 |
+
# Path to the ending frame image on disk.
|
| 82 |
+
# prompt (str):
|
| 83 |
+
# Text prompt describing the camera movement / transition.
|
| 84 |
+
# request (gr.Request):
|
| 85 |
+
# Gradio request object, used here to forward the `x-ip-token`
|
| 86 |
+
# header to the downstream Space for authentication/rate limiting.
|
| 87 |
|
| 88 |
+
# Returns:
|
| 89 |
+
# str:
|
| 90 |
+
# A string returned by the external service, usually a URL or path
|
| 91 |
+
# to the generated video.
|
| 92 |
+
# """
|
| 93 |
+
# x_ip_token = request.headers['x-ip-token']
|
| 94 |
+
# video_client = Client(
|
| 95 |
+
# "multimodalart/wan-2-2-first-last-frame",
|
| 96 |
+
# headers={"x-ip-token": x_ip_token}
|
| 97 |
+
# )
|
| 98 |
+
# result = video_client.predict(
|
| 99 |
+
# start_image_pil=handle_file(input_image_path),
|
| 100 |
+
# end_image_pil=handle_file(output_image_path),
|
| 101 |
+
# prompt=prompt,
|
| 102 |
+
# api_name="/generate_video",
|
| 103 |
+
# )
|
| 104 |
+
# return result[0]["video"]
|
| 105 |
|
| 106 |
|
| 107 |
def build_camera_prompt(
|
|
|
|
| 266 |
return result, seed, prompt
|
| 267 |
|
| 268 |
|
| 269 |
+
# def create_video_between_images(
|
| 270 |
+
# input_image: Optional[Image.Image],
|
| 271 |
+
# output_image: Optional[np.ndarray],
|
| 272 |
+
# prompt: str,
|
| 273 |
+
# request: gr.Request,
|
| 274 |
+
# api_name=False
|
| 275 |
+
# ) -> str:
|
| 276 |
+
# """
|
| 277 |
+
# Create a short transition video between the input and output images via the
|
| 278 |
+
# Wan 2.2 first-last-frame Space.
|
| 279 |
|
| 280 |
+
# Args:
|
| 281 |
+
# input_image (PIL.Image.Image | None):
|
| 282 |
+
# Starting frame image (the original / previous view).
|
| 283 |
+
# output_image (numpy.ndarray | None):
|
| 284 |
+
# Ending frame image - the output image with the the edited camera angles.
|
| 285 |
+
# prompt (str):
|
| 286 |
+
# The camera movement prompt used to describe the transition.
|
| 287 |
+
# request (gr.Request):
|
| 288 |
+
# Gradio request object, used to forward the `x-ip-token` header
|
| 289 |
+
# to the video generation app.
|
| 290 |
|
| 291 |
+
# Returns:
|
| 292 |
+
# str:
|
| 293 |
+
# a path pointing to the generated video.
|
| 294 |
|
| 295 |
+
# Raises:
|
| 296 |
+
# gr.Error:
|
| 297 |
+
# If either image is missing or if the video generation fails.
|
| 298 |
+
# """
|
| 299 |
+
# if input_image is None or output_image is None:
|
| 300 |
+
# raise gr.Error("Both input and output images are required to create a video.")
|
| 301 |
+
|
| 302 |
+
# try:
|
| 303 |
+
# with tempfile.NamedTemporaryFile(delete=False, suffix=".png") as tmp:
|
| 304 |
+
# input_image.save(tmp.name)
|
| 305 |
+
# input_image_path = tmp.name
|
| 306 |
+
|
| 307 |
+
# output_pil = Image.fromarray(output_image.astype('uint8'))
|
| 308 |
+
# with tempfile.NamedTemporaryFile(delete=False, suffix=".png") as tmp:
|
| 309 |
+
# output_pil.save(tmp.name)
|
| 310 |
+
# output_image_path = tmp.name
|
| 311 |
+
|
| 312 |
+
# video_path = _generate_video_segment(
|
| 313 |
+
# input_image_path,
|
| 314 |
+
# output_image_path,
|
| 315 |
+
# prompt if prompt else "Camera movement transformation",
|
| 316 |
+
# request
|
| 317 |
+
# )
|
| 318 |
+
# return video_path
|
| 319 |
+
# except Exception as e:
|
| 320 |
+
# raise gr.Error(f"Video generation failed: {e}")
|
| 321 |
|
| 322 |
|
| 323 |
# --- UI ---
|
|
|
|
| 622 |
|
| 623 |
# run_event.then(lambda img, *_: img, inputs=[result], outputs=[prev_output])
|
| 624 |
|
| 625 |
+
# gr.api(infer_camera_edit, api_name="infer_edit_camera_angles")
|
| 626 |
# gr.api(create_video_between_images, api_name="create_video_between_images")
|
| 627 |
|
| 628 |
+
demo.launch(mcp_server=True)
|