File size: 2,259 Bytes
dbf451c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
091632c
 
 
 
 
dbf451c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160167f
dbf451c
8a85af4
dbf451c
 
 
 
 
 
 
 
 
 
091632c
dbf451c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 shutil
# import cv2
# from PIL import Image
# from collections import deque, Counter

import time, os, json, onnx, onnxruntime
# import torch
import pandas as pd
import streamlit as st
import requests
from utils import *
import args
from streamlit_lottie import st_lottie

st.set_page_config(
    page_title=args.PAGE_TITLE,
    page_icon=args.PAGE_ICON, layout=args.LAYOUT, initial_sidebar_state='auto'
)


def load_lottieurl(url: str):
    r = requests.get(url)
    if r.status_code != 200:
        return None
    return r.json()


# Configure
options = onnxruntime.SessionOptions()
options.intra_op_num_threads = 8
options.inter_op_num_threads = 8

lottie_penguin = load_lottieurl('https://assets10.lottiefiles.com/datafiles/Yv8B88Go8kHRZ5T/data.json')
st_lottie(lottie_penguin, height=200)

hide_streamlit_style = """
    <style>
    footer {
    visibility: hidden;
        }
    footer:after {
        content:'© 2021 Vu Minh Chien';
        visibility: visible;
        display: block;
        position: relative;
        #background-color: red;
        padding: 5px;
        top: 2px;
            }
    </style>
    """
st.markdown(hide_streamlit_style, unsafe_allow_html=True)

st.write(args.LANDINGPAGE_TITLE)
st.sidebar.title(args.SIDEBAR_TITLE)
method = st.sidebar.radio('Choose input source 👇', options=['Image'])


# Load model
@st.cache(suppress_st_warning=False)
def initial_setup():
    df_train = pd.read_csv('full_set.csv')
    sub_test_list = sorted(list(df_train['Image'].map(lambda x: get_image(x))))
    with open('embeddings.npy', 'rb') as f:
        embeddings = np.load(f)
    PATH = 'model_onnx.onnx'
    ort_session = onnxruntime.InferenceSession(PATH, sess_options=options)
    input_name = ort_session.get_inputs()[0].name
    return df_train, sub_test_list, embeddings, ort_session, input_name


df_train, sub_test_list, embeddings, ort_session, input_name = initial_setup()

if method == 'Image':
    st.sidebar.markdown('---')
    st.sidebar.header('Options')
    content_file, col2 = show_original()
    image_input(
        content_file, df_train, sub_test_list, embeddings, ort_session, input_name, col2
    )
else:
    webcam_input(
        df_train, sub_test_list, embeddings, ort_session, input_name
    )