Spaces:
Sleeping
Sleeping
# -*- coding: utf-8 -*- | |
""" | |
Jos茅 Carlos Machicao | |
GestioDin谩mica | |
Fecha de producci贸n: 2021_08_28 | |
Fecha de actualizaci贸n 2021_12_29 | |
Ubicaci贸n Original: PythonScripts/gdmk_facerecog/ | |
""" | |
import streamlit as st | |
import face_recognition | |
from PIL import Image | |
import numpy as np | |
import pandas as pd | |
import datetime | |
import base64 | |
import pickle | |
# FUNCTIONS | |
def genera_imagenes_base(up_files): | |
ims = [] | |
lista_fotos = [] | |
codes = [] | |
for imk in up_files: | |
lista_fotos.append(imk.name) | |
imagex = face_recognition.load_image_file(imk) | |
facecodex = face_recognition.face_encodings(imagex)[0] | |
codes.append(facecodex) | |
imsh = Image.open(imk) | |
ims.append(imsh) | |
codtot = pd.DataFrame() | |
codtot['lista'] = lista_fotos | |
codtot['imagenes'] = ims | |
codtot['codigos'] = codes | |
return codtot | |
# BODY | |
st.image('images/uc_logo.jpg', width=150) | |
st.subheader('Aplicativos de Reconocimiento Facial') | |
st.title('Generaci贸n de Base Tensores') | |
# 1. IDENTIDAD BASE | |
st.subheader('**Procedimiento: Generaci贸n de Identidad Digital Base**') | |
up_files = st.file_uploader('Elija archivos base hasta 50 items: ', accept_multiple_files=True) | |
if not up_files: | |
l_pics = 1 | |
for i, col in enumerate(st.columns(1)): | |
col.image('images/void.jpg', width=150) | |
else: | |
codtotx = genera_imagenes_base(up_files) | |
n_fil = 5 | |
l_pics = int(len(codtotx.lista)) | |
filas = int(np.round(l_pics/n_fil,0)) + 1 | |
st.write(l_pics) | |
st.write('Procesando imagenes...') | |
imagenes = list(codtotx.imagenes) | |
for fila in range(filas): | |
st.write(fila) | |
for i, col in enumerate(st.columns(n_fil)): | |
try: | |
col.image(up_files[i+fila*n_fil], width=150) | |
except: | |
pass | |
st.write('Reportando: Archivo Base Generado') | |
timestamp = datetime.datetime.now() | |
ts = timestamp.strftime('%Y_%m_%d_%H_%M') | |
#nom_archivo = 'tensores_base_' + ts + '_' + nom_oper + '.pkl' | |
st.write('Archivo generado por: ', nom_oper) | |
st.write('Tiempo de generaci贸n: ', ts) | |
output_pkl = pickle.dumps(codtotx) | |
b64 = base64.b64encode(output_pkl).decode() | |
href = f'<a href="data:file/output_model;base64,{b64}" download="tensores.pkl">Descargar Tensores PKL</a>' | |
st.markdown(href, unsafe_allow_html=True) | |
c1, c2, c3 = st.columns(3) | |
with c1: | |
st.write(' ') | |
with c2: | |
st.write(' ') | |
with c3: | |
st.write(' ') | |
st.image('images/gdmk.png', width=100, caption='Designed and Powered by GestioDin谩mica') | |