rad / app.py
Moibe's picture
Busqueda Multiple es AND por default e incluí el OR
d78e28f
raw
history blame
2.93 kB
import funciones
from io import BytesIO
from fastapi import FastAPI, Form
from fastapi import FastAPI, File, UploadFile
from fastapi.responses import StreamingResponse, JSONResponse
from fastapi import FastAPI, Depends, HTTPException, status
from fastapi.security.api_key import APIKeyHeader
API_KEY = "tu_super_secreta_clave_de_api"
api_key_header = APIKeyHeader(name="X-API-Key", auto_error=False)
async def get_api_key(api_key: str = Depends(api_key_header)):
if not api_key or api_key != API_KEY:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Credenciales de autenticación inválidas",
)
return api_key
#Y manda ésto en los headers:
#"X-API-Key": apiKey
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(...),
#api_key: str = Depends(get_api_key)
):
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(
"/identifica_documento/",
tags=["General"],
summary="Reconocimiento Avanzado de Documentos")
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.identifica_documento(image)
#PROCESA CUALQUIER DOCUMENTO, ESTABA LISTO PARA DNI Y PASAPORTE PERO LE FALTA INE, SE REANUDA CADA QUE ESTÉ AL DÍA.
# @app.post(
# "/procesa_documento/",
# tags=["General"],
# summary="Reconocimiento Avanzado de Documentos")
# 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)
@app.post(
"/procesa_ine/",
tags=["Zurich"],
summary="Documentos México")
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_ine(image)