File size: 1,824 Bytes
50e993b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import os
import shutil
import glob

# ------------------------------
# 1. LIA MODEL RUN FUNCTION
# ------------------------------
def run_lia_model(source_image_path, driving_video_path):
    if source_image_path is None or driving_video_path is None:
        return None

    # Clean names for LIA expected input paths
    source_clean = "source_image.jpg"
    driving_clean = "driving_video.mp4"

    # Remove previous files if they exist
    if os.path.exists(source_clean): os.remove(source_clean)
    if os.path.exists(driving_clean): os.remove(driving_clean)

    shutil.copy(source_image_path, source_clean)
    shutil.copy(driving_video_path, driving_clean)

    print("🚀 Running LIA model...")

    # Run the LIA script
    exit_code = os.system(
        f'python run_demo.py --model vox --source_path {source_clean} --driving_path {driving_clean}'
    )

    if exit_code != 0:
        print("❌ Error running run_demo.py")
        return None

    # Look for latest result video
    results = glob.glob('res/vox/*.mp4')
    if not results:
        print("❌ No output video found.")
        return None

    latest = max(results, key=os.path.getctime)
    print(f"🎉 Returning output: {latest}")
    return latest


# ------------------------------
# 2. GRADIO INTERFACE
# ------------------------------
interface = gr.Interface(
    fn=run_lia_model,
    inputs=[
        gr.Image(type="filepath", label="Source Image (Face Image)"),
        gr.Video(label="Driving Video (Motion Video)")
    ],
    outputs=gr.Video(label="Generated Animation"),
    title="LIA - Latent Image Animator",
    description="Upload a face image and driving video to generate an animation."
)

if __name__ == "__main__":
    interface.launch()