Spaces:
Sleeping
Sleeping
MarigoldDepthPipeline
Browse files- Dockerfile +16 -24
- app.py +21 -26
- requirements.txt +7 -0
Dockerfile
CHANGED
@@ -1,38 +1,30 @@
|
|
1 |
-
#
|
2 |
FROM nvidia/cuda:11.7.1-cudnn8-runtime-ubuntu20.04
|
3 |
|
4 |
-
#
|
|
|
|
|
|
|
|
|
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 |
-
#
|
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 -
|
20 |
|
21 |
-
#
|
22 |
-
|
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 |
-
#
|
32 |
-
|
33 |
|
34 |
-
#
|
35 |
EXPOSE 8000
|
36 |
|
37 |
-
# Comando
|
38 |
-
CMD ["
|
|
|
1 |
+
# Imagen base para CUDA y PyTorch
|
2 |
FROM nvidia/cuda:11.7.1-cudnn8-runtime-ubuntu20.04
|
3 |
|
4 |
+
# Configuraci贸n de entornos
|
5 |
+
ENV TRANSFORMERS_CACHE="/app/.cache" \
|
6 |
+
HF_HOME="/app/.cache"
|
7 |
+
|
8 |
+
# Instalaci贸n de herramientas b谩sicas
|
9 |
RUN apt-get update && apt-get install -y \
|
10 |
python3 \
|
11 |
python3-pip \
|
12 |
git \
|
13 |
&& rm -rf /var/lib/apt/lists/*
|
14 |
|
15 |
+
# Instala dependencias de Python
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
RUN pip install --upgrade pip
|
17 |
+
RUN pip install torch torchvision diffusers fastapi uvicorn pillow prs-eth-marigold
|
18 |
|
19 |
+
# Crea directorios necesarios
|
20 |
+
WORKDIR /app
|
21 |
+
RUN mkdir -p /app/.cache && chmod -R 777 /app/.cache
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
+
# Copia el c贸digo de la aplicaci贸n
|
24 |
+
COPY . /app
|
25 |
|
26 |
+
# Expone el puerto de FastAPI
|
27 |
EXPOSE 8000
|
28 |
|
29 |
+
# Comando de inicio
|
30 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]
|
app.py
CHANGED
@@ -1,36 +1,31 @@
|
|
1 |
-
from fastapi import FastAPI,
|
2 |
-
import
|
3 |
-
import
|
4 |
|
5 |
app = FastAPI()
|
6 |
|
7 |
-
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
9 |
"""
|
10 |
-
|
11 |
"""
|
12 |
try:
|
13 |
-
|
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 |
-
|
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 |
-
|
31 |
-
|
32 |
-
raise HTTPException(status_code=500, detail=f"Error en la inferencia: {result.stderr}")
|
33 |
|
34 |
-
return {"message": "
|
35 |
except Exception as e:
|
36 |
-
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI, UploadFile, File
|
2 |
+
from PIL import Image
|
3 |
+
from prs_eth_marigold import MarigoldDepthPipeline
|
4 |
|
5 |
app = FastAPI()
|
6 |
|
7 |
+
# Carga el modelo Marigold al inicio
|
8 |
+
pipe = MarigoldDepthPipeline.from_pretrained(
|
9 |
+
"prs-eth/marigold-depth-v1-0", torch_dtype="auto"
|
10 |
+
).to("cuda")
|
11 |
+
|
12 |
+
@app.post("/generate-depth/")
|
13 |
+
async def generate_depth(file: UploadFile = File(...)):
|
14 |
"""
|
15 |
+
Genera un mapa de profundidad a partir de una imagen.
|
16 |
"""
|
17 |
try:
|
18 |
+
image = Image.open(file.file)
|
|
|
|
|
|
|
|
|
19 |
|
20 |
+
result = pipe(image).images[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
+
output_path = "/app/output_depth_map.png"
|
23 |
+
result.save(output_path)
|
|
|
24 |
|
25 |
+
return {"message": "Mapa de profundidad generado", "output_path": output_path}
|
26 |
except Exception as e:
|
27 |
+
return {"error": str(e)}
|
28 |
+
|
29 |
+
@app.get("/")
|
30 |
+
async def root():
|
31 |
+
return {"message": "API de generaci贸n de mapas de profundidad con Marigold"}
|
requirements.txt
CHANGED
@@ -1,2 +1,9 @@
|
|
1 |
fastapi>=0.95.0
|
2 |
uvicorn[standard]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
fastapi>=0.95.0
|
2 |
uvicorn[standard]
|
3 |
+
accelerate>=0.22.0
|
4 |
+
diffusers>=0.25.0
|
5 |
+
matplotlib
|
6 |
+
scipy
|
7 |
+
torch==2.0.1
|
8 |
+
torchvision==0.15.2
|
9 |
+
transformers>=4.32.1
|