-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp.py
90 lines (60 loc) · 3.62 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
86
87
88
import streamlit as st
from PIL import Image
import os
from src.save_img import save_uploaded_img_face1 , save_uploaded_img_face2
from src.similarity import Similarity
from src.option_menus import option_menus
from src.remove_ import remove
st.set_page_config(page_title="Two-Face-Similarity", page_icon=":👀:", layout="wide", initial_sidebar_state="expanded")
st.title('Two✌🏻Faces🙂(Similarity between two Faces)')
selected_mode , selected_model , selected_backend = option_menus()
remove()
st.markdown('>##### *Guide*: :choose Please add 2 Images and then click to show similarity button the model will show you similarity score between two Images that you have given. ')
if selected_mode == 'Pictures':
col1 ,col2 = st.columns(2)
with col1:
img1 = st.file_uploader('Upload Image',key='image1')
with col2:
img2 = st.file_uploader('Upload New Image ',key='image2')
if img1 and img2 is not None:
if save_uploaded_img_face1(img1) and save_uploaded_img_face2(img2):
display_img1 = Image.open(img1)
display_img2 = Image.open(img2)
col3 , col4 = st.columns(2)
with col3:
st.image(image=display_img1,width=350,channels='BGR',caption='Your Image')
with col4:
st.image(image=display_img2,width=350,channels='BGR',caption='Your New Image')
img1_path =os.path.join('images/uploaded_images/face1',img1.name)
img2_path =os.path.join('images/uploaded_images/face2',img2.name)
if st.button('Show Similarity'):
try:
sim = Similarity()
similarity_score = sim.similarity(img1=img1_path,img2=img2_path,backend=selected_backend,model=selected_model)
st.title(f'Similarity score: {similarity_score} %')
except Exception as e:
if selected_mode == 'VGG-Face' or selected_backend == 'opencv':
st.markdown(f'>### Please show your Face *Lazy Human🙄*. This model can only Show similarity by detecting face.')
else:
st.markdown(f'>### Please select another model Or backend.')
else:
col1 ,col2 = st.columns(2)
with col1:
img1_cam = st.camera_input('Please click Image',key='image111')
with col2:
img2_cam = st.camera_input('Please click new Image',key='image222')
if img1_cam and img2_cam is not None:
if save_uploaded_img_face1(img1_cam) and save_uploaded_img_face2(img2_cam):
img1_path =os.path.join('images/uploaded_images/face1',img1_cam.name)
img2_path =os.path.join('images/uploaded_images/face2',img2_cam.name)
if st.button('Show Similarity'):
try:
sim = Similarity()
similarity_score = sim.similarity(img1=img1_path,img2=img2_path,backend=selected_backend,model=selected_model)
st.markdown(f'>## 👀Similarity between faces is {similarity_score} % 👀\n made by 👨🏻💻Gyan Prakash Kushwaha ')
st.markdown(f"#### Utilizing the DeepFace Library, informed by a dataset of 4M images across 4K identities curated by Facebook researchers, My 'Two Faces✌🏻' project gauges facial similarity with precision.")
except Exception as e:
if selected_mode == 'VGG-Face' or selected_backend == 'opencv':
st.markdown(f'>### Please show your Face Lazy Human🙄 this model can only Show similarity by detecting face.')
else:
st.markdown(f'>### Please select another model Or backend.')