Spaces:
Sleeping
Sleeping
jcmachicao
commited on
Commit
•
9dce852
1
Parent(s):
86af259
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# -*- coding: utf-8 -*-
|
2 |
+
"""
|
3 |
+
José Carlos Machicao
|
4 |
+
GestioDinámica
|
5 |
+
Fecha de producción: 2021_08_28
|
6 |
+
Fecha de actualización 2021_12_29
|
7 |
+
Ubicación Original: PythonScripts/gdmk_facerecog/
|
8 |
+
"""
|
9 |
+
|
10 |
+
import streamlit as st
|
11 |
+
import face_recognition
|
12 |
+
from PIL import Image
|
13 |
+
import numpy as np
|
14 |
+
import pandas as pd
|
15 |
+
import datetime
|
16 |
+
import base64
|
17 |
+
import pickle
|
18 |
+
|
19 |
+
# FUNCTIONS
|
20 |
+
def genera_imagenes_base(up_files):
|
21 |
+
ims = []
|
22 |
+
lista_fotos = []
|
23 |
+
codes = []
|
24 |
+
for imk in up_files:
|
25 |
+
lista_fotos.append(imk.name)
|
26 |
+
imagex = face_recognition.load_image_file(imk)
|
27 |
+
facecodex = face_recognition.face_encodings(imagex)[0]
|
28 |
+
codes.append(facecodex)
|
29 |
+
imsh = Image.open(imk)
|
30 |
+
ims.append(imsh)
|
31 |
+
codtot = pd.DataFrame()
|
32 |
+
codtot['lista'] = lista_fotos
|
33 |
+
codtot['imagenes'] = ims
|
34 |
+
codtot['codigos'] = codes
|
35 |
+
return codtot
|
36 |
+
|
37 |
+
# BODY
|
38 |
+
st.image('images/uc_logo.jpg', width=150)
|
39 |
+
|
40 |
+
st.subheader('Aplicativos de Reconocimiento Facial')
|
41 |
+
st.title('Generación de Base Tensores')
|
42 |
+
|
43 |
+
# 1. IDENTIDAD BASE
|
44 |
+
st.subheader('**Procedimiento: Generación de Identidad Digital Base**')
|
45 |
+
|
46 |
+
nom_oper = st.text_input('Nombre del Comparador(a) que realizará evaluación')
|
47 |
+
nom_oper = nom_oper.replace(' ', '')
|
48 |
+
|
49 |
+
up_files = st.file_uploader('Elija archivos base hasta 50 items: ', accept_multiple_files=True)
|
50 |
+
|
51 |
+
if not up_files:
|
52 |
+
l_pics = 1
|
53 |
+
for i, col in enumerate(st.columns(1)):
|
54 |
+
col.image('images/void.jpg', width=150)
|
55 |
+
else:
|
56 |
+
|
57 |
+
codtotx = genera_imagenes_base(up_files)
|
58 |
+
|
59 |
+
n_fil = 5
|
60 |
+
l_pics = int(len(codtotx.lista))
|
61 |
+
filas = int(np.round(l_pics/n_fil,0)) + 1
|
62 |
+
st.write(l_pics)
|
63 |
+
st.write('Procesando imagenes...')
|
64 |
+
imagenes = list(codtotx.imagenes)
|
65 |
+
|
66 |
+
for fila in range(filas):
|
67 |
+
st.write(fila)
|
68 |
+
for i, col in enumerate(st.columns(n_fil)):
|
69 |
+
try:
|
70 |
+
col.image(up_files[i+fila*n_fil], width=150)
|
71 |
+
except:
|
72 |
+
pass
|
73 |
+
|
74 |
+
st.write('Reportando: Archivo Base Generado')
|
75 |
+
|
76 |
+
timestamp = datetime.datetime.now()
|
77 |
+
ts = timestamp.strftime('%Y_%m_%d_%H_%M')
|
78 |
+
#nom_archivo = 'tensores_base_' + ts + '_' + nom_oper + '.pkl'
|
79 |
+
st.write('Archivo generado por: ', nom_oper)
|
80 |
+
st.write('Tiempo de generación: ', ts)
|
81 |
+
|
82 |
+
output_pkl = pickle.dumps(codtotx)
|
83 |
+
b64 = base64.b64encode(output_pkl).decode()
|
84 |
+
href = f'<a href="data:file/output_model;base64,{b64}" download="tensores.pkl">Descargar Tensores PKL</a>'
|
85 |
+
st.markdown(href, unsafe_allow_html=True)
|
86 |
+
|
87 |
+
c1, c2, c3 = st.columns(3)
|
88 |
+
with c1:
|
89 |
+
st.write(' ')
|
90 |
+
with c2:
|
91 |
+
st.write(' ')
|
92 |
+
with c3:
|
93 |
+
st.write(' ')
|
94 |
+
st.image('images/gdmk.png', width=100, caption='Designed and Powered by GestioDinámica')
|