File size: 1,454 Bytes
4fa3412
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from flask import Flask, request, send_file
import os
import subprocess
from werkzeug.utils import secure_filename

app = Flask(__name__)
UPLOAD_FOLDER = "uploads"
OUTPUT_FOLDER = "outputs"
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
os.makedirs(OUTPUT_FOLDER, exist_ok=True)

@app.route("/sync", methods=["POST"])
def sync_lips():
    if "video" not in request.files or "audio" not in request.files:
        return {"error": "Missing video or audio file"}, 400
    
    video = request.files["video"]
    audio = request.files["audio"]
    
    video_filename = secure_filename(video.filename)
    audio_filename = secure_filename(audio.filename)
    
    video_path = os.path.join(UPLOAD_FOLDER, video_filename)
    audio_path = os.path.join(UPLOAD_FOLDER, audio_filename)
    output_path = os.path.join(OUTPUT_FOLDER, f"synced_{video_filename}")
    
    video.save(video_path)
    audio.save(audio_path)
    
    # Run LatentSync processing
    command = ["python", "scripts/inference.py", "--video", video_path, "--audio", audio_path, "--output", output_path]
    result = subprocess.run(command, capture_output=True, text=True)
    
    if result.returncode != 0:
        return {"error": "Lip sync processing failed", "details": result.stderr}, 500
    
    return send_file(output_path, mimetype="video/mp4", as_attachment=True)

if __name__ == "__main__":
    app.run(debug=True, host="0.0.0.0", port=5000)