update
Browse files
app.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
#!/usr/bin/env python
|
2 |
# -*- coding: utf-8 -*-
|
3 |
"""
|
4 |
-------------------------------------------------
|
@@ -8,22 +7,55 @@
|
|
8 |
@Description:
|
9 |
-------------------------------------------------
|
10 |
"""
|
|
|
|
|
|
|
11 |
from pathlib import Path
|
12 |
from PIL import Image
|
13 |
import streamlit as st
|
14 |
|
15 |
import config
|
16 |
from utils import load_model, infer_uploaded_image, infer_uploaded_video, infer_uploaded_webcam
|
17 |
-
from download_gd import *
|
18 |
import os
|
19 |
|
20 |
-
|
21 |
-
|
|
|
|
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
# setting page layout
|
29 |
st.set_page_config(
|
@@ -34,31 +66,34 @@ st.set_page_config(
|
|
34 |
)
|
35 |
|
36 |
# main page heading
|
37 |
-
st.title(
|
38 |
|
39 |
# sidebar
|
40 |
st.sidebar.header("DL Model Config")
|
41 |
|
42 |
# model options
|
43 |
task_type = "Detection"
|
44 |
-
|
|
|
|
|
|
|
45 |
|
46 |
confidence = float(st.sidebar.slider(
|
47 |
"Select Model Confidence", 30, 100, 50)) / 100
|
48 |
|
49 |
if model_type:
|
50 |
#model_path = Path(config.DETECTION_MODEL_DIR, str(model_type))
|
51 |
-
model_path =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
else:
|
53 |
st.error("Please Select Model in Sidebar")
|
54 |
|
55 |
-
# load pretrained DL model
|
56 |
-
try:
|
57 |
-
print('model_path', model_path)
|
58 |
-
model = load_model(model_path)
|
59 |
-
except Exception as e:
|
60 |
-
st.error(f"Unable to load model. Please check the specified path: {model_path}")
|
61 |
-
|
62 |
# image/video options
|
63 |
st.sidebar.header("Image/Video Config")
|
64 |
source_selectbox = st.sidebar.selectbox(
|
|
|
|
|
1 |
# -*- coding: utf-8 -*-
|
2 |
"""
|
3 |
-------------------------------------------------
|
|
|
7 |
@Description:
|
8 |
-------------------------------------------------
|
9 |
"""
|
10 |
+
#from dotenv import load_dotenv
|
11 |
+
#load_dotenv()
|
12 |
+
|
13 |
from pathlib import Path
|
14 |
from PIL import Image
|
15 |
import streamlit as st
|
16 |
|
17 |
import config
|
18 |
from utils import load_model, infer_uploaded_image, infer_uploaded_video, infer_uploaded_webcam
|
|
|
19 |
import os
|
20 |
|
21 |
+
base_download_path = "downloaded"
|
22 |
+
#------------------------
|
23 |
+
if not os.path.exists(base_download_path):
|
24 |
+
os.makedirs(base_download_path)
|
25 |
|
26 |
+
#model_count = int(os.getenv("model_count"))
|
27 |
+
model_count = int(st.secrets["model_count"])
|
28 |
+
|
29 |
+
model_info = {}
|
30 |
+
models_list = []
|
31 |
+
for i in range(0, model_count):
|
32 |
+
'''
|
33 |
+
model_name = os.getenv("m{}_name".format(i))
|
34 |
+
gdrive_id = os.getenv("m{}_griv".format(i))
|
35 |
+
model_extname = os.getenv("m{}_type".format(i))
|
36 |
+
model_desc = os.getenv("m{}_desc".format(i))
|
37 |
+
'''
|
38 |
+
model_name = st.secrets["m{}_name".format(i)]
|
39 |
+
gdrive_id = st.secrets["m{}_griv".format(i)]
|
40 |
+
model_extname = st.secrets["m{}_type".format(i)]
|
41 |
+
model_desc = st.secrets["m{}_desc".format(i)]
|
42 |
+
print(i, model_name, gdrive_id, model_extname, model_desc)
|
43 |
+
|
44 |
+
path_model = os.path.join(base_download_path, model_name + model_extname)
|
45 |
+
print('path_model', path_model)
|
46 |
+
model_info.update( {model_desc:path_model} )
|
47 |
+
models_list.append(model_desc)
|
48 |
+
|
49 |
+
if not os.path.exists(path_model):
|
50 |
+
download_link = "https://drive.google.com/uc?export=download&confirm=t&id={}".format(gdrive_id)
|
51 |
+
#subprocess.Popen( 'gdown {}'.format(download_link)
|
52 |
+
#if gdrive_id[:4] == "http":
|
53 |
+
print('wget -O {} --content-disposition "{}"'.format(path_model, download_link))
|
54 |
+
os.system( 'wget -O {} --content-disposition "{}"'.format(path_model, download_link))
|
55 |
+
#else:
|
56 |
+
# download_file_from_google_drive(gdrive_id, path_model)
|
57 |
+
|
58 |
+
print('models_list', models_list)
|
59 |
|
60 |
# setting page layout
|
61 |
st.set_page_config(
|
|
|
66 |
)
|
67 |
|
68 |
# main page heading
|
69 |
+
st.title("Models Demo")
|
70 |
|
71 |
# sidebar
|
72 |
st.sidebar.header("DL Model Config")
|
73 |
|
74 |
# model options
|
75 |
task_type = "Detection"
|
76 |
+
|
77 |
+
model_type = st.sidebar.selectbox(
|
78 |
+
"Model types",
|
79 |
+
tuple(models_list))
|
80 |
|
81 |
confidence = float(st.sidebar.slider(
|
82 |
"Select Model Confidence", 30, 100, 50)) / 100
|
83 |
|
84 |
if model_type:
|
85 |
#model_path = Path(config.DETECTION_MODEL_DIR, str(model_type))
|
86 |
+
model_path = model_info[model_type]
|
87 |
+
|
88 |
+
try:
|
89 |
+
print('model_path', model_path)
|
90 |
+
model = load_model(model_path)
|
91 |
+
except Exception as e:
|
92 |
+
st.error(f"Unable to load model. Please check the specified path: {model_path}")
|
93 |
+
|
94 |
else:
|
95 |
st.error("Please Select Model in Sidebar")
|
96 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
# image/video options
|
98 |
st.sidebar.header("Image/Video Config")
|
99 |
source_selectbox = st.sidebar.selectbox(
|