|
|
|
import streamlit as st |
|
import tensorflow as tf |
|
import keras |
|
import numpy as np |
|
from PIL import Image |
|
|
|
import requests |
|
from streamlit_lottie import st_lottie |
|
|
|
|
|
def load_lottieurl(url): |
|
r = requests.get(url) |
|
if r.status_code != 200: |
|
return None |
|
return r.json() |
|
|
|
lottie_faces = load_lottieurl("https://lottie.host/7ea78645-0d4e-4648-a015-fb58331ac7d7/47FTHHimCQ.json") |
|
|
|
|
|
model = tf.keras.models.load_model("/content/modelo_celeba_50e.h5", compile=False) |
|
|
|
st.subheader("Machine Learning para Producci贸n - M贸dulo 03") |
|
st.markdown("<h5>Tarea Streamlit</h5>", unsafe_allow_html=True) |
|
st.write("---") |
|
|
|
with st.container(): |
|
columna_1, columna_2 = st.columns(2) |
|
with columna_1: |
|
st.title("Implementaci贸n CelebA") |
|
st.markdown("<h3>Clasificador de rostros</h3>", unsafe_allow_html=True) |
|
with columna_2: |
|
st_lottie(lottie_faces, height = 200, key= "faces") |
|
|
|
st.write(""" |
|
CelebA es un conjunto de datos de im谩genes de rostros de celebridades utilizado en inteligencia artificial para entrenar sistemas de reconocimiento facial y otras tareas relacionadas con la visi贸n por computadora. Contiene m谩s de 200,000 im谩genes etiquetadas con atributos como edad, g茅nero y expresi贸n facial. Es ampliamente utilizado por investigadores y desarrolladores en el campo del aprendizaje autom谩tico. |
|
""") |
|
st.write("---") |
|
|
|
with st.container(): |
|
uploaded_image = st.file_uploader("Cargar imagen") |
|
foto = uploaded_image |
|
|
|
with st.container(): |
|
column1, column2 = st.columns(2) |
|
|
|
if uploaded_image is not None: |
|
with column1: |
|
st.image(foto, use_column_width=True) |
|
|
|
with column2: |
|
|
|
image = Image.open(uploaded_image).convert('RGB') |
|
image = image.resize((178,218)) |
|
|
|
image = np.array(image)/255.0 |
|
image = np.expand_dims(image,axis=0) |
|
|
|
prediction = model.predict(image) |
|
st.markdown("<h3>Resultados</h3>", unsafe_allow_html=True) |
|
|
|
st.markdown("<h5>Atractivo</h5>", unsafe_allow_html=True) |
|
st.write(f"{np.round(prediction[0][0], 2)}%") |
|
if prediction[0][0] >= 0.5: |
|
st.write(f"Es una persona atractiva") |
|
else: |
|
st.write(f"No es alguien tan atractivo") |
|
|
|
st.markdown("<h5>Sexo</h5>", unsafe_allow_html=True) |
|
st.write(f"{np.round(prediction[0][1], 2)}%") |
|
if prediction[0][1] >= 0.5: |
|
st.write(f"Es Hombre") |
|
else: |
|
st.write(f"Es Mujer") |
|
|
|
st.markdown("<h5>Lentes</h5>", unsafe_allow_html=True) |
|
st.write(f"{np.round(prediction[0][2], 2)}%") |
|
if prediction[0][2] >= 0.5: |
|
st.write(f"Trae lentes") |
|
else: |
|
st.write(f"No trae lentes") |
|
|
|
st.markdown("<h5>Bigote / Barba</h5>", unsafe_allow_html=True) |
|
st.write(f"{np.round(prediction[0][3], 2)}%") |
|
if prediction[0][3] >= 0.5: |
|
st.write(f"Tiene un bigote") |
|
else: |
|
st.write(f"No tiene bigote") |
|
|
|
else: |
|
pass |
|
|
|
st.write("---") |
|
st.write(""" |
|
## <font size="4">*Este es un descargo de responsabilidad est谩ndar que puedes personalizar seg煤n tus necesidades. Aqu铆 puedes incluir cualquier informaci贸n relevante, advertencias legales, exenciones de responsabilidad, etc.*</font> |
|
""", unsafe_allow_html=True) |
|
|