Spaces:
Sleeping
Sleeping
fix diffuser
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
-
|
2 |
-
from fastapi.responses import StreamingResponse
|
3 |
-
from diffusers import MarigoldDepthPipeline
|
4 |
import torch
|
|
|
|
|
5 |
from PIL import Image
|
6 |
import io
|
7 |
|
@@ -33,18 +33,18 @@ async def predict_depth(file: UploadFile = File(...)):
|
|
33 |
|
34 |
# Visualiza la profundidad
|
35 |
vis = pipe.image_processor.visualize_depth(depth.prediction)
|
36 |
-
|
|
|
37 |
img_buffer = io.BytesIO()
|
38 |
vis[0].save(img_buffer, format="PNG")
|
39 |
-
img_buffer.seek(0)
|
40 |
|
41 |
-
#
|
42 |
return StreamingResponse(img_buffer, media_type="image/png")
|
43 |
-
|
44 |
except Exception as e:
|
45 |
print(f"[ERROR] {str(e)}")
|
|
|
46 |
|
47 |
-
|
48 |
@app.get("/")
|
49 |
async def root():
|
50 |
return {"message": "API de generaci贸n de mapas de profundidad con Marigold"}
|
|
|
1 |
+
import diffusers
|
|
|
|
|
2 |
import torch
|
3 |
+
from fastapi import FastAPI, UploadFile, HTTPException, File
|
4 |
+
from fastapi.responses import StreamingResponse
|
5 |
from PIL import Image
|
6 |
import io
|
7 |
|
|
|
33 |
|
34 |
# Visualiza la profundidad
|
35 |
vis = pipe.image_processor.visualize_depth(depth.prediction)
|
36 |
+
|
37 |
+
# Guarda la imagen generada en un buffer
|
38 |
img_buffer = io.BytesIO()
|
39 |
vis[0].save(img_buffer, format="PNG")
|
40 |
+
img_buffer.seek(0)
|
41 |
|
42 |
+
# Devuelve la imagen como respuesta
|
43 |
return StreamingResponse(img_buffer, media_type="image/png")
|
|
|
44 |
except Exception as e:
|
45 |
print(f"[ERROR] {str(e)}")
|
46 |
+
raise HTTPException(status_code=500, detail="Error procesando la imagen.")
|
47 |
|
|
|
48 |
@app.get("/")
|
49 |
async def root():
|
50 |
return {"message": "API de generaci贸n de mapas de profundidad con Marigold"}
|