File size: 2,300 Bytes
57d7ed3
 
9acc552
57d7ed3
 
 
 
 
9acc552
 
 
99cd14f
 
 
 
 
7ee620d
9acc552
57d7ed3
 
 
 
 
7ee620d
9acc552
57d7ed3
7ee620d
 
 
 
99cd14f
f0adec0
 
99cd14f
 
f0adec0
99cd14f
 
 
57d7ed3
99cd14f
3733e70
7ee620d
57d7ed3
7ee620d
57d7ed3
 
99cd14f
 
 
 
 
 
 
 
9acc552
5f721d1
57d7ed3
 
 
99cd14f
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
import sys
import os.path as osp
import streamlit as st

root_path = osp.abspath(osp.join(__file__, osp.pardir))
sys.path.append(root_path)

from registry_utils import import_registered_modules
from app_utils import (
    is_image,
    is_video,
    process_image_and_vizualize_data,
    process_video_and_visualize_data,
    set_frames_processed_count_placeholder,
    set_input_image_on_ui,
    set_input_video_on_ui,
    set_page_info_and_sidebar_info,
)

import_registered_modules()


def main():
    cols, video_path, uploaded_file, pupil_selection, tv_model, blink_detection = set_page_info_and_sidebar_info()

    if uploaded_file is not None:
        try:
            file_extension = uploaded_file.name.split(".")[-1]
        except Exception:
            file_extension = video_path.split(".")[-1]
        st.session_state["file_extension"] = file_extension

        if is_image(file_extension):
            input_img = set_input_image_on_ui(uploaded_file, cols)
            st.session_state["input_img"] = input_img
        elif is_video(file_extension):
            video_frames, video_path = set_input_video_on_ui(uploaded_file, cols)
            st.session_state["video_frames"] = video_frames
            st.session_state["video_path"] = video_path

        set_frames_processed_count_placeholder(cols)

    if st.sidebar.button("Predict Diameter & Compute CAM", type="primary"):
        if uploaded_file is None:
            st.sidebar.error("Please select / upload an image or video")
        else:
            with st.spinner("Analyzing..."):
                if is_image(st.session_state.get("file_extension")):
                    input_img = st.session_state.get("input_img")
                    process_image_and_vizualize_data(cols, input_img, tv_model, pupil_selection, blink_detection)
                elif is_video(st.session_state.get("file_extension")):
                    video_frames = st.session_state.get("video_frames")
                    video_path = st.session_state.get("video_path")
                    process_video_and_visualize_data(
                        cols, video_frames, tv_model, pupil_selection, blink_detection, video_path
                    )


if __name__ == "__main__":
    main()
# run: streamlit run app.py --server.enableXsrfProtection false