File size: 1,630 Bytes
4794a48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e8ff10d
4794a48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import cv2
import base64
from detection import *

background_image = """
<style>
[data-testid="stAppViewContainer"] > .main {
    background-image: url("https://images.pexels.com/photos/1054218/pexels-photo-1054218.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=2");
    background-size: cover;
    background-position: center;  
    background-repeat: no-repeat;
}
</style>
"""

st.markdown(background_image, unsafe_allow_html=True)

st.components.v1.html("<h1><center>Face Detection Web App</center></h1>")
vis = True
db_mode = st.checkbox("Add to data base")
if db_mode:
    vis = False
if not vis:
    st.html("<h3><center>Storing Image to Database</h3></center>")
input_method = st.checkbox("Camera Mode")
cam_inp , file_inp = None , None
if input_method:
    cam_inp = st.camera_input(label="Say Cheese!")
else:
    file_inp = st.file_uploader("Upload a Photo!")

if cam_inp != None:
    file = cam_inp
else:
    file = file_inp

if file and vis:
    min_conf = st.number_input("Enter the desired confidence value:" , min_value=0.0 , max_value=1.0, step=0.10, disabled= not vis , value=0.65)
    if min_conf:
        img , labels = detect_and_fetch(file , min_confidence= min_conf)
        st.image(img , caption='Detections' , use_column_width=True)
        st.header('Detected:')
        labels = set(labels)
        for i in labels:
            if i is not "Unknown":
                st.text(i)
else:
    name = st.text_input("Write the Name of Person" , disabled= vis)
    if name:
        process = write_and_upsert(file , name)
        if process:
            st.text("Uploaded Sucessfully!")