From 7cc9df0c5a4dd35aab9729b1984b7aa19a95a788 Mon Sep 17 00:00:00 2001 From: "gireg.roussel" Date: Tue, 14 Jan 2025 09:42:33 +0100 Subject: [PATCH] rebase main --- edge_streamlit/Dockerfile | 8 +-- edge_streamlit/app-basic.py | 108 ------------------------------------ edge_streamlit/app.py | 5 +- edge_streamlit/utils.py | 44 --------------- 4 files changed, 2 insertions(+), 163 deletions(-) delete mode 100644 edge_streamlit/app-basic.py delete mode 100644 edge_streamlit/utils.py diff --git a/edge_streamlit/Dockerfile b/edge_streamlit/Dockerfile index de4561ae..8bdcf855 100644 --- a/edge_streamlit/Dockerfile +++ b/edge_streamlit/Dockerfile @@ -12,12 +12,6 @@ RUN apt-get update && apt-get install -y \ build-essential \ curl \ software-properties-common \ - # ffmpeg \ - # libsm6 \ - # libxext6 \ - # fswebcam \ - # libpq-dev \ - # libnuma-dev \ git \ && rm -rf /var/lib/apt/lists/* @@ -32,4 +26,4 @@ EXPOSE 8501 HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health -ENTRYPOINT ["streamlit", "run", "app-basic.py"] +ENTRYPOINT ["streamlit", "run", "app.py"] diff --git a/edge_streamlit/app-basic.py b/edge_streamlit/app-basic.py deleted file mode 100644 index a225c37c..00000000 --- a/edge_streamlit/app-basic.py +++ /dev/null @@ -1,108 +0,0 @@ -import json -import time -import requests -import streamlit as st -from prediction_boxes import filtering_items_that_have_predictions, plot_predictions -from PIL import Image -from io import BytesIO - -# Page configuration -st.set_page_config(page_title="VIO-edge", page_icon="🔦", layout="wide") - -# URL_ORCH = "http://localhost:8000/api/v1/" -URL_ORCH = "http://edge_orchestrator:8000/api/v1/" - -url_config = URL_ORCH + "configs" -url_active_config = URL_ORCH + "configs/active" -url_trigger = URL_ORCH + "trigger" - - -def main(): - """ - Fonction principale de l'application Streamlit. - """ - # Init variables - active_config = json.loads(requests.get(url_active_config).text) - if active_config: - st.session_state.active_config = active_config - - if "active_config" not in st.session_state: - st.session_state.active_config = None - if "trigger" not in st.session_state: - st.session_state.trigger = False - if "item_id" not in st.session_state: - st.session_state.item_id = None - - col1, col2, col3 = st.columns(3) - - configs = json.loads(requests.get(url_config).text) - - active_config_index = 0 - if st.session_state.active_config: - active_config_name = st.session_state.active_config.get('name') - active_config_index = next((index for (index, config) in enumerate(configs.values()) if config["name"] == active_config_name), 0) - option = col1.selectbox("Select an option", tuple(configs), index=active_config_index, label_visibility="collapsed") - - if col2.button("Active", use_container_width=True, ): - st.session_state.item_id = None - body = { - "config_name": option - } - requests.post(url=url_active_config, json=body) - st.session_state.active_config = json.loads(requests.get(url_active_config).text) - - if st.session_state.active_config: - active_config_name = st.session_state.active_config.get('name') - col2.write(f"active config: {active_config_name}") - - - if st.session_state.active_config: - if col3.button("Trigger", use_container_width=True): - st.session_state.trigger = True - response = requests.post(url_trigger) - item_id = response.json().get("item_id") - st.session_state.item_id = item_id - col3.write(f"item id: {item_id}") - - # TODO: Add camera inputs - - columns = st.columns(2) - - if st.session_state.item_id and (st.session_state.active_config is not None): - print("cameras", st.session_state.active_config["cameras"]) - - time.sleep(10) - - url_metadata = URL_ORCH + f"items/{st.session_state.item_id}" - response = requests.get(url_metadata) - metadata = response.json() - decision = metadata["decision"] - inferences = metadata["inferences"] - - print("decision", decision) - print("inferences", inferences) - - cameras = st.session_state.active_config["cameras"] - for i, camera in enumerate(cameras): - print("camera", camera) - url_binaries = URL_ORCH + f"items/{st.session_state.item_id}/binaries/{camera}" - response = requests.get(url_binaries) - image = response.content - # If metadata is not empty, we plot the predictions - if filtering_items_that_have_predictions(metadata, camera): - image = Image.open(BytesIO(image)) - image = plot_predictions(image, camera, metadata) - columns[i].image(image, channels="BGR", width=450) - if inferences.get(camera): - columns[i].markdown(inferences[camera]) - - st.markdown( - f"

{decision}

", - unsafe_allow_html=True, - ) - - # TODO: add prediction on picture - -# Exécution du script principal -if __name__ == "__main__": - main() diff --git a/edge_streamlit/app.py b/edge_streamlit/app.py index 4698ac89..ed92e917 100644 --- a/edge_streamlit/app.py +++ b/edge_streamlit/app.py @@ -1,6 +1,3 @@ -from utils import display_camera_checkboxes, list_cameras -import streamlit as st -import requests import json import os import time @@ -110,4 +107,4 @@ def main(): if __name__ == "__main__": - main() + main() \ No newline at end of file diff --git a/edge_streamlit/utils.py b/edge_streamlit/utils.py deleted file mode 100644 index a5398ce7..00000000 --- a/edge_streamlit/utils.py +++ /dev/null @@ -1,44 +0,0 @@ -import logging -from typing import List - -import cv2 -import streamlit as st - -logger = logging.getLogger(__name__) -logger.addHandler(logging.StreamHandler()) -logger.setLevel(logging.DEBUG) - - -def list_cameras() -> List[str]: - """ - Liste toutes les caméras disponibles sur le système. - """ - logger.info("Listing available cameras") - index = 0 - available_cameras = [] - while True: - cap = cv2.VideoCapture(index) - if cap.isOpened(): - available_cameras.append(f"Cam {index}") - else: - break - cap.release() - index += 1 - logger.debug(f"{len(available_cameras)} cameras found") - return available_cameras - - -def display_camera_checkboxes(available_cameras: List[str]) -> List[int]: - """ - Affiche les caméras disponibles sous forme de cases à cocher. - Retourne les indices des caméras sélectionnées. - """ - selected_cameras = [] - if len(available_cameras) == 0: - st.warning("No camera detected.") - else: - for i, camera_name in enumerate(available_cameras): - if st.sidebar.checkbox(camera_name, key=f"camera_{i}"): - selected_cameras.append(i) - logger.debug(f"Selected cameras are {selected_cameras}") - return selected_cameras