Spaces:
Runtime error
Runtime error
api
Browse files- Dockerfile +18 -8
- app.py +28 -4
- requirements.txt +5 -0
Dockerfile
CHANGED
@@ -1,13 +1,23 @@
|
|
1 |
-
|
|
|
2 |
|
3 |
-
|
4 |
-
|
5 |
-
|
|
|
|
|
6 |
|
|
|
|
|
|
|
|
|
7 |
WORKDIR /app
|
8 |
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
11 |
|
12 |
-
|
13 |
-
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
1 |
+
# Usar Python base
|
2 |
+
FROM python:3.10-slim
|
3 |
|
4 |
+
# Instalar dependencias del sistema
|
5 |
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
6 |
+
libgl1-mesa-glx \
|
7 |
+
libglib2.0-0 \
|
8 |
+
&& rm -rf /var/lib/apt/lists/*
|
9 |
|
10 |
+
# Instalar dependencias de Python
|
11 |
+
RUN pip install --no-cache-dir fastapi uvicorn torch torchvision diffusers transformers pillow
|
12 |
+
|
13 |
+
# Establecer directorio de trabajo
|
14 |
WORKDIR /app
|
15 |
|
16 |
+
# Copiar los archivos al contenedor
|
17 |
+
COPY . /app
|
18 |
+
|
19 |
+
# Exponer el puerto donde se ejecutar谩 el servidor
|
20 |
+
EXPOSE 7860
|
21 |
|
22 |
+
# Comando para ejecutar la aplicaci贸n
|
23 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
app.py
CHANGED
@@ -1,7 +1,31 @@
|
|
1 |
-
from fastapi import FastAPI
|
|
|
|
|
|
|
2 |
|
|
|
3 |
app = FastAPI()
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI, UploadFile, File
|
2 |
+
from diffusers import StableDiffusionDepth2ImgPipeline
|
3 |
+
from PIL import Image
|
4 |
+
import torch
|
5 |
|
6 |
+
# Crear la aplicaci贸n FastAPI
|
7 |
app = FastAPI()
|
8 |
|
9 |
+
# Cargar el modelo Marigold
|
10 |
+
model_id = "prs-eth/marigold-depth-v1-0"
|
11 |
+
pipe = StableDiffusionDepth2ImgPipeline.from_pretrained(
|
12 |
+
model_id, torch_dtype=torch.float16
|
13 |
+
)
|
14 |
+
pipe = pipe.to("cuda" if torch.cuda.is_available() else "cpu")
|
15 |
+
|
16 |
+
@app.post("/generate-depth/")
|
17 |
+
async def generate_depth(file: UploadFile = File(...)):
|
18 |
+
"""
|
19 |
+
Genera un mapa de profundidad a partir de una imagen.
|
20 |
+
"""
|
21 |
+
# Leer la imagen subida por el usuario
|
22 |
+
image = Image.open(file.file).convert("RGB")
|
23 |
+
|
24 |
+
# Generar el mapa de profundidad
|
25 |
+
depth_map = pipe(image).images[0]
|
26 |
+
|
27 |
+
# Guardar el resultado en un archivo temporal
|
28 |
+
depth_map.save("depth_map.png")
|
29 |
+
|
30 |
+
# Retornar un mensaje de 茅xito
|
31 |
+
return {"message": "Mapa de profundidad generado con 茅xito.", "output": "depth_map.png"}
|
requirements.txt
CHANGED
@@ -1,2 +1,7 @@
|
|
1 |
fastapi
|
2 |
uvicorn[standard]
|
|
|
|
|
|
|
|
|
|
|
|
1 |
fastapi
|
2 |
uvicorn[standard]
|
3 |
+
torch
|
4 |
+
torchvision
|
5 |
+
diffusers
|
6 |
+
transformers
|
7 |
+
pillow
|