File size: 1,821 Bytes
8b73048
5b91cf1
8b73048
 
5b91cf1
c7632e7
8b73048
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d56556d
8b73048
 
 
 
 
 
 
c2ff93d
 
93a5ed3
 
 
 
 
 
 
 
 
c2ff93d
b226794
5b91cf1
 
b226794
c2ff93d
 
b226794
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import funciones
from io import BytesIO
from fastapi import FastAPI, Form
from fastapi import FastAPI, File, UploadFile
from fastapi.responses import StreamingResponse, 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(
        "/identifica_documento/", 
        tags=["Documentos"],       
        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)

@app.post(
        "/procesa_documento/", 
        tags=["Documentos"],       
        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)