Spaces:
Running
Running
File size: 2,915 Bytes
52ea648 e425192 52ea648 e425192 52ea648 ab4ea38 52ea648 ab4ea38 e425192 52ea648 e425192 52ea648 e425192 52ea648 e425192 52ea648 e425192 52ea648 e425192 52ea648 ab4ea38 3ee8138 ab4ea38 52ea648 e425192 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
import gradio as gr
from datetime import datetime
from src.face_morp import morph
from src.utils.align_images import align_images
from src.utils.sort_images import sort_images
def transition(image_files, duration, fps, method, align_resize, order_images, guideline):
time = datetime.now().strftime("%d.%m.%Y_%H.%M.%S")
output_name = f"output_{time}_{fps}fps.mp4"
is_dlib = method == "Dlib"
debug_messages = []
print(f"Properties: Duration: {duration}, FPS: {fps}, Method: {method}, Align and Resize: {align_resize}, Order Images: {order_images}, Guideline: {guideline}")
try:
# Sort images by age
if order_images:
image_files = sort_images(image_files)
# Align and resize images
if align_resize:
aligned_dir = "aligned_images"
image_files = align_images(image_files, aligned_dir)
morph(image_files, duration, fps, output_name, guideline, is_dlib)
debug_messages.append("Video generation successful")
return output_name, "\n".join(debug_messages)
except Exception as e:
error_message = f"Error: {str(e)}"
print(error_message)
debug_messages.append(error_message)
return None, "\n".join(debug_messages)
if __name__ == "__main__":
gr.Interface(
fn=transition,
inputs=[
gr.File(file_count="multiple", type="filepath"),
gr.Slider(label="Duration (seconds) between images", minimum=1, maximum=10, step=1, value=3),
gr.Slider(label="Frames per second (fps)", minimum=2, maximum=60, step=1, value=30),
gr.Dropdown(label="Landmarks detection method", choices=["Dlib", "MediaPipe"], value="Dlib"),
gr.Checkbox(label="Align and Resize Images", value=True),
gr.Checkbox(label="Order Images by Age"),
gr.Checkbox(label="Guideline")
],
outputs=[gr.Video(), gr.Textbox(label="Output Message")],
examples=[
[["examples/1.png", "examples/2.png", "examples/3.png"], 3, 30, "Dlib", False, False, False],
[["examples/1.png", "examples/2.png", "examples/3.png"], 5, 30, "MediaPipe", False, False, True],
[["examples/1.jpg", "examples/2.jpg", "examples/3.jpg",
"examples/4.jpg", "examples/5.jpg", "examples/6.jpg", "examples/7.jpg",
"examples/8.jpg", "examples/9.jpg", "examples/10.jpg"], 3, 20, "Dlib", True, True, False],
[["examples/big_1.png", "examples/big_2.png", "examples/big_3.png",
"examples/big_4.png", "examples/big_5.png", "examples/big_6.png"], 3, 30, "Dlib", False, False, False]
],
title="Face Morphing",
description="Upload multiple images containing faces to create a transition video between them."
).launch(share=False)
|