aducsdr commited on
Commit
70b72ca
·
verified ·
1 Parent(s): 1dbab82

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -81
app.py CHANGED
@@ -1,90 +1,55 @@
1
- import gradio as gr
2
- import subprocess
3
- import os
4
- import shutil # MUDANÇA 1: Importar a biblioteca 'shutil' para cópia de arquivos
5
 
6
- def run_inference_app(video_file_path, seed_num):
7
- # O componente gr.Video passa o caminho do arquivo como uma string
8
- if video_file_path is None:
9
- return None, "Por favor, envie um arquivo de vídeo."
10
-
11
- # O app roda de dentro do diretório /app/SeedVR
12
- input_folder = "inputs"
13
- os.makedirs(input_folder, exist_ok=True)
14
-
15
- # MUDANÇA 2: Lógica de cópia de arquivo mais robusta
16
- # Usamos shutil.copy para copiar o arquivo temporário do Gradio para nossa pasta de entrada.
17
- # os.path.basename garante que pegamos apenas o nome do arquivo original.
18
- file_name = os.path.basename(video_file_path)
19
- input_video_path = os.path.join(input_folder, file_name)
20
- shutil.copy(video_file_path, input_video_path)
21
-
22
- output_folder = "outputs"
23
- os.makedirs(output_folder, exist_ok=True)
24
-
25
- # Comando de inferência. O ambiente conda já está "ativado".
26
- command = [
27
- "torchrun", "--nproc-per-node=4",
28
- "projects/inference_seedvr2_3b.py",
29
- "--video_path", input_folder,
30
- "--output_dir", output_folder,
31
- "--seed", str(seed_num),
32
- "--res_h", "320",
33
- "--res_w", "512",
34
- ]
35
 
36
- log_output = "Iniciando a inferência...\n" + ' '.join(command) + "\n\n"
37
-
38
- try:
39
- process = subprocess.Popen(
40
- command,
41
- stdout=subprocess.PIPE,
42
- stderr=subprocess.STDOUT,
43
- text=True,
44
- encoding='utf-8'
45
- )
46
 
47
- while True:
48
- line = process.stdout.readline()
49
- if not line:
50
- break
51
- log_output += line
52
- print(line.strip())
53
- yield None, log_output
54
 
55
- process.wait()
 
56
 
57
- if process.returncode != 0:
58
- raise RuntimeError("O script de inferência falhou. Verifique os logs.")
59
-
60
- result_files = [os.path.join(output_folder, f) for f in os.listdir(output_folder) if f.endswith('.mp4')]
61
- if not result_files:
62
- return None, log_output + "\n\nERRO: Nenhum vídeo foi gerado."
63
-
64
- return result_files, log_output + "\n\nInferência concluída com sucesso!"
65
 
66
- except Exception as e:
67
- error_message = f"{log_output}\n\nOcorreu um erro: {str(e)}"
68
- return None, error_message
69
 
70
- with gr.Blocks() as demo:
71
- gr.Markdown("# 🚀 Inferência SeedVR2 com Ambiente Conda")
72
- gr.Markdown("Este ambiente foi construído com Conda usando um Dockerfile para máxima estabilidade.")
73
 
74
- with gr.Row():
75
- with gr.Column(scale=1):
76
- # MUDANÇA 3: Usar gr.Video em vez de gr.File
77
- video_input = gr.Video(label="Vídeo de Entrada")
78
- seed_input = gr.Number(label="Seed", value=123)
79
- run_button = gr.Button("Gerar Vídeo", variant="primary")
80
- with gr.Column(scale=2):
81
- gallery_output = gr.Gallery(label="Vídeo de Saída", show_label=True)
82
- log_display = gr.Textbox(label="Logs de Execução", lines=15, interactive=False, autoscroll=True)
83
-
84
- run_button.click(
85
- fn=run_inference_app,
86
- inputs=[video_input, seed_input],
87
- outputs=[gallery_output, log_display]
88
- )
89
 
90
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Dockerfile (VERSÃO FINAL COM VÍDEOS DE EXEMPLO)
 
 
 
2
 
3
+ # 1. COMEÇAR COM A BASE CORRETA
4
+ FROM nvidia/cuda:12.1.1-devel-ubuntu22.04
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
+ # 2. INSTALAR DEPENDÊNCIAS DO SISTEMA
7
+ ENV DEBIAN_FRONTEND=noninteractive
8
+ RUN apt-get update && apt-get install -y --no-install-recommends \
9
+ wget \
10
+ git \
11
+ && apt-get clean \
12
+ && rm -rf /var/lib/apt/lists/*
 
 
 
13
 
14
+ # 3. INSTALAR O MINICONDA
15
+ RUN wget --quiet https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda.sh && \
16
+ /bin/bash ~/miniconda.sh -b -p /opt/conda && \
17
+ rm ~/miniconda.sh
 
 
 
18
 
19
+ # 4. ADICIONAR CONDA AO PATH
20
+ ENV PATH /opt/conda/bin:$PATH
21
 
22
+ # 5. ACEITAR OS TERMOS DE SERVIÇO
23
+ RUN yes | conda tos accept
 
 
 
 
 
 
24
 
25
+ # 6. ATUALIZAR O CONDA
26
+ RUN conda update -n base -c defaults conda
 
27
 
28
+ # 7. CRIAR O AMBIENTE CONDA
29
+ COPY environment.yml .
30
+ RUN conda env create -f environment.yml && conda clean --all -y
31
 
32
+ # 8. INSTALAR FLASH_ATTN DENTRO DO AMBIENTE
33
+ RUN conda run -n seedvr pip install "flash_attn==2.5.9.post1" --no-build-isolation
 
 
 
 
 
 
 
 
 
 
 
 
 
34
 
35
+ # 9. DEFINIR O AMBIENTE CONDA COMO PADRÃO
36
+ SHELL ["conda", "run", "-n", "seedvr", "/bin/bash", "-c"]
37
+
38
+ # 10. PREPARAR O APLICATIVO
39
+ WORKDIR /app
40
+ RUN git clone https://github.com/bytedance-seed/SeedVR.git
41
+ WORKDIR /app/SeedVR
42
+
43
+ # 11. BAIXAR O MODELO DURANTE A CONSTRUÇÃO
44
+ RUN huggingface-cli download ByteDance-Seed/SeedVR2-3B --local-dir ckpts --local-dir-use-symlinks False
45
+
46
+ # 12. !!! NOVO !!! BAIXAR OS VÍDEOS DE EXEMPLO
47
+ RUN wget -O 01.mp4 https://huggingface.co/datasets/Iceclear/SeedVR_VideoDemos/resolve/main/seedvr_videos_crf23/aigc1k/23_1_lq.mp4 && \
48
+ wget -O 02.mp4 https://huggingface.co/datasets/Iceclear/SeedVR_VideoDemos/resolve/main/seedvr_videos_crf23/aigc1k/28_1_lq.mp4 && \
49
+ wget -O 03.mp4 https://huggingface.co/datasets/Iceclear/SeedVR_VideoDemos/resolve/main/seedvr_videos_crf23/aigc1k/2_1_lq.mp4
50
+
51
+ # 13. COPIAR O CÓDIGO DO NOSSO APP
52
+ COPY app.py .
53
+
54
+ # 14. DEFINIR O COMANDO DE EXECUÇÃO
55
+ CMD ["python", "app.py"]