Face-Morphing / app.py
Robys01's picture
Added Align and Order Options
e425192
raw
history blame
2.17 kB
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 = []
try:
# Align and resize images
if align_resize:
aligned_dir = "aligned_images"
image_files = align_images(image_files, aligned_dir)
# Sort images by age
if order_images:
image_files = sort_images(image_files)
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]
],
title="Face Morphing",
description="Upload multiple images containing faces to create a transition video between them."
).launch(share=False)