Carlex22222 commited on
Commit
b9e2818
·
verified ·
1 Parent(s): 36b03d5

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +22 -135
Dockerfile CHANGED
@@ -1,144 +1,31 @@
1
- # app.py (Interface final com 3 abas: SeedVR, V-INT Edit, V-INT Pipeline)
2
 
3
- import gradio as gr
4
- import os
5
- import subprocess
6
- import shutil
7
- import uuid
8
- from huggingface_hub import snapshot_download
9
- import spaces
10
 
11
- # --- 1. CONFIGURAÇÃO E DOWNLOAD DOS MODELOS ---
 
12
 
13
- SEEDVR_DIR = "/app/SeedVR"
14
- VINCIE_DIR = "/app/VINCIE"
15
- HF_TOKEN = os.environ.get("HF_TOKEN")
16
 
17
- @spaces.GPU
18
- def download_models():
19
- """Baixa os modelos para SeedVR e V-INT se eles não existirem."""
20
- # Download do SeedVR
21
- if not os.path.exists(os.path.join(SEEDVR_DIR, "ckpts", "seedvr2_ema_3b.pth")):
22
- print("Baixando modelo do SeedVR-3B...")
23
- snapshot_download(repo_id="ByteDance-Seed/SeedVR2-3B", local_dir=os.path.join(SEEDVR_DIR, "ckpts"), token=HF_TOKEN, local_dir_use_symlinks=False)
24
- else: print("Modelo do SeedVR já existe.")
25
 
26
- # Download do V-INT
27
- if not os.path.exists(os.path.join(VINCIE_DIR, "ckpt", "VINCIE-3B")):
28
- print("Baixando modelo do VINCIE-3B...")
29
- snapshot_download(repo_id="ByteDance-Seed/VINCIE-3B", local_dir=os.path.join(VINCIE_DIR, "ckpt", "VINCIE-3B"), token=HF_TOKEN, local_dir_use_symlinks=False)
30
- else: print("Modelo do VINCIE já existe.")
31
 
32
- # Download de assets e configs do V-INT (para os exemplos)
33
- if not os.path.exists(os.path.join(VINCIE_DIR, "assets", "woman_pineapple.png")):
34
- print("Baixando assets e configs do V-INT...")
35
- snapshot_download(repo_id="ByteDance-Seed/VINCIE", repo_type="space", local_dir=VINCIE_DIR, token=HF_TOKEN, allow_patterns=["assets/*", "configs/*"], local_dir_use_symlinks=False)
36
- else: print("Assets e configs do V-INT já existem.")
37
 
38
- download_models()
 
 
 
39
 
40
- # --- 2. LÓGICA DE INFERÊNCIA ---
 
 
41
 
