Spaces:
Runtime error
Runtime error
- Dockerfile +23 -21
- app.py +19 -24
- requirements.txt +7 -4
Dockerfile
CHANGED
@@ -1,28 +1,30 @@
|
|
1 |
-
#
|
2 |
-
FROM
|
3 |
-
|
4 |
-
#
|
5 |
-
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
&& rm -rf /var/lib/apt/lists/*
|
9 |
|
10 |
-
#
|
11 |
-
|
12 |
|
|
|
|
|
13 |
|
14 |
-
#
|
15 |
-
RUN
|
16 |
-
|
17 |
|
18 |
-
#
|
19 |
-
WORKDIR /app
|
20 |
-
|
21 |
-
# Copiar los archivos al contenedor
|
22 |
COPY . /app
|
23 |
|
24 |
-
#
|
25 |
-
|
26 |
-
|
27 |
-
# Comando para iniciar la aplicaci贸n
|
28 |
-
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
1 |
+
# Usa una imagen base con soporte para Python y CUDA
|
2 |
+
FROM nvidia/cuda:11.7.1-cudnn8-runtime-ubuntu20.04
|
3 |
+
|
4 |
+
# Establece variables de entorno necesarias
|
5 |
+
ENV TRANSFORMERS_CACHE="/app/.cache" \
|
6 |
+
HF_HOME="/app/.cache" \
|
7 |
+
PATH="/opt/conda/bin:$PATH"
|
8 |
+
|
9 |
+
# Instala dependencias b谩sicas
|
10 |
+
RUN apt-get update && apt-get install -y \
|
11 |
+
python3 \
|
12 |
+
python3-pip \
|
13 |
+
git \
|
14 |
&& rm -rf /var/lib/apt/lists/*
|
15 |
|
16 |
+
# Establece el directorio de trabajo
|
17 |
+
WORKDIR /app
|
18 |
|
19 |
+
# Copia el archivo requirements.txt al contenedor
|
20 |
+
COPY requirements.txt /app/requirements.txt
|
21 |
|
22 |
+
# Instala las dependencias necesarias
|
23 |
+
RUN pip install --upgrade pip
|
24 |
+
RUN pip install -r requirements.txt
|
25 |
|
26 |
+
# Copia los archivos de la aplicaci贸n al contenedor
|
|
|
|
|
|
|
27 |
COPY . /app
|
28 |
|
29 |
+
# Comando para ejecutar la aplicaci贸n
|
30 |
+
CMD ["python3", "app.py"]
|
|
|
|
|
|
app.py
CHANGED
@@ -1,33 +1,28 @@
|
|
1 |
-
from fastapi import FastAPI
|
2 |
from diffusers import StableDiffusionDepth2ImgPipeline
|
3 |
-
from PIL import Image
|
4 |
import torch
|
5 |
|
6 |
app = FastAPI()
|
7 |
|
8 |
-
#
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
|
|
14 |
|
15 |
-
@app.post("/generate-depth/")
|
16 |
-
async def generate_depth(file: UploadFile = File(...)):
|
17 |
-
"""
|
18 |
-
Generar un mapa de profundidad a partir de una imagen.
|
19 |
-
"""
|
20 |
-
try:
|
21 |
-
# Leer la imagen
|
22 |
-
image = Image.open(file.file).convert("RGB")
|
23 |
|
24 |
-
|
25 |
-
|
|
|
26 |
|
27 |
-
# Guardar el resultado en un archivo temporal
|
28 |
-
depth_map.save("/app/cache/depth_map.png")
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
|
|
|
1 |
+
from fastapi import FastAPI
|
2 |
from diffusers import StableDiffusionDepth2ImgPipeline
|
|
|
3 |
import torch
|
4 |
|
5 |
app = FastAPI()
|
6 |
|
7 |
+
# Inicializa el modelo Marigold
|
8 |
+
@app.on_event("startup")
|
9 |
+
async def load_model():
|
10 |
+
global pipe
|
11 |
+
pipe = StableDiffusionDepth2ImgPipeline.from_pretrained(
|
12 |
+
"prs-eth/marigold-depth-v1-0",
|
13 |
+
torch_dtype=torch.float16
|
14 |
+
)
|
15 |
+
pipe.to("cuda") # Mueve el modelo a la GPU
|
16 |
+
print("Modelo cargado correctamente")
|
17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
+
@app.get("/")
|
20 |
+
async def root():
|
21 |
+
return {"message": "Marigold API funcionando correctamente"}
|
22 |
|
|
|
|
|
23 |
|
24 |
+
@app.post("/depthmap/")
|
25 |
+
async def generate_depth_map(input_image: str):
|
26 |
+
# Carga la imagen y genera el mapa de profundidad
|
27 |
+
image = pipe(input_image).images[0]
|
28 |
+
return {"depth_map": image}
|
requirements.txt
CHANGED
@@ -1,7 +1,10 @@
|
|
1 |
fastapi
|
2 |
uvicorn[standard]
|
3 |
-
torch
|
4 |
-
torchvision
|
5 |
-
diffusers
|
6 |
-
transformers
|
7 |
pillow
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
fastapi
|
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
|