Se integra maquetado de pasaportes
Browse files- __pycache__/app.cpython-311.pyc +0 -0
- __pycache__/funciones.cpython-311.pyc +0 -0
- app.py +7 -7
- documentos.py +10 -1
- funciones.py +16 -15
- herramientas.py +17 -1
- obtenCampo.py +2 -0
__pycache__/app.cpython-311.pyc
CHANGED
Binary files a/__pycache__/app.cpython-311.pyc and b/__pycache__/app.cpython-311.pyc differ
|
|
__pycache__/funciones.cpython-311.pyc
CHANGED
Binary files a/__pycache__/funciones.cpython-311.pyc and b/__pycache__/funciones.cpython-311.pyc differ
|
|
app.py
CHANGED
@@ -36,10 +36,10 @@ async def procesa_dni(image: UploadFile = File(...)):
|
|
36 |
return {"error": "El archivo no es una imagen"}
|
37 |
return await funciones.procesa_dni(image)
|
38 |
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
|
|
36 |
return {"error": "El archivo no es una imagen"}
|
37 |
return await funciones.procesa_dni(image)
|
38 |
|
39 |
+
@app.post(
|
40 |
+
"/procesa_pasaporte/",
|
41 |
+
summary="Procesamiento de DNI")
|
42 |
+
async def procesa_pasaporte(image: UploadFile = File(...)):
|
43 |
+
if not image.content_type.startswith("image/"):
|
44 |
+
return {"error": "El archivo no es una imagen"}
|
45 |
+
return await funciones.procesa_pasaporte(image)
|
documentos.py
CHANGED
@@ -1,6 +1,15 @@
|
|
1 |
import obtenCampo
|
2 |
|
3 |
-
def dni(textos_extraidos):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
textos_extraidos_simplificados = [texto.lower().replace(" ", "") for texto in textos_extraidos]
|
5 |
|
6 |
#Campos Buscados
|
|
|
1 |
import obtenCampo
|
2 |
|
3 |
+
async def dni(textos_extraidos):
|
4 |
+
textos_extraidos_simplificados = [texto.lower().replace(" ", "") for texto in textos_extraidos]
|
5 |
+
|
6 |
+
#Campos Buscados
|
7 |
+
nombre, apellido = obtenCampo.Nombre(textos_extraidos, textos_extraidos_simplificados)
|
8 |
+
identificacion = obtenCampo.Identificacion(textos_extraidos, textos_extraidos_simplificados)
|
9 |
+
|
10 |
+
return nombre, apellido, identificacion
|
11 |
+
|
12 |
+
async def pasaporte(textos_extraidos):
|
13 |
textos_extraidos_simplificados = [texto.lower().replace(" ", "") for texto in textos_extraidos]
|
14 |
|
15 |
#Campos Buscados
|
funciones.py
CHANGED
@@ -1,29 +1,30 @@
|
|
1 |
import herramientas
|
2 |
import documentos
|
3 |
import time
|
4 |
-
from gradio_client import Client, handle_file
|
5 |
|
6 |
-
async def procesa_dni(image):
|
7 |
|
8 |
-
|
9 |
|
10 |
-
|
11 |
-
dict_recibido = client.predict(
|
12 |
-
img=handle_file(temp_image),
|
13 |
-
lang="en",
|
14 |
-
api_name="/predict"
|
15 |
-
) #Ésto porque gradio envía un dict con headers y su key data es el que contiene nuestro result original que tenía en la API original.
|
16 |
-
|
17 |
-
#Aquí es donde personalizo el proceso:
|
18 |
-
textos_extraidos = herramientas.listaTextosExtraidos(dict_recibido)
|
19 |
|
20 |
#Campos DNI Panamá.
|
21 |
-
nombre, apellido, identificacion = documentos.dni(textos_extraidos)
|
22 |
-
|
23 |
-
print(f"Hola: {nombre}, {apellido} con identificación: {identificacion}")
|
24 |
|
25 |
return {
|
26 |
"nombre": nombre,
|
27 |
"apellido": apellido,
|
28 |
"identificacion": identificacion
|
29 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import herramientas
|
2 |
import documentos
|
3 |
import time
|
|
|
4 |
|
|
|
5 |
|
6 |
+
async def procesa_dni(image):
|
7 |
|
8 |
+
textos_extraidos = await herramientas.procesaImagen(image)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
#Campos DNI Panamá.
|
11 |
+
nombre, apellido, identificacion = await documentos.dni(textos_extraidos)
|
|
|
|
|
12 |
|
13 |
return {
|
14 |
"nombre": nombre,
|
15 |
"apellido": apellido,
|
16 |
"identificacion": identificacion
|
17 |
}
|
18 |
+
|
19 |
+
async def procesa_pasaporte(image):
|
20 |
+
|
21 |
+
textos_extraidos = await herramientas.procesaImagen(image)
|
22 |
+
|
23 |
+
#Campos DNI Panamá.
|
24 |
+
nombre, apellido, identificacion = await documentos.pasaporte(textos_extraidos)
|
25 |
+
|
26 |
+
return {
|
27 |
+
"nombre": nombre,
|
28 |
+
"apellido": apellido,
|
29 |
+
"identificacion": identificacion
|
30 |
+
}
|
herramientas.py
CHANGED
@@ -1,5 +1,7 @@
|
|
1 |
import tempfile
|
2 |
import time
|
|
|
|
|
3 |
|
4 |
async def imageToTemp(image):
|
5 |
print("Estoy en imageToTemp...")
|
@@ -44,4 +46,18 @@ def buscarPatronCedula(lista_textos):
|
|
44 |
for i, texto in enumerate(lista_textos):
|
45 |
if texto and texto[0].isdigit() and '-' in texto:
|
46 |
return i
|
47 |
-
return 'error'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import tempfile
|
2 |
import time
|
3 |
+
import herramientas
|
4 |
+
from gradio_client import Client, handle_file
|
5 |
|
6 |
async def imageToTemp(image):
|
7 |
print("Estoy en imageToTemp...")
|
|
|
46 |
for i, texto in enumerate(lista_textos):
|
47 |
if texto and texto[0].isdigit() and '-' in texto:
|
48 |
return i
|
49 |
+
return 'error'
|
50 |
+
|
51 |
+
async def procesaImagen(image):
|
52 |
+
|
53 |
+
temp_image = await imageToTemp(image)
|
54 |
+
|
55 |
+
client = Client("Moibe/api_rapicash")
|
56 |
+
dict_recibido = client.predict(
|
57 |
+
img=handle_file(temp_image),
|
58 |
+
lang="en",
|
59 |
+
api_name="/predict"
|
60 |
+
)
|
61 |
+
#Aquí es donde personalizo el proceso:
|
62 |
+
textos_extraidos = listaTextosExtraidos(dict_recibido)
|
63 |
+
return textos_extraidos
|
obtenCampo.py
CHANGED
@@ -1,5 +1,7 @@
|
|
1 |
import herramientas
|
2 |
|
|
|
|
|
3 |
def Nombre(textos_extraidos, textos_extraidos_limpios):
|
4 |
indice = herramientas.buscaIndexPalabra(textos_extraidos_limpios, 'usual')
|
5 |
print(f"Indice es: {indice} y es del tipo {type(indice)}...")
|
|
|
1 |
import herramientas
|
2 |
|
3 |
+
|
4 |
+
#Campos para DNI.
|
5 |
def Nombre(textos_extraidos, textos_extraidos_limpios):
|
6 |
indice = herramientas.buscaIndexPalabra(textos_extraidos_limpios, 'usual')
|
7 |
print(f"Indice es: {indice} y es del tipo {type(indice)}...")
|