rad / app.py
Moibe's picture
Capacidad de procesar imagenes sin texto
b226794
raw
history blame
1.45 kB
from io import BytesIO
import funciones
from fastapi import FastAPI, Form
from fastapi import FastAPI, File, UploadFile
from fastapi.responses import StreamingResponse, FileResponse, JSONResponse
app = FastAPI()
# Nuevo endpoint para Health Check
@app.get("/health",
tags=["Health Check"],
description="Verifica el estado de salud de la API.",
summary="Health Check"
)
async def health_check():
"""
Este endpoint devuelve una respuesta 200 OK para indicar que la API está funcionando.
"""
return JSONResponse(content={"status": "ok"}, status_code=200)
@app.post("/echo-image/",
tags=["Health Check"],
description="Test endpoint que recibe y regresa la misma imagen, para probar envío, recepción y problemas con api o red.",
summary="Summary"
)
async def echo_image(image: UploadFile = File(...)):
if not image.content_type.startswith("image/"):
return {"error": "El archivo no es una imagen"}
contents = await image.read()
return StreamingResponse(BytesIO(contents), media_type=image.content_type)
@app.post(
"/procesa_documento/",
tags=["Rapicash"],
summary="Procesamiento de DNI")
async def procesa_documento(image: UploadFile = File(...)):
if not image.content_type.startswith("image/"):
return {"error": "El archivo no es una imagen"}
return await funciones.procesa_documento(image)