Spaces:
Running
Running
KiloClaw commited on
Commit ·
33e9498
1
Parent(s): bec67a2
Fresh deploy: gradio 3.50.2, Docker, CPU mode
Browse files- Dockerfile +32 -0
- README.md +6 -4
- app.py +60 -0
Dockerfile
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.10-slim
|
| 2 |
+
|
| 3 |
+
RUN apt-get update && apt-get install -y \
|
| 4 |
+
git ffmpeg libgl1 libglib2.0-0 curl \
|
| 5 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 6 |
+
|
| 7 |
+
WORKDIR /app
|
| 8 |
+
|
| 9 |
+
# Install PyTorch CPU
|
| 10 |
+
RUN pip install --no-cache-dir \
|
| 11 |
+
torch==2.3.0+cpu torchvision==0.18.0+cpu torchaudio==2.3.0+cpu \
|
| 12 |
+
--index-url https://download.pytorch.org/whl/cpu
|
| 13 |
+
|
| 14 |
+
# Install gradio 3.x (stable, no schema bug)
|
| 15 |
+
RUN pip install --no-cache-dir \
|
| 16 |
+
"gradio==3.50.2" \
|
| 17 |
+
"gradio_client==0.6.1" \
|
| 18 |
+
huggingface_hub \
|
| 19 |
+
omegaconf einops tqdm rich tyro \
|
| 20 |
+
"imageio[ffmpeg]" opencv-python-headless \
|
| 21 |
+
scikit-image lmdb safetensors \
|
| 22 |
+
diffusers transformers
|
| 23 |
+
|
| 24 |
+
# Clone and install LivePortrait
|
| 25 |
+
RUN git clone --depth=1 https://github.com/KlingAIResearch/LivePortrait.git /app/LivePortrait && \
|
| 26 |
+
pip install --no-cache-dir -r /app/LivePortrait/requirements.txt 2>/dev/null || true
|
| 27 |
+
|
| 28 |
+
COPY app.py /app/app.py
|
| 29 |
+
|
| 30 |
+
EXPOSE 7860
|
| 31 |
+
|
| 32 |
+
CMD ["python", "/app/app.py"]
|
README.md
CHANGED
|
@@ -1,10 +1,12 @@
|
|
| 1 |
---
|
| 2 |
title: LivePortrait
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: docker
|
| 7 |
pinned: false
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
| 1 |
---
|
| 2 |
title: LivePortrait
|
| 3 |
+
emoji: 🎭
|
| 4 |
+
colorFrom: purple
|
| 5 |
+
colorTo: blue
|
| 6 |
sdk: docker
|
| 7 |
pinned: false
|
| 8 |
+
license: mit
|
| 9 |
---
|
| 10 |
|
| 11 |
+
# LivePortrait
|
| 12 |
+
Bring portraits to life!
|
app.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
import os
|
| 3 |
+
import tempfile
|
| 4 |
+
|
| 5 |
+
os.environ["CUDA_VISIBLE_DEVICES"] = ""
|
| 6 |
+
|
| 7 |
+
from huggingface_hub import snapshot_download
|
| 8 |
+
|
| 9 |
+
weights_dir = "/app/LivePortrait/pretrained_weights"
|
| 10 |
+
if not os.path.exists(os.path.join(weights_dir, "appearance_feature_extractor.safetensors")):
|
| 11 |
+
print("Downloading model weights (~2GB)...")
|
| 12 |
+
snapshot_download(
|
| 13 |
+
repo_id="KlingTeam/LivePortrait",
|
| 14 |
+
local_dir=weights_dir,
|
| 15 |
+
ignore_patterns=["*.git*", "README.md", "docs/*"],
|
| 16 |
+
)
|
| 17 |
+
print("Weights ready ✓")
|
| 18 |
+
|
| 19 |
+
sys.path.insert(0, "/app/LivePortrait")
|
| 20 |
+
os.chdir("/app/LivePortrait")
|
| 21 |
+
|
| 22 |
+
from src.config.argument_config import ArgumentConfig
|
| 23 |
+
from src.config.inference_config import InferenceConfig
|
| 24 |
+
from src.config.crop_config import CropConfig
|
| 25 |
+
from src.live_portrait_pipeline import LivePortraitPipeline
|
| 26 |
+
|
| 27 |
+
infer_cfg = InferenceConfig()
|
| 28 |
+
infer_cfg.flag_force_cpu = True
|
| 29 |
+
|
| 30 |
+
pipeline = LivePortraitPipeline(
|
| 31 |
+
inference_cfg=infer_cfg,
|
| 32 |
+
crop_cfg=CropConfig(),
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
def animate(source_image, driving_video):
|
| 36 |
+
if source_image is None or driving_video is None:
|
| 37 |
+
return None
|
| 38 |
+
out_dir = tempfile.mkdtemp()
|
| 39 |
+
args = ArgumentConfig(
|
| 40 |
+
source=source_image,
|
| 41 |
+
driving=driving_video,
|
| 42 |
+
output_dir=out_dir,
|
| 43 |
+
)
|
| 44 |
+
wfp, _ = pipeline.execute(args)
|
| 45 |
+
return wfp
|
| 46 |
+
|
| 47 |
+
import gradio as gr
|
| 48 |
+
|
| 49 |
+
with gr.Blocks(title="LivePortrait 🎭") as demo:
|
| 50 |
+
gr.Markdown("# 🎭 LivePortrait\nAnimate any portrait with a driving video.\n> ⚠️ Running on CPU — takes a few minutes.")
|
| 51 |
+
with gr.Row():
|
| 52 |
+
with gr.Column():
|
| 53 |
+
src_image = gr.Image(label="Source Portrait", type="filepath")
|
| 54 |
+
drv_video = gr.Video(label="Driving Video")
|
| 55 |
+
btn = gr.Button("✨ Animate!", variant="primary")
|
| 56 |
+
with gr.Column():
|
| 57 |
+
out_video = gr.Video(label="Result")
|
| 58 |
+
btn.click(fn=animate, inputs=[src_image, drv_video], outputs=[out_video])
|
| 59 |
+
|
| 60 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|