Spaces:
Running
on
T4
Running
on
T4
run version
Browse files- Dockerfile +28 -20
- app.py +34 -21
- entrypoint.sh +2 -0
- environment.yaml +0 -16
- requirements.txt +0 -8
Dockerfile
CHANGED
@@ -1,30 +1,38 @@
|
|
1 |
# Usa una imagen base con soporte para Python y CUDA
|
2 |
FROM nvidia/cuda:11.7.1-cudnn8-runtime-ubuntu20.04
|
3 |
|
4 |
-
# Instala
|
5 |
-
RUN apt-get update && apt-get install -y
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
|
11 |
-
#
|
12 |
-
|
13 |
|
14 |
-
#
|
15 |
-
|
16 |
|
17 |
-
# Instala
|
18 |
-
RUN
|
|
|
19 |
|
20 |
-
#
|
21 |
-
|
22 |
|
23 |
-
#
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
-
#
|
27 |
-
|
28 |
|
29 |
-
# Comando para
|
30 |
-
CMD ["
|
|
|
1 |
# Usa una imagen base con soporte para Python y CUDA
|
2 |
FROM nvidia/cuda:11.7.1-cudnn8-runtime-ubuntu20.04
|
3 |
|
4 |
+
# Instala dependencias b谩sicas
|
5 |
+
RUN apt-get update && apt-get install -y \
|
6 |
+
python3 \
|
7 |
+
python3-pip \
|
8 |
+
git \
|
9 |
+
&& rm -rf /var/lib/apt/lists/*
|
10 |
|
11 |
+
# Establece el directorio de trabajo
|
12 |
+
WORKDIR /app
|
13 |
|
14 |
+
# Clona el repositorio de Marigold
|
15 |
+
RUN git clone https://github.com/prs-eth/Marigold.git /app/Marigold
|
16 |
|
17 |
+
# Instala las dependencias del repositorio de Marigold
|
18 |
+
RUN pip install --upgrade pip
|
19 |
+
RUN pip install -r /app/Marigold/requirements.txt
|
20 |
|
21 |
+
# Copia el archivo requirements.txt para dependencias adicionales (API, etc.)
|
22 |
+
COPY requirements.txt /app/requirements.txt
|
23 |
|
24 |
+
# Instala las dependencias necesarias para la API
|
25 |
+
RUN pip install -r /app/requirements.txt
|
26 |
+
|
27 |
+
# Copia los archivos necesarios para la API
|
28 |
+
COPY app.py /app/app.py
|
29 |
+
COPY entrypoint.sh /app/entrypoint.sh
|
30 |
+
|
31 |
+
# Da permisos de ejecuci贸n al archivo entrypoint
|
32 |
+
RUN chmod +x /app/entrypoint.sh
|
33 |
|
34 |
+
# Exponer el puerto para la API
|
35 |
+
EXPOSE 8000
|
36 |
|
37 |
+
# Comando para inicializar la app
|
38 |
+
CMD ["/app/entrypoint.sh"]
|
app.py
CHANGED
@@ -1,23 +1,36 @@
|
|
1 |
-
from
|
2 |
-
import
|
|
|
3 |
|
4 |
-
|
5 |
-
print("[DEBUG] Cargando modelo Marigold...")
|
6 |
-
try:
|
7 |
-
pipe = StableDiffusionDepth2ImgPipeline.from_pretrained(
|
8 |
-
"prs-eth/marigold-depth-v1-0",
|
9 |
-
torch_dtype=torch.float16
|
10 |
-
)
|
11 |
-
pipe.to("cuda")
|
12 |
-
print("[DEBUG] Modelo Marigold cargado exitosamente.")
|
13 |
-
except Exception as e:
|
14 |
-
print(f"[ERROR] Error al cargar el modelo: {e}")
|
15 |
-
raise e
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI, HTTPException
|
2 |
+
import subprocess
|
3 |
+
import os
|
4 |
|
5 |
+
app = FastAPI()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
+
@app.post("/run_inference/")
|
8 |
+
def run_inference(input_dir: str = "Marigold/input/in-the-wild_example", output_dir: str = "Marigold/output"):
|
9 |
+
"""
|
10 |
+
Llama al script de inferencia de Marigold con los par谩metros proporcionados.
|
11 |
+
"""
|
12 |
+
try:
|
13 |
+
# Verifica que los directorios existan
|
14 |
+
if not os.path.exists(input_dir):
|
15 |
+
raise HTTPException(status_code=400, detail="Directorio de entrada no encontrado.")
|
16 |
+
if not os.path.exists(output_dir):
|
17 |
+
os.makedirs(output_dir)
|
18 |
+
|
19 |
+
# Llama al script de inferencia
|
20 |
+
command = [
|
21 |
+
"python", "Marigold/run.py",
|
22 |
+
"--checkpoint", "prs-eth/marigold-v1-0",
|
23 |
+
"--denoise_steps", "50",
|
24 |
+
"--ensemble_size", "10",
|
25 |
+
"--input_rgb_dir", input_dir,
|
26 |
+
"--output_dir", output_dir
|
27 |
+
]
|
28 |
+
result = subprocess.run(command, capture_output=True, text=True)
|
29 |
+
|
30 |
+
# Verifica si hubo errores durante la ejecuci贸n
|
31 |
+
if result.returncode != 0:
|
32 |
+
raise HTTPException(status_code=500, detail=f"Error en la inferencia: {result.stderr}")
|
33 |
+
|
34 |
+
return {"message": "Inferencia completada", "output_dir": output_dir}
|
35 |
+
except Exception as e:
|
36 |
+
raise HTTPException(status_code=500, detail=str(e))
|
entrypoint.sh
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
#!/bin/bash
|
2 |
+
uvicorn app:app --host 0.0.0.0 --port 8000
|
environment.yaml
DELETED
@@ -1,16 +0,0 @@
|
|
1 |
-
name: marigold
|
2 |
-
channels:
|
3 |
-
- conda-forge
|
4 |
-
- nvidia
|
5 |
-
- pytorch
|
6 |
-
dependencies:
|
7 |
-
- accelerate>=0.22.0
|
8 |
-
- diffusers>=0.25.0
|
9 |
-
- matplotlib>=3.8.2
|
10 |
-
- scipy>=1.11.4
|
11 |
-
- python=3.10.12
|
12 |
-
- pytorch=2.4.0
|
13 |
-
- pytorch-cuda=11.7
|
14 |
-
- torchvision=0.19.0
|
15 |
-
- pip:
|
16 |
-
- transformers>=4.32.1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
requirements.txt
CHANGED
@@ -1,10 +1,2 @@
|
|
1 |
fastapi>=0.95.0
|
2 |
uvicorn[standard]
|
3 |
-
pillow
|
4 |
-
accelerate>=0.22.0
|
5 |
-
diffusers>=0.25.0
|
6 |
-
matplotlib
|
7 |
-
scipy
|
8 |
-
torch==2.4.0
|
9 |
-
torchvision==0.19.0
|
10 |
-
transformers>=4.32.1
|
|
|
1 |
fastapi>=0.95.0
|
2 |
uvicorn[standard]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|