Spaces:
Running
Running
File size: 2,170 Bytes
52ea648 e425192 52ea648 e425192 52ea648 e425192 52ea648 e425192 52ea648 e425192 52ea648 e425192 52ea648 e425192 52ea648 e425192 52ea648 e425192 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 |
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)
|