SadTalker-API / app.py
akin23's picture
Update app.py
0f6af18 verified
raw
history blame
1.74 kB
import gradio as gr
import subprocess
import os
from datetime import datetime
# 🔧 Model parçalarını birleştirme fonksiyonu
def merge_model_parts():
parts = [
"checkpoints/facevid2vid_00189-model_aa",
"checkpoints/facevid2vid_00189-model_bb",
"checkpoints/facevid2vid_00189-model_cc",
"checkpoints/facevid2vid_00189-model_dd",
"checkpoints/facevid2vid_00189-model_ee"
]
output_file = "checkpoints/facevid2vid_00189-model.pth.tar"
os.makedirs("checkpoints", exist_ok=True) # <-- klasörü oluştur
if not os.path.exists(output_file):
with open(output_file, "wb") as out:
for part in parts:
with open(part, "rb") as p:
out.write(p.read())
print("✅ Model parçaları birleştirildi.")
else:
print("🟡 Birleştirilmiş dosya zaten var.")
# 🔥 Birleştirme işlemini başta yap
merge_model_parts()
# 🔁 Ana video üretim fonksiyonu
def generate_video(source_image, driven_audio):
output_dir = "results"
os.makedirs(output_dir, exist_ok=True)
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
result_path = f"{output_dir}/video_{timestamp}.mp4"
cmd = f"python inference.py --driven_audio {driven_audio} --source_image {source_image} --result_dir {output_dir} --enhancer gfpgan --pose_style 45 --still --preprocess full"
subprocess.run(cmd, shell=True)
return result_path
# 🎛️ Gradio arayüzü
demo = gr.Interface(
fn=generate_video,
inputs=[
gr.Image(type="filepath", label="Source Image"),
gr.Audio(type="filepath", label="Driven Audio")
],
outputs=gr.Video(label="Generated Video")
)
# 🚀 Başlat
demo.launch()