-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
85 lines (73 loc) · 3.26 KB
/
app.py
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import streamlit as st
import io
from PIL import Image
from utils import *
# Configura el favicon de la aplicación
favicon = open("logos/favicon.ico", "rb").read()
st.set_page_config(page_title="Registrado en PoH?", page_icon=favicon)
# agrego logo
logo = Image.open("logos/democratic-poh-logo-text-hi-res-p-500.png")
st.image(logo, use_column_width=True)
# Titulo en color verde
st.markdown(
"<h1 style='color: green;'>Registered with Proof of Humanity?</h1>",
unsafe_allow_html=True,
)
def process_image(path):
try:
_models = FaceNetModels()
img = Image.open(path)
# Verificar si la imagen está en formato PNG y convertir a JPG si es necesario
if img.format == "PNG":
jpg_io = (
io.BytesIO()
) # Crear un objeto BytesIO para guardar la imagen en memoria
img = img.convert(
"RGB"
) # Convertir a modo RGB (requerido para guardar como JPG)
img.save(
jpg_io, format="JPEG"
) # Guardar la imagen en el objeto BytesIO en formato JPG
jpg_io.seek(0) # Colocar el puntero de lectura al inicio del objeto BytesIO
img = Image.open(
jpg_io
) # Abrir la imagen en formato JPG desde el objeto BytesIO
image_embedding = _models.embedding(_models.mtcnn(img))
return _models.Distancia(image_embedding)
except:
return None
def upload_image():
uploaded_file = st.file_uploader(
"Upload the image of a Human and verify if it is registered in https://app.proofofhumanity.id/",
type=["jpg", "png"],
)
print(uploaded_file)
if uploaded_file is not None:
image = Image.open(uploaded_file)
st.image(image, caption="uploaded image ", width=200)
result = process_image(uploaded_file)
if result:
label, distance = result
url = f"https://app.proofofhumanity.id/profile/{label}"
st.markdown(
f'<a href="{url}" target="_blank">https://app.proofofhumanity.id/profile/{label}</a>',
unsafe_allow_html=True,
)
st.write("% Similitud: ", int(100- 17.14*distance))
else:
st.write(
"Something went wrong with the provided image, please try another!!"
)
# información adicional
with st.expander("Información adicional"):
st.write(
"This application uses the neural network model known as ResNet"
+ "to recognize features of faces in images. With this technology, a dictionary was built that the app uses "
+ "to compare with the features of the face entered by the user. "
+ "The user can upload an image from their device or use the camera to take a photo, and the application "
+ "will return the closest PoH profile to the one in the database along with the Euclidean distance between the two faces."
+ "If the image corresponds to a registered human, the face will be recognized in correspondence with a very low Euclidean distance, close to zero."
"At the moment 17 thousand registered in PoH are recognized, the database will be updated every thousand new registered."
)
# lanza app
upload_image()