pupilsense / app.py
vijul.shah
Added Suport for Sample Library
7ee620d
raw
history blame
2.3 kB
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