42
- def run_subprocess_with_logs(command, cwd):
43
- """Função genérica para rodar um subprocesso e streamar os logs para o Gradio."""
44
- log_output = f"Executando comando:\n{' '.join(command)}\n\n"
45
- yield [], log_output
46
-
47
- env = os.environ.copy(); env["PYTHONUNBUFFERED"] = "1"
48
- process = subprocess.Popen(command, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, encoding='utf-8', env=env)
49
-
50
- while True:
51
- output = process.stdout.readline()
52
- if output == '' and process.poll() is not None: break
53
- if output: log_output += output; yield [], log_output
54
-
55
- if process.poll() != 0: raise gr.Error("A inferência falhou. Verifique os logs.")
56
-
57
- def run_seedvr_inference(video_path, seed):
58
- # (Lógica específica do SeedVR)
59
- if video_path is None: raise gr.Error("Por favor, faça o upload de um arquivo para o SeedVR.")
60
- job_id = str(uuid.uuid4())
61
- input_dir = os.path.join("/app", "temp_inputs", job_id); os.makedirs(input_dir, exist_ok=True)
62
- output_dir = os.path.join("/app", "temp_outputs", job_id); os.makedirs(output_dir, exist_ok=True)
63
- shutil.copy(video_path, input_dir)
64
-
65
- input_folder_relative = os.path.relpath(input_dir, SEEDVR_DIR)
66
- output_folder_relative = os.path.relpath(output_dir, SEEDVR_DIR)
67
- command = ["torchrun", "--nproc-per-node=4", "projects/inference_seedvr2_3b.py", "--video_path", input_folder_relative, "--output_dir", output_folder_relative, "--seed", str(seed), "--res_h", "720", "--res_w", "1280"]
68
-
69
- for gallery, logs in run_subprocess_with_logs(command, SEEDVR_DIR):
70
- yield None, logs # Retorna None para o output enquanto os logs são atualizados
71
-
72
- output_files = [os.path.join(output_dir, f) for f in os.listdir(output_dir) if f.endswith(('.mp4', '.png'))]
73
- if not output_files: raise gr.Error("Nenhum arquivo de saída encontrado.")
74
- yield output_files[0], logs
75
-
76
- def run_vincie_edit_inference(files, prompts_str):
77
- # (Lógica específica para o modo de EDIÇÃO do V-INT)
78
- if not files: raise gr.Error("Por favor, faça o upload de uma imagem para editar.")
79
- if not prompts_str: raise gr.Error("Por favor, forneça os prompts de edição.")
80
-
81
- job_id = str(uuid.uuid4())
82
- output_dir = os.path.join(VINCIE_DIR, "output", job_id)
83
-
84
- image_paths_str = ", ".join([f'"{f.name}"' for f in files])
85
- prompts_list_str = ", ".join([f'"{p.strip()}"' for p in prompts_str.split(';')])
86
- command = ["python", "main.py", "configs/generate.yaml", f'generation.positive_prompt.image_path=[{image_paths_str}]', f'generation.positive_prompt.prompts=[{prompts_list_str}]', f'generation.output.dir={output_dir}']
87
-
88
- for gallery, logs in run_subprocess_with_logs(command, VINCIE_DIR):
89
- yield gallery, logs
90
-
91
- output_files = [os.path.join(output_dir, f) for f in os.listdir(output_dir) if f.endswith(('.png', '.jpg'))]
92
- if not output_files: raise gr.Error("Nenhum arquivo de saída encontrado.")
93
- yield output_files, logs
94
-
95
- def run_vincie_pipeline_inference(files, final_prompt):
96
- # (NOVA LÓGICA para o modo de PIPELINE do V-INT)
97
- if not files: raise gr.Error("Por favor, faça o upload de múltiplas imagens para a composição.")
98
- if not final_prompt: raise gr.Error("Por favor, forneça o prompt de composição final.")
99
-
100
- job_id = str(uuid.uuid4())
101
- output_dir = os.path.join(VINCIE_DIR, "output", job_id)
102
-
103
- # Gera os prompts de placeholder
104
- placeholder_prompts = [f"<IMG{i}>: " for i in range(len(files))]
105
- all_prompts = placeholder_prompts + [final_prompt]
106
-
107
- image_paths_str = ", ".join([f'"{f.name}"' for f in files])
108
- prompts_list_str = ", ".join([f'"{p}"' for p in all_prompts])
109
- command = ["python", "main.py", "configs/generate.yaml", "generation.pad_img_placehoder=False", f'generation.positive_prompt.image_path=[{image_paths_str}]', f'generation.positive_prompt.prompts=[{prompts_list_str}]', f'generation.output.dir={output_dir}']
110
-
111
- for gallery, logs in run_subprocess_with_logs(command, VINCIE_DIR):
112
- yield gallery, logs
113
-
114
- output_files = [os.path.join(output_dir, f) for f in os.listdir(output_dir) if f.endswith(('.png', '.jpg'))]
115
- if not output_files: raise gr.Error("Nenhum arquivo de saída foi encontrado.")
116
- yield output_files, logs
117
-
118
- # --- 3. INTERFACE GRADIO COM 3 ABAS ---
119
-
120
- with gr.Blocks() as demo:
121
- gr.Markdown("<h1><center>Super-Space: SeedVR & V-INT</center></h1>")
122
-
123
- with gr.Tabs():
124
- # --- ABA SEEDVR ---
125
- with gr.TabItem("SeedVR (Restauração de Vídeo)"):
126
- with gr.Row():
127
- with gr.Column(scale=1):
128
- seedvr_input_video = gr.Video(label="Upload de Vídeo")
129
- seedvr_seed = gr.Number(value=666, label="Seed")
130
- seedvr_run_button = gr.Button("Executar SeedVR", variant="primary")
131
- with gr.Column(scale=2):
132
- seedvr_output = gr.Video(label="Vídeo Restaurado")
133
- seedvr_logs = gr.Textbox(label="Logs", lines=10, interactive=False)
134
- seedvr_run_button.click(fn=run_seedvr_inference, inputs=[seedvr_input_video, seedvr_seed], outputs=[seedvr_output, seedvr_logs])
135
-
136
- # --- ABA V-INT EDIÇÃO ---
137
- with gr.TabItem("V-INT (Edição de Imagem)"):
138
- with gr.Row():
139
- with gr.Column(scale=1):
140
- vincie_edit_input = gr.Files(label="Upload de Imagem(ns) para Editar", file_types=["image"])
141
- vincie_edit_prompts = gr.Textbox(label="Prompts de Edição (separados por ';')", lines=5, placeholder="Ex: Add a crown to her head; Change the background...")
142
- vincie_edit_button = gr.Button("Executar Edição", variant="primary")
143
- with gr.Column(scale=2):
144
- vincie_edit_output
 
1
+ # Dockerfile (VERSÃO FINAL COM OS DOIS PROJETOS)
2
 
3
+ FROM nvidia/cuda:12.1.1-devel-ubuntu22.04
 
 
 
 
 
 
4
 
5
+ ENV DEBIAN_FRONTEND=noninteractive
6
+ RUN apt-get update && apt-get install -y --no-install-recommends wget git && apt-get clean && rm -rf /var/lib/apt/lists/*
7
 
8
+ RUN wget --quiet https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda.sh && \
9
+ /bin/bash ~/miniconda.sh -b -p /opt/conda && \
10
+ rm ~/miniconda.sh
11
 
12
+ ENV PATH /opt/conda/bin:$PATH
 
 
 
 
 
 
 
13
 
14
+ COPY . /app
15
+ WORKDIR /app
 
 
 
16
 
17
+ RUN yes | conda tos accept
18
+ RUN conda update -n base -c defaults conda
19
+ RUN conda env create -f environment.yml && conda clean --all -y
 
 
20
 
21
+ # Instala flash_attn para ambos os projetos
22
+ # V-INT usa uma versão mais nova, então instalamos essa.
23
+ RUN conda run -n seedvr env FLASH_ATTENTION_SKIP_CUDA_BUILD=TRUE \
24
+ pip install "flash_attn==2.6.3" --no-build-isolation --no-cache-dir
25
 
26
+ # Clona os repositórios dos projetos
27
+ RUN git clone https://github.com/ByteDance-Seed/SeedVR.git
28
+ RUN git clone https://github.com/ByteDance-Seed/VINCIE.git
29
 
30
+ WORKDIR /app
31
+ CMD ["conda", "run", "-n", "seedvr", "env", "PYTHONUNBUFFERED=1", "python", "app.py", "--share"]