Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -22,6 +22,36 @@ from io import BytesIO
|
|
| 22 |
import json
|
| 23 |
import time # Added for history update delay
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
SYSTEM_PROMPT = '''
|
| 26 |
# Edit Instruction Rewriter
|
| 27 |
You are a professional edit instruction rewriter. Your task is to generate a precise, concise, and visually achievable professional-level edit instruction based on the user-provided instruction and the image to be edited.
|
|
@@ -445,7 +475,8 @@ def infer(
|
|
| 445 |
).images
|
| 446 |
|
| 447 |
# Return images, seed, and make button visible
|
| 448 |
-
return image, seed, gr.update(visible=True)
|
|
|
|
| 449 |
|
| 450 |
# --- Examples and UI Layout ---
|
| 451 |
examples = []
|
|
@@ -544,8 +575,10 @@ with gr.Blocks(css=css) as demo:
|
|
| 544 |
|
| 545 |
with gr.Column():
|
| 546 |
result = gr.Gallery(label="Result", show_label=False, type="pil")
|
| 547 |
-
|
| 548 |
-
|
|
|
|
|
|
|
| 549 |
|
| 550 |
with gr.Row():
|
| 551 |
gr.Markdown("### 📜 History")
|
|
@@ -583,7 +616,8 @@ with gr.Blocks(css=css) as demo:
|
|
| 583 |
width,
|
| 584 |
rewrite_prompt,
|
| 585 |
],
|
| 586 |
-
outputs=[result, seed, use_output_btn],
|
|
|
|
| 587 |
).then(
|
| 588 |
fn=update_history,
|
| 589 |
inputs=[result, history_gallery],
|
|
@@ -615,5 +649,12 @@ with gr.Blocks(css=css) as demo:
|
|
| 615 |
|
| 616 |
input_images.change(fn=suggest_next_scene_prompt, inputs=[input_images], outputs=[prompt])
|
| 617 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 618 |
if __name__ == "__main__":
|
| 619 |
demo.launch()
|
|
|
|
| 22 |
import json
|
| 23 |
import time # Added for history update delay
|
| 24 |
|
| 25 |
+
from gradio_client import Client, handle_file
|
| 26 |
+
import tempfile
|
| 27 |
+
|
| 28 |
+
def turn_into_video(input_images, output_images, prompt):
|
| 29 |
+
"""Calls multimodalart/wan-2-2-first-last-frame space to generate a video."""
|
| 30 |
+
if not input_images or not output_images:
|
| 31 |
+
raise gr.Error("Please generate at least one result first.")
|
| 32 |
+
|
| 33 |
+
# Take the first input and first output frame
|
| 34 |
+
start_img = input_images[0][0] if isinstance(input_images[0], tuple) else input_images[0]
|
| 35 |
+
end_img = output_images[0]
|
| 36 |
+
|
| 37 |
+
# Save them temporarily
|
| 38 |
+
with tempfile.NamedTemporaryFile(suffix=".png", delete=False) as tmp_start, \
|
| 39 |
+
tempfile.NamedTemporaryFile(suffix=".png", delete=False) as tmp_end:
|
| 40 |
+
start_img.save(tmp_start.name)
|
| 41 |
+
end_img.save(tmp_end.name)
|
| 42 |
+
|
| 43 |
+
client = Client("multimodalart/wan-2-2-first-last-frame")
|
| 44 |
+
|
| 45 |
+
# Run inference on the remote space
|
| 46 |
+
result = client.predict(
|
| 47 |
+
start_image_pil={"image": handle_file(tmp_start.name)},
|
| 48 |
+
end_image_pil={"image": handle_file(tmp_end.name)},
|
| 49 |
+
prompt=prompt or "generate smooth cinematic transition",
|
| 50 |
+
api_name="/generate_video" # must match the remote Space’s API function name
|
| 51 |
+
)
|
| 52 |
+
return result, gr.update(visible=True)
|
| 53 |
+
|
| 54 |
+
|
| 55 |
SYSTEM_PROMPT = '''
|
| 56 |
# Edit Instruction Rewriter
|
| 57 |
You are a professional edit instruction rewriter. Your task is to generate a precise, concise, and visually achievable professional-level edit instruction based on the user-provided instruction and the image to be edited.
|
|
|
|
| 475 |
).images
|
| 476 |
|
| 477 |
# Return images, seed, and make button visible
|
| 478 |
+
return image, seed, gr.update(visible=True), gr.update(visible=True)
|
| 479 |
+
|
| 480 |
|
| 481 |
# --- Examples and UI Layout ---
|
| 482 |
examples = []
|
|
|
|
| 575 |
|
| 576 |
with gr.Column():
|
| 577 |
result = gr.Gallery(label="Result", show_label=False, type="pil")
|
| 578 |
+
with gr.Row():
|
| 579 |
+
use_output_btn = gr.Button("↗️ Use as input", variant="secondary", size="sm", visible=False)
|
| 580 |
+
turn_video_btn = gr.Button("🎬 Turn into Video", variant="secondary", size="sm", visible=False)
|
| 581 |
+
output_video = gr.Video(label="Generated Video", autoplay=True, visible=False)
|
| 582 |
|
| 583 |
with gr.Row():
|
| 584 |
gr.Markdown("### 📜 History")
|
|
|
|
| 616 |
width,
|
| 617 |
rewrite_prompt,
|
| 618 |
],
|
| 619 |
+
outputs=[result, seed, use_output_btn, turn_video_btn],
|
| 620 |
+
|
| 621 |
).then(
|
| 622 |
fn=update_history,
|
| 623 |
inputs=[result, history_gallery],
|
|
|
|
| 649 |
|
| 650 |
input_images.change(fn=suggest_next_scene_prompt, inputs=[input_images], outputs=[prompt])
|
| 651 |
|
| 652 |
+
turn_video_btn.click(
|
| 653 |
+
fn=turn_into_video,
|
| 654 |
+
inputs=[input_images, result, prompt],
|
| 655 |
+
outputs=[output_video, output_video],
|
| 656 |
+
)
|
| 657 |
+
|
| 658 |
+
|
| 659 |
if __name__ == "__main__":
|
| 660 |
demo.launch()
|