Spaces:
Running
Running
Create modules/lut.py
#2
by Jacky2305 - opened
- .gitattributes +35 -0
- Dockerfile +4 -28
- README.md +5 -7
- __pycache__/app.cpython-310.pyc +0 -0
- app.py +128 -101
- modules/lut.py +47 -0
- requirements.txt +8 -18
.gitattributes
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
Dockerfile
CHANGED
|
@@ -1,30 +1,6 @@
|
|
| 1 |
FROM python:3.10-slim
|
| 2 |
-
|
|
|
|
| 3 |
WORKDIR /app
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 7 |
-
libgl1 libglib2.0-0 libgomp1 unzip curl git g++ \
|
| 8 |
-
&& rm -rf /var/lib/apt/lists/*
|
| 9 |
-
|
| 10 |
-
# 構建期下載 insightface antelopev2 人臉模型包(運行期不再聯網,避免 FaceAnalysis assertion)
|
| 11 |
-
RUN mkdir -p /app/models && \
|
| 12 |
-
curl -sL -o /tmp/antelopev2.zip \
|
| 13 |
-
https://github.com/deepinsight/insightface/releases/download/v0.7/antelopev2.zip && \
|
| 14 |
-
unzip -q /tmp/antelopev2.zip -d /app/models/ && \
|
| 15 |
-
rm /tmp/antelopev2.zip && \
|
| 16 |
-
ls /app/models/antelopev2
|
| 17 |
-
|
| 18 |
-
# CPU 版 torch:用 extra-index-url 同時保留 PyPI,否則依賴包解析會炸
|
| 19 |
-
RUN pip install --no-cache-dir torch==2.4.1 --extra-index-url https://download.pytorch.org/whl/cpu
|
| 20 |
-
|
| 21 |
-
COPY requirements.txt .
|
| 22 |
-
RUN pip install --no-cache-dir -r requirements.txt
|
| 23 |
-
|
| 24 |
-
COPY . .
|
| 25 |
-
|
| 26 |
-
EXPOSE 7860
|
| 27 |
-
ENV GRADIO_SERVER_NAME=0.0.0.0
|
| 28 |
-
ENV GRADIO_SERVER_PORT=7860
|
| 29 |
-
|
| 30 |
-
CMD ["python", "app.py"]
|
|
|
|
| 1 |
FROM python:3.10-slim
|
| 2 |
+
RUN apt-get update && apt-get install -y ffmpeg fonts-noto-cjk
|
| 3 |
+
COPY . /app
|
| 4 |
WORKDIR /app
|
| 5 |
+
RUN pip install -r requirements.txt
|
| 6 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
README.md
CHANGED
|
@@ -1,12 +1,10 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: docker
|
| 7 |
-
app_port: 7860
|
| 8 |
pinned: false
|
| 9 |
-
license: apache-2.0
|
| 10 |
---
|
| 11 |
|
| 12 |
-
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Video Gen
|
| 3 |
+
emoji: 📊
|
| 4 |
+
colorFrom: green
|
| 5 |
+
colorTo: red
|
| 6 |
sdk: docker
|
|
|
|
| 7 |
pinned: false
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
__pycache__/app.cpython-310.pyc
DELETED
|
Binary file (3.75 kB)
|
|
|
app.py
CHANGED
|
@@ -1,114 +1,141 @@
|
|
| 1 |
-
import
|
|
|
|
|
|
|
|
|
|
| 2 |
import traceback
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
import
|
| 5 |
-
|
| 6 |
-
import
|
| 7 |
-
import
|
| 8 |
-
from insightface.app import FaceAnalysis
|
| 9 |
-
from diffusers import StableDiffusionPipeline
|
| 10 |
-
from ip_adapter.ip_adapter_faceid import IPAdapterFaceIDPlus
|
| 11 |
-
from huggingface_hub import hf_hub_download
|
| 12 |
|
| 13 |
-
|
| 14 |
-
device = "cpu"
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
)
|
| 30 |
-
image_encoder_path = "laion/CLIP-ViT-H-14-laion2B-s32B-b79K"
|
| 31 |
-
# 官方库默认 torch_dtype=float16;CPU 上 pipe 是 fp32,必须显式传 float32,
|
| 32 |
-
# 否则 image_proj_model / attn processors 是 Half,和 fp32 的 embeds 冲突会炸 dtype 错误
|
| 33 |
-
ip_model = IPAdapterFaceIDPlus(
|
| 34 |
-
pipe, image_encoder_path, ip_ckpt, device, torch_dtype=torch.float32
|
| 35 |
-
)
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
try:
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
-
|
| 55 |
-
if
|
| 56 |
-
|
|
|
|
|
|
|
| 57 |
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
|
|
|
|
|
|
|
| 79 |
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
"SD1.5 + IP-Adapter FaceID-PlusV2(带 CLIP),免费 cpu-basic,512×512 约几分钟/张。"
|
| 85 |
-
)
|
| 86 |
-
with gr.Row():
|
| 87 |
-
with gr.Column():
|
| 88 |
-
face = gr.Image(label="参考人脸(必传,正脸最佳)", type="pil")
|
| 89 |
-
prompt = gr.Textbox(
|
| 90 |
-
label="Prompt",
|
| 91 |
-
value="a person smiling, natural skin tone, cinematic lighting, detailed face, 8k, photorealistic",
|
| 92 |
-
)
|
| 93 |
-
neg = gr.Textbox(
|
| 94 |
-
label="Negative prompt",
|
| 95 |
-
value="(lowres, low quality, worst quality), blurry, deformed, watermark, text, ugly, oversaturated, color noise, glitch, disfigured",
|
| 96 |
-
)
|
| 97 |
-
with gr.Row():
|
| 98 |
-
seed = gr.Number(label="Seed(-1 = 随机)", value=-1)
|
| 99 |
-
steps = gr.Slider(15, 50, 30, step=1, label="采样步数")
|
| 100 |
-
with gr.Row():
|
| 101 |
-
guidance = gr.Slider(1, 12, 5.0, step=0.5, label="CFG(建议 4–6)")
|
| 102 |
-
ip_scale = gr.Slider(0, 1.0, 0.5, step=0.05, label="锁脸强度 scale(建议 0.4–0.6)")
|
| 103 |
-
btn = gr.Button("生成(CPU 较慢,请耐心等待)", variant="primary")
|
| 104 |
-
with gr.Column():
|
| 105 |
-
out = gr.Image(label="生成结果")
|
| 106 |
-
out_seed = gr.Number(label="实际使用的 seed")
|
| 107 |
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
|
| 114 |
-
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, File, UploadFile, HTTPException, Form
|
| 2 |
+
from fastapi.responses import Response
|
| 3 |
+
import tempfile
|
| 4 |
+
import os
|
| 5 |
import traceback
|
| 6 |
+
import sys
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
from typing import Optional, List
|
| 9 |
|
| 10 |
+
from modules.video_processor import generate_video
|
| 11 |
+
from modules.lut import LUTS
|
| 12 |
+
from modules.particles import EFFECTS
|
| 13 |
+
from modules.titles import TITLE_STYLES, TITLE_ANIMATIONS, TITLE_POSITIONS
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
+
app = FastAPI(title="Video Generator with Effects API")
|
|
|
|
| 16 |
|
| 17 |
+
@app.get("/")
|
| 18 |
+
async def root():
|
| 19 |
+
return {
|
| 20 |
+
"message": "Video Generator API",
|
| 21 |
+
"effects": EFFECTS,
|
| 22 |
+
"luts": {k: v["name"] for k, v in LUTS.items()},
|
| 23 |
+
"title_styles": TITLE_STYLES,
|
| 24 |
+
"title_animations": TITLE_ANIMATIONS,
|
| 25 |
+
"title_positions": TITLE_POSITIONS,
|
| 26 |
+
"features": ["ken_burns", "typewriter", "cinemascope", "title", "video_input"],
|
| 27 |
+
}
|
| 28 |
|
| 29 |
+
@app.get("/health")
|
| 30 |
+
async def health():
|
| 31 |
+
return {"status": "healthy"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
+
@app.post("/generate")
|
| 34 |
+
async def generate(
|
| 35 |
+
images: List[UploadFile] = File(None),
|
| 36 |
+
video: UploadFile = File(None),
|
| 37 |
+
audio: UploadFile = File(...),
|
| 38 |
+
srt_text: str = Form(""),
|
| 39 |
+
bgm: Optional[UploadFile] = File(None),
|
| 40 |
+
effect: str = Form("snow"),
|
| 41 |
+
lut: str = Form("none"),
|
| 42 |
+
ken_burns: bool = Form(False),
|
| 43 |
+
typewriter: bool = Form(False),
|
| 44 |
+
cinemascope: bool = Form(False),
|
| 45 |
+
title_text: str = Form(""),
|
| 46 |
+
title_style: str = Form("3d"),
|
| 47 |
+
title_color: str = Form("white"),
|
| 48 |
+
title_animation: str = Form("fade_in"),
|
| 49 |
+
title_duration: float = Form(4.0),
|
| 50 |
+
title_position: str = Form("center"),
|
| 51 |
+
title_start: float = Form(0.0),
|
| 52 |
+
title_font_size: int = Form(0),
|
| 53 |
+
typewriter_font_size: int = Form(0),
|
| 54 |
+
typewriter_color: str = Form("white"),
|
| 55 |
+
subtitle_color: str = Form("white"),
|
| 56 |
+
subtitle_effect: str = Form("none"),
|
| 57 |
+
fps: int = Form(25),
|
| 58 |
+
):
|
| 59 |
+
# 验证
|
| 60 |
+
if not images and not video:
|
| 61 |
+
raise HTTPException(400, "必须提供 images 或 video 中的一个")
|
| 62 |
+
if images and video:
|
| 63 |
+
raise HTTPException(400, "不能同时提供 images 和 video")
|
| 64 |
+
|
| 65 |
+
# 创建临时目录
|
| 66 |
+
tmp_dir = tempfile.mkdtemp()
|
| 67 |
try:
|
| 68 |
+
# 保存文件
|
| 69 |
+
image_paths = None
|
| 70 |
+
video_path = None
|
| 71 |
+
if images:
|
| 72 |
+
image_paths = []
|
| 73 |
+
for i, img in enumerate(images):
|
| 74 |
+
suffix = Path(img.filename).suffix if img.filename else ".jpg"
|
| 75 |
+
path = os.path.join(tmp_dir, f"image_{i}{suffix}")
|
| 76 |
+
with open(path, "wb") as f:
|
| 77 |
+
f.write(await img.read())
|
| 78 |
+
image_paths.append(path)
|
| 79 |
+
elif video:
|
| 80 |
+
suffix = Path(video.filename).suffix if video.filename else ".mp4"
|
| 81 |
+
video_path = os.path.join(tmp_dir, f"video{suffix}")
|
| 82 |
+
with open(video_path, "wb") as f:
|
| 83 |
+
f.write(await video.read())
|
| 84 |
+
|
| 85 |
+
audio_path = os.path.join(tmp_dir, "audio" + (Path(audio.filename).suffix or ".wav"))
|
| 86 |
+
with open(audio_path, "wb") as f:
|
| 87 |
+
f.write(await audio.read())
|
| 88 |
|
| 89 |
+
bgm_path = None
|
| 90 |
+
if bgm:
|
| 91 |
+
bgm_path = os.path.join(tmp_dir, "bgm" + (Path(bgm.filename).suffix or ".mp3"))
|
| 92 |
+
with open(bgm_path, "wb") as f:
|
| 93 |
+
f.write(await bgm.read())
|
| 94 |
|
| 95 |
+
output_path = os.path.join(tmp_dir, "output.mp4")
|
| 96 |
+
|
| 97 |
+
# 调用主合成函数
|
| 98 |
+
generate_video(
|
| 99 |
+
image_paths=image_paths,
|
| 100 |
+
video_path=video_path,
|
| 101 |
+
audio_path=audio_path,
|
| 102 |
+
srt_text=srt_text,
|
| 103 |
+
bgm_path=bgm_path,
|
| 104 |
+
effect=effect,
|
| 105 |
+
output_path=output_path,
|
| 106 |
+
lut=lut,
|
| 107 |
+
ken_burns=ken_burns,
|
| 108 |
+
typewriter=typewriter,
|
| 109 |
+
cinemascope=cinemascope,
|
| 110 |
+
title_text=title_text,
|
| 111 |
+
title_style=title_style,
|
| 112 |
+
title_color=title_color,
|
| 113 |
+
title_animation=title_animation,
|
| 114 |
+
title_duration=title_duration,
|
| 115 |
+
title_position=title_position,
|
| 116 |
+
title_start=title_start,
|
| 117 |
+
title_font_size=title_font_size,
|
| 118 |
+
typewriter_font_size=typewriter_font_size,
|
| 119 |
+
typewriter_color=typewriter_color,
|
| 120 |
+
subtitle_color=subtitle_color,
|
| 121 |
+
subtitle_effect=subtitle_effect,
|
| 122 |
+
fps=fps,
|
| 123 |
+
)
|
| 124 |
|
| 125 |
+
with open(output_path, "rb") as f:
|
| 126 |
+
video_bytes = f.read()
|
| 127 |
|
| 128 |
+
import shutil
|
| 129 |
+
shutil.rmtree(tmp_dir, ignore_errors=True)
|
| 130 |
+
return Response(content=video_bytes, media_type="video/mp4",
|
| 131 |
+
headers={"Content-Disposition": "attachment; filename=output.mp4"})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
|
| 133 |
+
except Exception as e:
|
| 134 |
+
print(traceback.format_exc(), file=sys.stderr)
|
| 135 |
+
import shutil
|
| 136 |
+
shutil.rmtree(tmp_dir, ignore_errors=True)
|
| 137 |
+
raise HTTPException(500, detail=str(e))
|
| 138 |
|
| 139 |
+
if __name__ == "__main__":
|
| 140 |
+
import uvicorn
|
| 141 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|
modules/lut.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
LUTS = {
|
| 4 |
+
"cinematic": {
|
| 5 |
+
"name": "🎬 电影橙青",
|
| 6 |
+
"matrix": np.array([[1.1, 0.0, -0.1], [0.0, 1.05, 0.0], [-0.05, 0.0, 1.15]]),
|
| 7 |
+
"warmth": (5, 0, -5), "contrast": 1.15,
|
| 8 |
+
},
|
| 9 |
+
"bw": {
|
| 10 |
+
"name": "⬛ 经典黑白",
|
| 11 |
+
"matrix": np.array([[0.3, 0.59, 0.11], [0.3, 0.59, 0.11], [0.3, 0.59, 0.11]]),
|
| 12 |
+
"warmth": (0, 0, 0), "contrast": 1.3,
|
| 13 |
+
},
|
| 14 |
+
"cyberpunk": {
|
| 15 |
+
"name": "🌆 赛博朋克",
|
| 16 |
+
"matrix": np.array([[0.8, 0.0, 0.3], [0.0, 0.9, 0.1], [0.1, 0.0, 1.3]]),
|
| 17 |
+
"warmth": (-10, 0, 15), "contrast": 1.2,
|
| 18 |
+
},
|
| 19 |
+
"warm": {
|
| 20 |
+
"name": "☀️ 日系暖阳",
|
| 21 |
+
"matrix": np.array([[1.1, 0.05, 0.0], [0.0, 1.0, -0.05], [-0.05, -0.05, 0.9]]),
|
| 22 |
+
"warmth": (15, 5, -10), "contrast": 0.95,
|
| 23 |
+
},
|
| 24 |
+
"noir": {
|
| 25 |
+
"name": "🌙 夜景蓝调",
|
| 26 |
+
"matrix": np.array([[0.7, 0.0, 0.2], [0.0, 0.8, 0.1], [0.1, 0.0, 1.2]]),
|
| 27 |
+
"warmth": (-15, -5, 10), "contrast": 1.25,
|
| 28 |
+
},
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
def apply_lut(frame, lut_name):
|
| 32 |
+
lut = LUTS.get(lut_name)
|
| 33 |
+
if not lut:
|
| 34 |
+
return frame
|
| 35 |
+
frame_float = frame.astype(np.float32)
|
| 36 |
+
h, w = frame.shape[:2]
|
| 37 |
+
pixels = frame_float.reshape(-1, 3)
|
| 38 |
+
transformed = pixels @ lut["matrix"].T
|
| 39 |
+
transformed = np.clip(transformed, 0, 255).reshape(h, w, 3)
|
| 40 |
+
b, g, r = cv2.split(transformed.astype(np.uint8))
|
| 41 |
+
r = cv2.add(r, lut["warmth"][0])
|
| 42 |
+
g = cv2.add(g, lut["warmth"][1])
|
| 43 |
+
b = cv2.add(b, lut["warmth"][2])
|
| 44 |
+
frame = cv2.merge([b, g, r])
|
| 45 |
+
frame = frame.astype(np.float32)
|
| 46 |
+
frame = (frame - 128) * lut["contrast"] + 128
|
| 47 |
+
return np.clip(frame, 0, 255).astype(np.uint8)
|
requirements.txt
CHANGED
|
@@ -1,18 +1,8 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
opencv-python-headless
|
| 10 |
-
git+https://github.com/tencent-ailab/IP-Adapter.git
|
| 11 |
-
# gradio 4.44 需和 gradio_client 1.3.0 + pydantic<2.12 搭配,否則 /api_info 炸掉主页 500
|
| 12 |
-
gradio==4.44.1
|
| 13 |
-
gradio_client==1.3.0
|
| 14 |
-
pydantic==2.10.6
|
| 15 |
-
fastapi==0.115.7
|
| 16 |
-
starlette==0.41.3
|
| 17 |
-
pillow
|
| 18 |
-
numpy<2
|
|
|
|
| 1 |
+
fastapi==0.104.1
|
| 2 |
+
uvicorn==0.24.0
|
| 3 |
+
python-multipart==0.0.6
|
| 4 |
+
numpy>=1.24.0
|
| 5 |
+
opencv-python-headless>=4.8.0
|
| 6 |
+
Pillow>=10.0.0
|
| 7 |
+
pydub>=0.25.0
|
| 8 |
+
librosa>=0.10.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|