| import os |
| import sys |
| import subprocess |
| import cv2 |
| import gradio as gr |
| from huggingface_hub import snapshot_download |
|
|
| |
| st.info if "streamlit" in sys.modules else print("Завантаження чекпоінтів FasterLivePortrait...") |
| checkpoint_dir = "./checkpoints" |
| if not os.path.exists(checkpoint_dir): |
| snapshot_download(repo_id="warmshao/FasterLivePortrait", local_dir=checkpoint_dir) |
|
|
| |
| sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), 'src'))) |
|
|
| |
| |
| from src.pipelines.live_portrait_pipeline import LivePortraitPipeline |
|
|
| class LivePortraitAnimator: |
| def __init__(self): |
| |
| self.pipeline = LivePortraitPipeline( |
| config_path="src/config/inference.yaml", |
| checkpoint_dir="./checkpoints", |
| mode="onnx", |
| device_id=0 |
| ) |
|
|
| def animate(self, source_image_path, driving_video_path, stitching=True, relative_motion=True): |
| if not source_image_path or not driving_video_path: |
| return None |
| |
| output_dir = "./animations" |
| os.makedirs(output_dir, exist_ok=True) |
| output_path = os.path.join(output_dir, "liveportrait_result.mp4") |
| |
| |
| self.pipeline.execute( |
| source_image=source_image_path, |
| driving_video=driving_video_path, |
| output_path=output_path, |
| stitching=stitching, |
| relative=relative_motion, |
| flag_crop=True |
| ) |
| return output_path |
|
|
| |
| animator = LivePortraitAnimator() |
|
|
| |
| def create_ui(): |
| with gr.Blocks(title="LivePortrait Studio PRO") as demo: |
| gr.Markdown("# 🎭 LivePortrait Studio — Емоційний Аніматор Обличчя (PRO GPU)") |
| gr.Markdown("Перенесення живої міміки, поглядів та емоцій з будь-якого driving-відео на фото-джерело.") |
| |
| with gr.Row(): |
| with gr.Column(): |
| source_img = gr.Image(label="Завантажте фото обличчя (Source Image)", type="filepath") |
| driving_vid = gr.Video(label="Завантажте емоційне відео (Driving Video)", format="mp4") |
| |
| with gr.Accordion("Просунуті налаштування маскування", open=False): |
| stitching_toggle = gr.Checkbox(label="Безшовне вшивання (Stitching)", value=True) |
| relative_toggle = gr.Checkbox(label="Відносний рух м'язів (Relative Motion)", value=True) |
| |
| submit_btn = gr.Button("🚀 Запустити 3D Анімацію", variant="primary") |
| |
| with gr.Column(): |
| output_vid = gr.Video(label="Результат у кінематографічній якості (MP4)") |
| |
| submit_btn.click( |
| fn=animator.animate, |
| inputs=[source_img, driving_vid, stitching_toggle, relative_toggle], |
| outputs=output_vid |
| ) |
| |
| return demo |
|
|
| if __name__ == "__main__": |
| demo = create_ui() |
| |
| demo.launch(server_name="0.0.0.0", server_port=7860) |