File size: 1,634 Bytes
52ea648
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from datetime import datetime

from src.face_morp import morph

def transition(image_files, duration, fps, method, 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:
        # Apelează funcția morph și prinde mesajele de debug
        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)}"
        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=1, maximum=60, step=1, value=30),
            gr.Dropdown(label="Landmarks detection method", choices=["Dlib", "MediaPipe"], value="Dlib"),
            gr.Checkbox(label="Guideline")
        ],
        outputs=[gr.Video(), gr.Textbox(label="Debug Messages")],
        examples=[
            [["examples/1.png", "examples/2.png", "examples/3.png"], 3, 30, "Dlib", False]
        ],
        title="Face Morphing",
        description="Upload multiple images containing faces to create a transition video between them."
    ).launch()