File size: 1,541 Bytes
ef0719a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import cv2
import numpy as np
import os
from moviepy.editor import ImageSequenceClip

def generate_video(photo, audio):
    # Save temporary files
    photo_path = "user_photo.jpg"
    audio_path = "user_audio.wav"
    cv2.imwrite(photo_path, photo)
    audio.write_audiofile(audio_path)
    
    # Create simple talking animation (face stays static)
    frames = []
    for i in range(30):  # 1 second video at 30fps
        frame = photo.copy()
        
        # Add simple mouth movement (sin wave)
        y_offset = int(10 * np.sin(i/3))
        cv2.rectangle(frame, 
                     (100, 150 + y_offset), 
                     (200, 250 - y_offset), 
                     (0, 0, 0), -1)
        
        frames.append(frame)
    
    # Save video
    video_path = "output.mp4"
    clip = ImageSequenceClip([cv2.cvtColor(f, cv2.COLOR_BGR2RGB) for f in frames], 
                           fps=30)
    clip.write_videofile(video_path, codec="libx264", audio=audio_path)
    
    return video_path

# Gradio Interface
with gr.Blocks() as demo:
    gr.Markdown("## 🎥 Video Resume Generator")
    
    with gr.Row():
        photo_input = gr.Image(label="Upload Your Photo", type="numpy")
        audio_input = gr.Audio(label="Record/Upload Audio", type="filepath")
    
    generate_btn = gr.Button("Generate Video")
    video_output = gr.Video(label="Result")
    
    generate_btn.click(
        fn=generate_video,
        inputs=[photo_input, audio_input],
        outputs=video_output
    )

demo.launch()