diff --git a/ai/ai-vision/video-stream-analysis/LICENSE b/ai/ai-vision/video-stream-analysis/LICENSE new file mode 100644 index 000000000..46c0c79d9 --- /dev/null +++ b/ai/ai-vision/video-stream-analysis/LICENSE @@ -0,0 +1,35 @@ +Copyright (c) 2025 Oracle and/or its affiliates. + +The Universal Permissive License (UPL), Version 1.0 + +Subject to the condition set forth below, permission is hereby granted to any +person obtaining a copy of this software, associated documentation and/or data +(collectively the "Software"), free of charge and under any and all copyright +rights in the Software, and any and all patent rights owned or freely +licensable by each licensor hereunder covering either (i) the unmodified +Software as contributed to or provided by such licensor, or (ii) the Larger +Works (as defined below), to deal in both + +(a) the Software, and +(b) any piece of software and/or hardware listed in the lrgrwrks.txt file if +one is included with the Software (each a "Larger Work" to which the Software +is contributed by such licensors), + +without restriction, including without limitation the rights to copy, create +derivative works of, display, perform, and distribute the Software and make, +use, sell, offer for sale, import, export, have made, and have sold the +Software and the Larger Work(s), and to sublicense the foregoing rights on +either these or other terms. + +This license is subject to the following condition: +The above copyright notice and either this complete permission notice or at +a minimum a reference to the UPL must be included in all copies or +substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/ai/ai-vision/video-stream-analysis/README.md b/ai/ai-vision/video-stream-analysis/README.md new file mode 100644 index 000000000..b699ee36a --- /dev/null +++ b/ai/ai-vision/video-stream-analysis/README.md @@ -0,0 +1,96 @@ +# OCI Vision Streaming Setup and Consumption + +## Quick Start Guide + +- The code files in this demo are + - OCIVisionStreamSetup.ipynb - Notebook containing cells to run to start the stream job(streaming frames from the RTSP server to the OCI Vision). + - Stream-analysis.py - Streamlit application that can be used to consume the generated outputs of stream video analysis + +## 1. Region Selection + +OCI Vision Streaming is available in multiple regions. + +- For the **simplest setup**, run your pipeline within the **Ashburn** region. + No subnet or private endpoint creation is required in Ashburn. + +- To run in a region other than Ashburn, **[follow these steps](https://docs.oracle.com/en-us/iaas/Content/vision/using/video-stream-processing-top.htm)**. + > _Running in other regions may require additional VCN/Subnet/Endpoint configuration._ + +--- + +## 2. Prerequisites + +- **An active RTSP stream URL** (e.g., from an IP camera or RTSP streaming source) +- Access to a **Jupyter environment** +- Required permissions in your OCI compartment to use Vision, Stream Jobs, and Object Storage buckets + +--- + +## 3. Setting up the Vision Streaming Job + +1. **Open the** `OCIVisionStreamSetup.ipynb` **notebook in Jupyter**. + +2. **Fill out the required fields at the top of the notebook:** + + - `CONFIG_PROFILE` — OCI CLI profile to use (e.g., `"DEFAULT"`) + - `COMPARTMENT_ID` — your OCI compartment's OCID + - `STREAM_JOB_DISPLAY_NAME` — a display name for your stream job + - `CAMERA_URL` — your RTSP stream URL + - `NAMESPACE` — your Object Storage namespace + - `BUCKET` — target Object Storage bucket + - `PREFIX` — (Optional) Prefix for output files in Object Storage + - `FEATURES` — Detection features (`face`, `object`, etc.) + +3. **Run the following notebook cells in order:** + - Create Stream Source + - Create Stream Job + - Run Stream Job + + _This will start streaming frames from your camera to OCI Vision for detection (e.g., face or object recognition). The results (bounding box coordinates, frame encodings, etc.) will be stored as JSON files in the specified Object Storage bucket._ + +--- + +## 4. Consuming Streams with Streamlit + + Install the required dependencies by running + + pip install -r requirements.txt + + +While the stream job is active: + +1. **Start the Streamlit app (in terminal):** + ```bash + streamlit run streamlit_app.py +2. In the Streamlit UI, enter the following: + - Stream Job OCID + - Bucket Name + - Prefix (Object Storage path, if applicable) + - Object Storage Namespace + - Detection Type: choose between "Object Detection" or "Face Detection" +3. Click on Consume Stream The video with detected objects/faces will appear in your browser as annotated frames. +Note: Frames may appear slow; OCI Vision Streaming currently supports a maximum of 2 frames per second. +- Depending on whether you selected object detection or face detection in the features during the creation of the stream job, select the appropriate radio button to get the relevant analytics. +![UI Screenshot](./media/appUI.png) + + +## 5. Resource Management — Important! +Stop the Stream Job when finished! +Leaving it running will keep streaming data into your bucket, leading to large storage consumption. +Clean up resources: +Use the notebook cells to delete the Stream Job and Stream Source. +Optionally, store the OCIDs of created resources and reuse them to avoid recreating each time. + + +## 6. References +- [OCI Vision Stream Analysis Documentation](https://docs.oracle.com/en-us/iaas/Content/vision/using/video-stream-processing-top.htm) +- [OCI Python SDK API Reference](https://docs.oracle.com/en-us/iaas/tools/python/2.162.0/api/landing.html) + +## 7. Troubleshooting +**Common Errors: +If you encounter a 405 – Request Not Allowed error while running the stream job, it may be because the job is currently transitioning between states (for example, from CREATED to RUNNING). During this UPDATING phase, the job is temporarily locked, and you won’t be able to perform any actions on it. If it remains stuck in this state, try deleting the stream job and creating a new one. + +## 8. License +Copyright (c) 2025 Oracle and/or its affiliates. +Licensed under the Universal Permissive License (UPL), Version 1.0. +See [LICENSE](LICENSE) for more details. diff --git a/ai/ai-vision/video-stream-analysis/files/OCIVisionStreamSetup.ipynb b/ai/ai-vision/video-stream-analysis/files/OCIVisionStreamSetup.ipynb new file mode 100644 index 000000000..bd65086f1 --- /dev/null +++ b/ai/ai-vision/video-stream-analysis/files/OCIVisionStreamSetup.ipynb @@ -0,0 +1,1897 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 15, + "id": "179aa378", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Looking in indexes: https://artifactory.oci.oraclecorp.com/api/pypi/global-dev-pypi/simple\n", + "Collecting oci==2.158.0+394\n", + " Downloading https://artifactory.oci.oraclecorp.com/api/pypi/global-dev-pypi/oci-2.158.0%2B394-py3-none-any.whl (32.1 MB)\n", + " ---------------------------------------- 0.0/32.1 MB ? eta -:--:--\n", + " ---------------------------------------- 0.0/32.1 MB ? eta -:--:--\n", + " ---------------------------------------- 0.0/32.1 MB ? eta -:--:--\n", + " ---------------------------------------- 0.0/32.1 MB ? eta -:--:--\n", + " ---------------------------------------- 0.0/32.1 MB ? eta -:--:--\n", + " ---------------------------------------- 0.3/32.1 MB ? eta -:--:--\n", + " --------------------------------------- 0.5/32.1 MB 1.0 MB/s eta 0:00:31\n", + " --------------------------------------- 0.5/32.1 MB 1.0 MB/s eta 0:00:31\n", + " - -------------------------------------- 1.0/32.1 MB 1.5 MB/s eta 0:00:21\n", + " - -------------------------------------- 1.6/32.1 MB 1.6 MB/s eta 0:00:19\n", + " -- ------------------------------------- 2.1/32.1 MB 1.7 MB/s eta 0:00:18\n", + " -- ------------------------------------- 2.1/32.1 MB 1.7 MB/s eta 0:00:18\n", + " -- ------------------------------------- 2.1/32.1 MB 1.7 MB/s eta 0:00:18\n", + " --- ------------------------------------ 2.9/32.1 MB 1.6 MB/s eta 0:00:18\n", + " --- ------------------------------------ 3.1/32.1 MB 1.5 MB/s eta 0:00:19\n", + " ---- ----------------------------------- 3.4/32.1 MB 1.5 MB/s eta 0:00:20\n", + " ---- ----------------------------------- 3.9/32.1 MB 1.5 MB/s eta 0:00:19\n", + " ---- ----------------------------------- 3.9/32.1 MB 1.5 MB/s eta 0:00:19\n", + " ---- ----------------------------------- 3.9/32.1 MB 1.5 MB/s eta 0:00:19\n", + " ----- ---------------------------------- 4.5/32.1 MB 1.4 MB/s eta 0:00:20\n", + " ----- ---------------------------------- 4.7/32.1 MB 1.4 MB/s eta 0:00:20\n", + " ------ --------------------------------- 5.2/32.1 MB 1.4 MB/s eta 0:00:19\n", + " ------ --------------------------------- 5.2/32.1 MB 1.4 MB/s eta 0:00:19\n", + " ------ --------------------------------- 5.5/32.1 MB 1.4 MB/s eta 0:00:20\n", + " ------- -------------------------------- 5.8/32.1 MB 1.4 MB/s eta 0:00:20\n", + " ------- -------------------------------- 6.0/32.1 MB 1.3 MB/s eta 0:00:20\n", + " ------- -------------------------------- 6.3/32.1 MB 1.3 MB/s eta 0:00:20\n", + " -------- ------------------------------- 6.6/32.1 MB 1.3 MB/s eta 0:00:20\n", + " -------- ------------------------------- 6.8/32.1 MB 1.3 MB/s eta 0:00:19\n", + " -------- ------------------------------- 7.1/32.1 MB 1.3 MB/s eta 0:00:19\n", + " --------- ------------------------------ 7.3/32.1 MB 1.3 MB/s eta 0:00:19\n", + " --------- ------------------------------ 7.6/32.1 MB 1.3 MB/s eta 0:00:19\n", + " --------- ------------------------------ 7.9/32.1 MB 1.3 MB/s eta 0:00:19\n", + " ---------- ----------------------------- 8.1/32.1 MB 1.3 MB/s eta 0:00:19\n", + " ---------- ----------------------------- 8.4/32.1 MB 1.3 MB/s eta 0:00:19\n", + " ---------- ----------------------------- 8.7/32.1 MB 1.3 MB/s eta 0:00:19\n", + " ----------- ---------------------------- 8.9/32.1 MB 1.3 MB/s eta 0:00:18\n", + " ----------- ---------------------------- 9.4/32.1 MB 1.3 MB/s eta 0:00:18\n", + " ----------- ---------------------------- 9.4/32.1 MB 1.3 MB/s eta 0:00:18\n", + " ------------ --------------------------- 9.7/32.1 MB 1.3 MB/s eta 0:00:18\n", + " ------------ --------------------------- 10.0/32.1 MB 1.3 MB/s eta 0:00:18\n", + " ------------- -------------------------- 10.5/32.1 MB 1.3 MB/s eta 0:00:17\n", + " ------------- -------------------------- 10.7/32.1 MB 1.3 MB/s eta 0:00:17\n", + " ------------- -------------------------- 11.0/32.1 MB 1.3 MB/s eta 0:00:17\n", + " -------------- ------------------------- 11.3/32.1 MB 1.3 MB/s eta 0:00:17\n", + " -------------- ------------------------- 11.5/32.1 MB 1.3 MB/s eta 0:00:16\n", + " -------------- ------------------------- 11.8/32.1 MB 1.3 MB/s eta 0:00:16\n", + " --------------- ------------------------ 12.1/32.1 MB 1.3 MB/s eta 0:00:16\n", + " --------------- ------------------------ 12.3/32.1 MB 1.3 MB/s eta 0:00:16\n", + " --------------- ------------------------ 12.6/32.1 MB 1.3 MB/s eta 0:00:16\n", + " --------------- ------------------------ 12.8/32.1 MB 1.3 MB/s eta 0:00:15\n", + " ---------------- ----------------------- 13.1/32.1 MB 1.3 MB/s eta 0:00:15\n", + " ---------------- ----------------------- 13.4/32.1 MB 1.3 MB/s eta 0:00:15\n", + " ---------------- ----------------------- 13.6/32.1 MB 1.3 MB/s eta 0:00:15\n", + " ----------------- ---------------------- 13.9/32.1 MB 1.3 MB/s eta 0:00:14\n", + " ----------------- ---------------------- 14.2/32.1 MB 1.3 MB/s eta 0:00:14\n", + " ------------------ --------------------- 14.7/32.1 MB 1.3 MB/s eta 0:00:14\n", + " ------------------ --------------------- 14.9/32.1 MB 1.3 MB/s eta 0:00:14\n", + " ------------------ --------------------- 14.9/32.1 MB 1.3 MB/s eta 0:00:14\n", + " ------------------- -------------------- 15.5/32.1 MB 1.3 MB/s eta 0:00:13\n", + " ------------------- -------------------- 15.7/32.1 MB 1.3 MB/s eta 0:00:13\n", + " ------------------- -------------------- 16.0/32.1 MB 1.3 MB/s eta 0:00:13\n", + " -------------------- ------------------- 16.3/32.1 MB 1.3 MB/s eta 0:00:13\n", + " -------------------- ------------------- 16.8/32.1 MB 1.3 MB/s eta 0:00:12\n", + " -------------------- ------------------- 16.8/32.1 MB 1.3 MB/s eta 0:00:12\n", + " --------------------- ------------------ 17.3/32.1 MB 1.3 MB/s eta 0:00:12\n", + " --------------------- ------------------ 17.6/32.1 MB 1.3 MB/s eta 0:00:12\n", + " ---------------------- ----------------- 18.1/32.1 MB 1.3 MB/s eta 0:00:11\n", + " ---------------------- ----------------- 18.4/32.1 MB 1.3 MB/s eta 0:00:11\n", + " ----------------------- ---------------- 18.6/32.1 MB 1.3 MB/s eta 0:00:11\n", + " ----------------------- ---------------- 18.9/32.1 MB 1.3 MB/s eta 0:00:10\n", + " ------------------------ --------------- 19.4/32.1 MB 1.4 MB/s eta 0:00:10\n", + " ------------------------ --------------- 19.9/32.1 MB 1.4 MB/s eta 0:00:09\n", + " ------------------------- -------------- 20.2/32.1 MB 1.4 MB/s eta 0:00:09\n", + " ------------------------- -------------- 20.4/32.1 MB 1.4 MB/s eta 0:00:09\n", + " -------------------------- ------------- 21.0/32.1 MB 1.4 MB/s eta 0:00:09\n", + " -------------------------- ------------- 21.5/32.1 MB 1.4 MB/s eta 0:00:08\n", + " --------------------------- ------------ 22.0/32.1 MB 1.4 MB/s eta 0:00:08\n", + " ---------------------------- ----------- 22.5/32.1 MB 1.4 MB/s eta 0:00:07\n", + " ---------------------------- ----------- 22.5/32.1 MB 1.4 MB/s eta 0:00:07\n", + " ---------------------------- ----------- 23.1/32.1 MB 1.4 MB/s eta 0:00:07\n", + " ----------------------------- ---------- 23.6/32.1 MB 1.4 MB/s eta 0:00:06\n", + " ----------------------------- ---------- 23.6/32.1 MB 1.4 MB/s eta 0:00:06\n", + " ----------------------------- ---------- 23.6/32.1 MB 1.4 MB/s eta 0:00:06\n", + " ----------------------------- ---------- 23.9/32.1 MB 1.4 MB/s eta 0:00:06\n", + " ------------------------------ --------- 24.1/32.1 MB 1.4 MB/s eta 0:00:06\n", + " ------------------------------ --------- 24.1/32.1 MB 1.4 MB/s eta 0:00:06\n", + " ------------------------------ --------- 24.4/32.1 MB 1.4 MB/s eta 0:00:06\n", + " ------------------------------ --------- 24.6/32.1 MB 1.4 MB/s eta 0:00:06\n", + " ------------------------------ --------- 24.9/32.1 MB 1.4 MB/s eta 0:00:06\n", + " ------------------------------- -------- 25.2/32.1 MB 1.4 MB/s eta 0:00:06\n", + " ------------------------------- -------- 25.2/32.1 MB 1.4 MB/s eta 0:00:06\n", + " ------------------------------- -------- 25.2/32.1 MB 1.4 MB/s eta 0:00:06\n", + " ------------------------------- -------- 25.2/32.1 MB 1.4 MB/s eta 0:00:06\n", + " ------------------------------- -------- 25.2/32.1 MB 1.4 MB/s eta 0:00:06\n", + " ------------------------------- -------- 25.2/32.1 MB 1.4 MB/s eta 0:00:06\n", + " ------------------------------- -------- 25.2/32.1 MB 1.4 MB/s eta 0:00:06\n", + " ------------------------------- -------- 25.2/32.1 MB 1.4 MB/s eta 0:00:06\n", + " ------------------------------- -------- 25.2/32.1 MB 1.4 MB/s eta 0:00:06\n", + " ------------------------------- -------- 25.2/32.1 MB 1.4 MB/s eta 0:00:06\n", + " ------------------------------- -------- 25.2/32.1 MB 1.4 MB/s eta 0:00:06\n", + " ------------------------------- -------- 25.4/32.1 MB 1.2 MB/s eta 0:00:06\n", + " ------------------------------- -------- 25.4/32.1 MB 1.2 MB/s eta 0:00:06\n", + " ------------------------------- -------- 25.4/32.1 MB 1.2 MB/s eta 0:00:06\n", + " ------------------------------- -------- 25.4/32.1 MB 1.2 MB/s eta 0:00:06\n", + " ------------------------------- -------- 25.4/32.1 MB 1.2 MB/s eta 0:00:06\n", + " ------------------------------- -------- 25.4/32.1 MB 1.2 MB/s eta 0:00:06\n", + " -------------------------------- ------- 26.0/32.1 MB 1.2 MB/s eta 0:00:06\n", + " -------------------------------- ------- 26.0/32.1 MB 1.2 MB/s eta 0:00:06\n", + " -------------------------------- ------- 26.0/32.1 MB 1.2 MB/s eta 0:00:06\n", + " -------------------------------- ------- 26.5/32.1 MB 1.2 MB/s eta 0:00:05\n", + " -------------------------------- ------- 26.5/32.1 MB 1.2 MB/s eta 0:00:05\n", + " -------------------------------- ------- 26.5/32.1 MB 1.2 MB/s eta 0:00:05\n", + " --------------------------------- ------ 26.7/32.1 MB 1.1 MB/s eta 0:00:05\n", + " --------------------------------- ------ 26.7/32.1 MB 1.1 MB/s eta 0:00:05\n", + " --------------------------------- ------ 27.0/32.1 MB 1.1 MB/s eta 0:00:05\n", + " ---------------------------------- ----- 27.5/32.1 MB 1.1 MB/s eta 0:00:05\n", + " ---------------------------------- ----- 27.5/32.1 MB 1.1 MB/s eta 0:00:05\n", + " ---------------------------------- ----- 27.8/32.1 MB 1.1 MB/s eta 0:00:04\n", + " ---------------------------------- ----- 27.8/32.1 MB 1.1 MB/s eta 0:00:04\n", + " ---------------------------------- ----- 28.0/32.1 MB 1.1 MB/s eta 0:00:04\n", + " ---------------------------------- ----- 28.0/32.1 MB 1.1 MB/s eta 0:00:04\n", + " ----------------------------------- ---- 28.3/32.1 MB 1.1 MB/s eta 0:00:04\n", + " ----------------------------------- ---- 28.6/32.1 MB 1.1 MB/s eta 0:00:04\n", + " ----------------------------------- ---- 28.8/32.1 MB 1.1 MB/s eta 0:00:03\n", + " ----------------------------------- ---- 28.8/32.1 MB 1.1 MB/s eta 0:00:03\n", + " ------------------------------------ --- 29.1/32.1 MB 1.1 MB/s eta 0:00:03\n", + " ------------------------------------ --- 29.4/32.1 MB 1.1 MB/s eta 0:00:03\n", + " ------------------------------------ --- 29.4/32.1 MB 1.1 MB/s eta 0:00:03\n", + " ------------------------------------ --- 29.6/32.1 MB 1.1 MB/s eta 0:00:03\n", + " ------------------------------------ --- 29.6/32.1 MB 1.1 MB/s eta 0:00:03\n", + " ------------------------------------- -- 29.9/32.1 MB 1.1 MB/s eta 0:00:03\n", + " ------------------------------------- -- 30.1/32.1 MB 1.1 MB/s eta 0:00:02\n", + " ------------------------------------- -- 30.1/32.1 MB 1.1 MB/s eta 0:00:02\n", + " ------------------------------------- -- 30.4/32.1 MB 1.1 MB/s eta 0:00:02\n", + " ------------------------------------- -- 30.4/32.1 MB 1.1 MB/s eta 0:00:02\n", + " -------------------------------------- - 30.7/32.1 MB 1.1 MB/s eta 0:00:02\n", + " -------------------------------------- - 30.9/32.1 MB 1.1 MB/s eta 0:00:02\n", + " -------------------------------------- - 30.9/32.1 MB 1.1 MB/s eta 0:00:02\n", + " -------------------------------------- - 31.2/32.1 MB 1.1 MB/s eta 0:00:01\n", + " --------------------------------------- 31.5/32.1 MB 1.1 MB/s eta 0:00:01\n", + " --------------------------------------- 31.5/32.1 MB 1.1 MB/s eta 0:00:01\n", + " --------------------------------------- 31.7/32.1 MB 1.1 MB/s eta 0:00:01\n", + " --------------------------------------- 32.0/32.1 MB 1.1 MB/s eta 0:00:01\n", + " --------------------------------------- 32.0/32.1 MB 1.1 MB/s eta 0:00:01\n", + " ---------------------------------------- 32.1/32.1 MB 1.1 MB/s eta 0:00:00\n", + "Requirement already satisfied: certifi in c:\\users\\david\\miniconda3\\envs\\whatsnew\\lib\\site-packages (from oci==2.158.0+394) (2025.10.5)\n", + "Requirement already satisfied: cryptography<46.0.0,>=3.2.1 in c:\\users\\david\\miniconda3\\envs\\whatsnew\\lib\\site-packages (from oci==2.158.0+394) (44.0.3)\n", + "Requirement already satisfied: pyOpenSSL<25.0.0,>=17.5.0 in c:\\users\\david\\miniconda3\\envs\\whatsnew\\lib\\site-packages (from oci==2.158.0+394) (24.3.0)\n", + "Requirement already satisfied: python-dateutil<3.0.0,>=2.5.3 in c:\\users\\david\\miniconda3\\envs\\whatsnew\\lib\\site-packages (from oci==2.158.0+394) (2.9.0.post0)\n", + "Requirement already satisfied: pytz>=2016.10 in c:\\users\\david\\miniconda3\\envs\\whatsnew\\lib\\site-packages (from oci==2.158.0+394) (2025.2)\n", + "Requirement already satisfied: circuitbreaker<3.0.0,>=1.3.1 in c:\\users\\david\\miniconda3\\envs\\whatsnew\\lib\\site-packages (from oci==2.158.0+394) (2.1.3)\n", + "Requirement already satisfied: cffi>=1.12 in c:\\users\\david\\miniconda3\\envs\\whatsnew\\lib\\site-packages (from cryptography<46.0.0,>=3.2.1->oci==2.158.0+394) (1.17.1)\n", + "Requirement already satisfied: six>=1.5 in c:\\users\\david\\miniconda3\\envs\\whatsnew\\lib\\site-packages (from python-dateutil<3.0.0,>=2.5.3->oci==2.158.0+394) (1.17.0)\n", + "Requirement already satisfied: pycparser in c:\\users\\david\\miniconda3\\envs\\whatsnew\\lib\\site-packages (from cffi>=1.12->cryptography<46.0.0,>=3.2.1->oci==2.158.0+394) (2.22)\n", + "Installing collected packages: oci\n", + " Attempting uninstall: oci\n", + " Found existing installation: oci 2.156.1+preview.1.257\n", + " Uninstalling oci-2.156.1+preview.1.257:\n", + " Successfully uninstalled oci-2.156.1+preview.1.257\n", + "Successfully installed oci-2.158.0+394\n", + "Note: you may need to restart the kernel to use updated packages.\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError(\"HTTPSConnectionPool(host='artifactory.oci.oraclecorp.com', port=443): Read timed out. (read timeout=15)\")': /api/pypi/global-dev-pypi/simple/oci/\n", + " DEPRECATION: Wheel filename 'oci-1.3.12+preview.1+47-py2.py3-none-any.whl' is not correctly normalised. Future versions of pip will raise the following error:\n", + " Invalid wheel filename (invalid version): 'oci-1.3.12+preview.1+47-py2.py3-none-any'\n", + " \n", + " pip 25.3 will enforce this behaviour change. A possible replacement is to rename the wheel to use a correctly normalised name (this may require updating the version in the project metadata). Discussion can be found at https://github.com/pypa/pip/issues/12938\n", + " DEPRECATION: Wheel filename 'oci-1.3.14+preview.1+51-py2.py3-none-any.whl' is not correctly normalised. Future versions of pip will raise the following error:\n", + " Invalid wheel filename (invalid version): 'oci-1.3.14+preview.1+51-py2.py3-none-any'\n", + " \n", + " pip 25.3 will enforce this behaviour change. A possible replacement is to rename the wheel to use a correctly normalised name (this may require updating the version in the project metadata). Discussion can be found at https://github.com/pypa/pip/issues/12938\n", + " DEPRECATION: Wheel filename 'oci-1.3.14+preview.1+52-py2.py3-none-any.whl' is not correctly normalised. Future versions of pip will raise the following error:\n", + " Invalid wheel filename (invalid version): 'oci-1.3.14+preview.1+52-py2.py3-none-any'\n", + " \n", + " pip 25.3 will enforce this behaviour change. A possible replacement is to rename the wheel to use a correctly normalised name (this may require updating the version in the project metadata). Discussion can be found at https://github.com/pypa/pip/issues/12938\n", + " DEPRECATION: Wheel filename 'oci-1.3.16+preview.1+25-py2.py3-none-any.whl' is not correctly normalised. Future versions of pip will raise the following error:\n", + " Invalid wheel filename (invalid version): 'oci-1.3.16+preview.1+25-py2.py3-none-any'\n", + " \n", + " pip 25.3 will enforce this behaviour change. A possible replacement is to rename the wheel to use a correctly normalised name (this may require updating the version in the project metadata). Discussion can be found at https://github.com/pypa/pip/issues/12938\n", + " DEPRECATION: Wheel filename 'oci-1.3.16+preview.1+26-py2.py3-none-any.whl' is not correctly normalised. Future versions of pip will raise the following error:\n", + " Invalid wheel filename (invalid version): 'oci-1.3.16+preview.1+26-py2.py3-none-any'\n", + " \n", + " pip 25.3 will enforce this behaviour change. A possible replacement is to rename the wheel to use a correctly normalised name (this may require updating the version in the project metadata). Discussion can be found at https://github.com/pypa/pip/issues/12938\n", + " DEPRECATION: Wheel filename 'oci-1.3.16+preview.1+27-py2.py3-none-any.whl' is not correctly normalised. Future versions of pip will raise the following error:\n", + " Invalid wheel filename (invalid version): 'oci-1.3.16+preview.1+27-py2.py3-none-any'\n", + " \n", + " pip 25.3 will enforce this behaviour change. A possible replacement is to rename the wheel to use a correctly normalised name (this may require updating the version in the project metadata). Discussion can be found at https://github.com/pypa/pip/issues/12938\n", + " DEPRECATION: Wheel filename 'oci-1.3.16+preview.1+53-py2.py3-none-any.whl' is not correctly normalised. Future versions of pip will raise the following error:\n", + " Invalid wheel filename (invalid version): 'oci-1.3.16+preview.1+53-py2.py3-none-any'\n", + " \n", + " pip 25.3 will enforce this behaviour change. A possible replacement is to rename the wheel to use a correctly normalised name (this may require updating the version in the project metadata). Discussion can be found at https://github.com/pypa/pip/issues/12938\n", + " DEPRECATION: Wheel filename 'oci-1.3.17+preview.1+55-py2.py3-none-any.whl' is not correctly normalised. Future versions of pip will raise the following error:\n", + " Invalid wheel filename (invalid version): 'oci-1.3.17+preview.1+55-py2.py3-none-any'\n", + " \n", + " pip 25.3 will enforce this behaviour change. A possible replacement is to rename the wheel to use a correctly normalised name (this may require updating the version in the project metadata). Discussion can be found at https://github.com/pypa/pip/issues/12938\n", + " DEPRECATION: Wheel filename 'oci-1.3.17+preview.1+59-py2.py3-none-any.whl' is not correctly normalised. Future versions of pip will raise the following error:\n", + " Invalid wheel filename (invalid version): 'oci-1.3.17+preview.1+59-py2.py3-none-any'\n", + " \n", + " pip 25.3 will enforce this behaviour change. A possible replacement is to rename the wheel to use a correctly normalised name (this may require updating the version in the project metadata). Discussion can be found at https://github.com/pypa/pip/issues/12938\n", + " DEPRECATION: Wheel filename 'oci-1.3.17+preview.1+61-py2.py3-none-any.whl' is not correctly normalised. Future versions of pip will raise the following error:\n", + " Invalid wheel filename (invalid version): 'oci-1.3.17+preview.1+61-py2.py3-none-any'\n", + " \n", + " pip 25.3 will enforce this behaviour change. A possible replacement is to rename the wheel to use a correctly normalised name (this may require updating the version in the project metadata). Discussion can be found at https://github.com/pypa/pip/issues/12938\n", + " DEPRECATION: Wheel filename 'oci-1.3.17+preview.1+63-py2.py3-none-any.whl' is not correctly normalised. Future versions of pip will raise the following error:\n", + " Invalid wheel filename (invalid version): 'oci-1.3.17+preview.1+63-py2.py3-none-any'\n", + " \n", + " pip 25.3 will enforce this behaviour change. A possible replacement is to rename the wheel to use a correctly normalised name (this may require updating the version in the project metadata). Discussion can be found at https://github.com/pypa/pip/issues/12938\n", + " DEPRECATION: Wheel filename 'oci-1.3.8+orchestration.preview+403-py2.py3-none-any.whl' is not correctly normalised. Future versions of pip will raise the following error:\n", + " Invalid wheel filename (invalid version): 'oci-1.3.8+orchestration.preview+403-py2.py3-none-any'\n", + " \n", + " pip 25.3 will enforce this behaviour change. A possible replacement is to rename the wheel to use a correctly normalised name (this may require updating the version in the project metadata). Discussion can be found at https://github.com/pypa/pip/issues/12938\n", + " DEPRECATION: Wheel filename 'oci-2.133.1..-py3-none-any.whl' is not correctly normalised. Future versions of pip will raise the following error:\n", + " Invalid wheel filename (invalid version): 'oci-2.133.1..-py3-none-any'\n", + " \n", + " pip 25.3 will enforce this behaviour change. A possible replacement is to rename the wheel to use a correctly normalised name (this may require updating the version in the project metadata). Discussion can be found at https://github.com/pypa/pip/issues/12938\n", + " DEPRECATION: Wheel filename 'oci-2.134.0.-py3-none-any.whl' is not correctly normalised. Future versions of pip will raise the following error:\n", + " Invalid wheel filename (invalid version): 'oci-2.134.0.-py3-none-any'\n", + " \n", + " pip 25.3 will enforce this behaviour change. A possible replacement is to rename the wheel to use a correctly normalised name (this may require updating the version in the project metadata). Discussion can be found at https://github.com/pypa/pip/issues/12938\n", + " DEPRECATION: Wheel filename 'oci-2.147.1..-py3-none-any.whl' is not correctly normalised. Future versions of pip will raise the following error:\n", + " Invalid wheel filename (invalid version): 'oci-2.147.1..-py3-none-any'\n", + " \n", + " pip 25.3 will enforce this behaviour change. A possible replacement is to rename the wheel to use a correctly normalised name (this may require updating the version in the project metadata). Discussion can be found at https://github.com/pypa/pip/issues/12938\n", + " DEPRECATION: Wheel filename 'oci-2.148.1..-py3-none-any.whl' is not correctly normalised. Future versions of pip will raise the following error:\n", + " Invalid wheel filename (invalid version): 'oci-2.148.1..-py3-none-any'\n", + " \n", + " pip 25.3 will enforce this behaviour change. A possible replacement is to rename the wheel to use a correctly normalised name (this may require updating the version in the project metadata). Discussion can be found at https://github.com/pypa/pip/issues/12938\n", + " DEPRECATION: Wheel filename 'oci-2.149.0..-py3-none-any.whl' is not correctly normalised. Future versions of pip will raise the following error:\n", + " Invalid wheel filename (invalid version): 'oci-2.149.0..-py3-none-any'\n", + " \n", + " pip 25.3 will enforce this behaviour change. A possible replacement is to rename the wheel to use a correctly normalised name (this may require updating the version in the project metadata). Discussion can be found at https://github.com/pypa/pip/issues/12938\n", + " DEPRECATION: Wheel filename 'oci-2.149.1..-py3-none-any.whl' is not correctly normalised. Future versions of pip will raise the following error:\n", + " Invalid wheel filename (invalid version): 'oci-2.149.1..-py3-none-any'\n", + " \n", + " pip 25.3 will enforce this behaviour change. A possible replacement is to rename the wheel to use a correctly normalised name (this may require updating the version in the project metadata). Discussion can be found at https://github.com/pypa/pip/issues/12938\n", + " DEPRECATION: Wheel filename 'oci-2.160.3.ssltest-py3-none-any.whl' is not correctly normalised. Future versions of pip will raise the following error:\n", + " Invalid wheel filename (invalid version): 'oci-2.160.3.ssltest-py3-none-any'\n", + " \n", + " pip 25.3 will enforce this behaviour change. A possible replacement is to rename the wheel to use a correctly normalised name (this may require updating the version in the project metadata). Discussion can be found at https://github.com/pypa/pip/issues/12938\n", + " DEPRECATION: Wheel filename 'oci-2.160.3.ssltest.1-py3-none-any.whl' is not correctly normalised. Future versions of pip will raise the following error:\n", + " Invalid wheel filename (invalid version): 'oci-2.160.3.ssltest.1-py3-none-any'\n", + " \n", + " pip 25.3 will enforce this behaviour change. A possible replacement is to rename the wheel to use a correctly normalised name (this may require updating the version in the project metadata). Discussion can be found at https://github.com/pypa/pip/issues/12938\n" + ] + } + ], + "source": [ + "pip install --trusted-host=artifactory.oci.oraclecorp.com -i https://artifactory.oci.oraclecorp.com/api/pypi/global-dev-pypi/simple -U oci==2.158.0+394" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "id": "eb8d5bc4-5499-4da2-b706-275fb4e2ce6a", + "metadata": { + "ExecuteTime": { + "end_time": "2025-05-16T12:37:19.295156Z", + "start_time": "2025-05-16T12:37:19.285932Z" + }, + "tags": [] + }, + "outputs": [], + "source": [ + "from vision_service_python_client import ai_service_vision_client\n", + "from vision_service_python_client.models import CreateStreamJobDetails, CreateStreamSourceDetails, \\\n", + " RtspSourceDetails, ObjectStorageOutputLocation, PublicStreamNetworkAccessDetails\n", + "import oci, time" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "id": "c668da24-0040-484e-9d4d-6d712677ca07", + "metadata": { + "ExecuteTime": { + "end_time": "2025-05-16T12:37:22.802754Z", + "start_time": "2025-05-16T12:37:22.798722Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "done\n" + ] + } + ], + "source": [ + "CONFIG_PROFILE = \"DEFAULT\"\n", + "COMPARTMENT_ID = \"ocid1.compartment.oc1..aaaaaaaarsssgsb3dqeibesnmbaaqkvomkpl5sua26wfuz5povnvohdw2ekq\"\n", + "STREAM_JOB_DISPLAY_NAME = \"Python SDK Test\"\n", + "CAMERA_URL=\"rtsp://64.181.159.98:443/stream\"\n", + "NAMESPACE= \"frpj5kvxryk1\"\n", + "BUCKET= \"stream_vision_bucket\"\n", + "PREFIX= \"testing_person_min\"\n", + "FEATURES = [\n", + " {\n", + " \"featureType\": \"OBJECT_DETECTION\",\n", + " \n", + " \"minConfidence\": 0.35\n", + " # \"trackingTypes\":[\n", + " # {\n", + " # \"objects\": [\"face\"],\n", + " # \"maxResults\": 5,\n", + " # \"shouldReturnLandmarks\": True,\n", + " # }\n", + " # ]\n", + " }\n", + " ]\n", + "print(\"done\")" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "id": "badb3e5f-fd4b-4d48-b2b7-a7462a597c89", + "metadata": { + "ExecuteTime": { + "end_time": "2025-05-16T12:37:30.962895Z", + "start_time": "2025-05-16T12:37:30.877886Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "done\n" + ] + } + ], + "source": [ + "config = oci.config.from_file('~/.oci/config', profile_name=CONFIG_PROFILE)\n", + "endpoint = \"\"\n", + "token_file = config['security_token_file']\n", + "with open(token_file, 'r') as f:\n", + " token = f.read()\n", + "private_key = oci.signer.load_private_key_from_file(config['key_file'])\n", + "signer = oci.auth.signers.SecurityTokenSigner(token, private_key)\n", + "ai_service_vision_client = ai_service_vision_client.AIServiceVisionClient(config=config, signer=signer, service_endpoint=endpoint)\n", + "print(\"done\")" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "id": "c88963bd4140a86d", + "metadata": { + "ExecuteTime": { + "end_time": "2025-05-16T12:37:34.505524Z", + "start_time": "2025-05-16T12:37:34.500133Z" + }, + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "done\n" + ] + } + ], + "source": [ + "create_stream_source_details = CreateStreamSourceDetails()\n", + "\n", + "stream_source_details = RtspSourceDetails()\n", + "stream_source_details.camera_url = CAMERA_URL\n", + "stream_source_details.stream_network_access_details = PublicStreamNetworkAccessDetails()\n", + "create_stream_source_details.stream_source_details = stream_source_details\n", + "create_stream_source_details.compartment_id = COMPARTMENT_ID\n", + "\n", + "# Send request for adding the device and parse the response\n", + "print(\"done\")" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "id": "a55725bcdee1d542", + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ocid1.aivisionstreamsource.oc1..aaaaaaaaechtt4bpecmiiiony4gvmnyu7a3a43oziwclqxorm4z4kzp6zm2q\n", + "done\n" + ] + } + ], + "source": [ + "stream_source = ai_service_vision_client.create_stream_source(create_stream_source_details)\n", + "source_id = stream_source.data.id\n", + "print(source_id)\n", + "while stream_source.data.lifecycle_state != 'ACTIVE':\n", + " stream_source = ai_service_vision_client.get_stream_source(source_id)\n", + " time.sleep(2)\n", + "print(\"done\")" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "id": "a34dc90e75b4744", + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{\n", + " \"compartment_id\": \"ocid1.compartment.oc1..aaaaaaaarsssgsb3dqeibesnmbaaqkvomkpl5sua26wfuz5povnvohdw2ekq\",\n", + " \"defined_tags\": {},\n", + " \"display_name\": \"aivisionstreamsource20251113075113\",\n", + " \"freeform_tags\": {},\n", + " \"id\": \"ocid1.aivisionstreamsource.oc1..aaaaaaaaechtt4bpecmiiiony4gvmnyu7a3a43oziwclqxorm4z4kzp6zm2q\",\n", + " \"lifecycle_state\": \"ACTIVE\",\n", + " \"stream_source_details\": {\n", + " \"camera_url\": \"rtsp://64.181.159.98:443/stream\",\n", + " \"secret_id\": null,\n", + " \"source_type\": \"RTSP\",\n", + " \"stream_network_access_details\": {\n", + " \"stream_access_type\": \"PUBLIC\"\n", + " }\n", + " },\n", + " \"system_tags\": {},\n", + " \"time_created\": \"2025-11-13T07:51:13.253000+00:00\",\n", + " \"time_updated\": \"2025-11-13T07:51:13.253000+00:00\"\n", + "}\n" + ] + } + ], + "source": [ + "stream_source = ai_service_vision_client.get_stream_source(source_id)\n", + "print(stream_source.data)" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "id": "79f8d960015e2b7f", + "metadata": { + "ExecuteTime": { + "end_time": "2025-05-16T12:38:33.258866Z", + "start_time": "2025-05-16T12:38:33.255429Z" + }, + "collapsed": false + }, + "outputs": [], + "source": [ + "create_stream_job_details = CreateStreamJobDetails()\n", + "create_stream_job_details.stream_source_id = source_id\n", + "\n", + "# For Object Tracker (Only \"face\" supported as of now) - commend if not required\n", + "create_stream_job_details.features = FEATURES\n", + "# print(create_stream_job_detai)\n", + "\n", + "output_location = ObjectStorageOutputLocation()\n", + "output_location.namespace_name = NAMESPACE\n", + "output_location.bucket_name = BUCKET\n", + "output_location.prefix = PREFIX\n", + "# Choose output location in object storage, make sure you have created the bucket\n", + "create_stream_job_details.stream_output_location = output_location\n", + "\n", + "create_stream_job_details.compartment_id = COMPARTMENT_ID\n", + "create_stream_job_details.display_name = STREAM_JOB_DISPLAY_NAME\n" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "id": "98bfe34c260c797d", + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ocid1.aivisionstreamjob.oc1..aaaaaaaawcophuezqz7kewd2g4dioaxh4cbc5laf474enhfc4f5ue3yaycqa\n" + ] + } + ], + "source": [ + "stream_job = ai_service_vision_client.create_stream_job(create_stream_job_details=create_stream_job_details)\n", + "job_id = stream_job.data.id\n", + "print(job_id)\n", + "while stream_job.data.lifecycle_state == 'CREATING':\n", + " stream_job = ai_service_vision_client.get_stream_job(job_id)\n", + " time.sleep(10)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "id": "2c75a45e", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{\n", + " \"agent_participant_id\": null,\n", + " \"compartment_id\": \"ocid1.compartment.oc1..aaaaaaaarsssgsb3dqeibesnmbaaqkvomkpl5sua26wfuz5povnvohdw2ekq\",\n", + " \"defined_tags\": {},\n", + " \"display_name\": \"Python SDK Test\",\n", + " \"features\": [\n", + " {\n", + " \"feature_type\": \"UNKNOWN_ENUM_VALUE\"\n", + " }\n", + " ],\n", + " \"freeform_tags\": {},\n", + " \"id\": \"ocid1.aivisionstreamjob.oc1..aaaaaaaawcophuezqz7kewd2g4dioaxh4cbc5laf474enhfc4f5ue3yaycqa\",\n", + " \"lifecycle_details\": null,\n", + " \"lifecycle_state\": \"UPDATING\",\n", + " \"stream_output_location\": {\n", + " \"bucket_name\": \"stream_vision_bucket\",\n", + " \"namespace_name\": \"frpj5kvxryk1\",\n", + " \"obo_token\": null,\n", + " \"output_location_type\": \"OBJECT_STORAGE\",\n", + " \"prefix\": \"testing_person_min\"\n", + " },\n", + " \"stream_source_id\": \"ocid1.aivisionstreamsource.oc1..aaaaaaaaechtt4bpecmiiiony4gvmnyu7a3a43oziwclqxorm4z4kzp6zm2q\",\n", + " \"system_tags\": {},\n", + " \"time_created\": \"2025-11-13T07:51:23.140000+00:00\",\n", + " \"time_updated\": \"2025-11-13T07:51:25.811000+00:00\"\n", + "}\n" + ] + } + ], + "source": [ + "print(ai_service_vision_client.get_stream_job(job_id).data)" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "id": "b240a876c3ce4254", + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Calling startStream job at 1763020285.530762\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n", + "updating\n", + "UPDATING\n" + ] + }, + { + "ename": "KeyboardInterrupt", + "evalue": "", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[32], line 9\u001b[0m\n\u001b[0;32m 7\u001b[0m \u001b[38;5;28mprint\u001b[39m(stream_job\u001b[38;5;241m.\u001b[39mdata\u001b[38;5;241m.\u001b[39mlifecycle_state)\n\u001b[0;32m 8\u001b[0m stream_job \u001b[38;5;241m=\u001b[39m ai_service_vision_client\u001b[38;5;241m.\u001b[39mget_stream_job(job_id)\n\u001b[1;32m----> 9\u001b[0m \u001b[43mtime\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msleep\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m2\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[0;32m 10\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mComplete\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n", + "\u001b[1;31mKeyboardInterrupt\u001b[0m: " + ] + } + ], + "source": [ + "print(\"Calling startStream job at \", time.time())\n", + "ai_service_vision_client.start_stream_job(job_id)\n", + "stream_job = ai_service_vision_client.get_stream_job(job_id)\n", + "\n", + "while stream_job.data.lifecycle_state == 'UPDATING':\n", + " print(\"updating\")\n", + " print(stream_job.data.lifecycle_state)\n", + " stream_job = ai_service_vision_client.get_stream_job(job_id)\n", + " time.sleep(2)\n", + "print(\"Complete\")\n" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "id": "3cead1c70c67f325", + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "ename": "ServiceError", + "evalue": "{'target_service': 'ai_service_vision', 'status': 405, 'code': 'MethodNotAllowed', 'opc-request-id': '76AFD9D5F3104BB396A587347A013AA2/15A93B1B18D9FAFB9993156949414455/5563022A3161180CFF0662C43F4F36D0', 'message': 'Cannot stop already Updating resource', 'operation_name': 'stop_stream_job', 'timestamp': '2025-11-13T08:15:21.312952+00:00', 'client_version': 'Oracle-PythonSDK/2.156.1+preview.1.257', 'request_endpoint': 'POST https://vision.aiservice.us-ashburn-1.oci.oraclecloud.com/20220125/streamJobs/ocid1.aivisionstreamjob.oc1..aaaaaaaawcophuezqz7kewd2g4dioaxh4cbc5laf474enhfc4f5ue3yaycqa/actions/stop', 'logging_tips': 'To get more info on the failing request, refer to https://docs.oracle.com/en-us/iaas/tools/python/latest/logging.html for ways to log the request/response details.', 'troubleshooting_tips': 'See https://docs.oracle.com/iaas/Content/API/References/apierrors.htm#apierrors_405__405_methodnotallowed for more information about resolving this error. If you are unable to resolve this ai_service_vision issue, please contact Oracle support and provide them this full error message.'}", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mServiceError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[34], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43mai_service_vision_client\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mstop_stream_job\u001b[49m\u001b[43m(\u001b[49m\u001b[43mjob_id\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 2\u001b[0m stream_job \u001b[38;5;241m=\u001b[39m ai_service_vision_client\u001b[38;5;241m.\u001b[39mget_stream_job(job_id)\n\u001b[0;32m 4\u001b[0m \u001b[38;5;28;01mwhile\u001b[39;00m stream_job\u001b[38;5;241m.\u001b[39mdata\u001b[38;5;241m.\u001b[39mlifecycle_state \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mUPDATING\u001b[39m\u001b[38;5;124m'\u001b[39m:\n", + "File \u001b[1;32mc:\\Users\\David\\miniconda3\\envs\\whatsNew\\lib\\site-packages\\vision_service_python_client\\ai_service_vision_client.py:4873\u001b[0m, in \u001b[0;36mAIServiceVisionClient.stop_stream_job\u001b[1;34m(self, stream_job_id, **kwargs)\u001b[0m\n\u001b[0;32m 4871\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mbase_client\u001b[38;5;241m.\u001b[39madd_opc_client_retries_header(header_params)\n\u001b[0;32m 4872\u001b[0m retry_strategy\u001b[38;5;241m.\u001b[39madd_circuit_breaker_callback(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mcircuit_breaker_callback)\n\u001b[1;32m-> 4873\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mretry_strategy\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mmake_retrying_call\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m 4874\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mbase_client\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcall_api\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 4875\u001b[0m \u001b[43m \u001b[49m\u001b[43mresource_path\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mresource_path\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 4876\u001b[0m \u001b[43m \u001b[49m\u001b[43mmethod\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mmethod\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 4877\u001b[0m \u001b[43m \u001b[49m\u001b[43mpath_params\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mpath_params\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 4878\u001b[0m \u001b[43m \u001b[49m\u001b[43mheader_params\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mheader_params\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 4879\u001b[0m \u001b[43m \u001b[49m\u001b[43mallow_control_chars\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mallow_control_chars\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 4880\u001b[0m \u001b[43m \u001b[49m\u001b[43moperation_name\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43moperation_name\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 4881\u001b[0m \u001b[43m \u001b[49m\u001b[43mapi_reference_link\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mapi_reference_link\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 4882\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m 4883\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mbase_client\u001b[38;5;241m.\u001b[39mcall_api(\n\u001b[0;32m 4884\u001b[0m resource_path\u001b[38;5;241m=\u001b[39mresource_path,\n\u001b[0;32m 4885\u001b[0m method\u001b[38;5;241m=\u001b[39mmethod,\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 4889\u001b[0m operation_name\u001b[38;5;241m=\u001b[39moperation_name,\n\u001b[0;32m 4890\u001b[0m api_reference_link\u001b[38;5;241m=\u001b[39mapi_reference_link)\n", + "File \u001b[1;32mc:\\Users\\David\\miniconda3\\envs\\whatsNew\\lib\\site-packages\\oci\\retry\\retry.py:309\u001b[0m, in \u001b[0;36mExponentialBackoffRetryStrategyBase.make_retrying_call\u001b[1;34m(self, func_ref, *func_args, **func_kwargs)\u001b[0m\n\u001b[0;32m 305\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m _should_record_body_position_for_retry:\n\u001b[0;32m 306\u001b[0m \u001b[38;5;66;03m# Attempt to save current position for file-like body\u001b[39;00m\n\u001b[0;32m 307\u001b[0m _is_body_retryable, body_position \u001b[38;5;241m=\u001b[39m record_body_position_for_rewind(func_kwargs\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mbody\u001b[39m\u001b[38;5;124m'\u001b[39m))\n\u001b[1;32m--> 309\u001b[0m response \u001b[38;5;241m=\u001b[39m func_ref(\u001b[38;5;241m*\u001b[39mfunc_args, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mfunc_kwargs)\n\u001b[0;32m 310\u001b[0m time_elapsed \u001b[38;5;241m=\u001b[39m time\u001b[38;5;241m.\u001b[39mtime() \u001b[38;5;241m-\u001b[39m start_time\n\u001b[0;32m 312\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m log_info[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mlogger\u001b[39m\u001b[38;5;124m\"\u001b[39m] \u001b[38;5;129;01mand\u001b[39;00m log_info[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mdebug\u001b[39m\u001b[38;5;124m\"\u001b[39m]:\n", + "File \u001b[1;32mc:\\Users\\David\\miniconda3\\envs\\whatsNew\\lib\\site-packages\\oci\\base_client.py:640\u001b[0m, in \u001b[0;36mBaseClient.call_api\u001b[1;34m(self, resource_path, method, path_params, query_params, header_params, body, response_type, enforce_content_headers, allow_control_chars, enable_strict_url_encoding, operation_name, api_reference_link, required_arguments)\u001b[0m\n\u001b[0;32m 638\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m\n\u001b[0;32m 639\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m--> 640\u001b[0m response \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrequest\u001b[49m\u001b[43m(\u001b[49m\u001b[43mrequest\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mallow_control_chars\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43moperation_name\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mapi_reference_link\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 641\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m response\n", + "File \u001b[1;32mc:\\Users\\David\\miniconda3\\envs\\whatsNew\\lib\\site-packages\\circuitbreaker.py:146\u001b[0m, in \u001b[0;36mCircuitBreaker._decorate_sync..wrapper\u001b[1;34m(*args, **kwargs)\u001b[0m\n\u001b[0;32m 144\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mfallback_function(\u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n\u001b[0;32m 145\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m CircuitBreakerError(\u001b[38;5;28mself\u001b[39m)\n\u001b[1;32m--> 146\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mcall(function, \u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n", + "File \u001b[1;32mc:\\Users\\David\\miniconda3\\envs\\whatsNew\\lib\\site-packages\\circuitbreaker.py:188\u001b[0m, in \u001b[0;36mCircuitBreaker.call\u001b[1;34m(self, func, *args, **kwargs)\u001b[0m\n\u001b[0;32m 182\u001b[0m \u001b[38;5;250m\u001b[39m\u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m 183\u001b[0m \u001b[38;5;124;03mCalls the decorated function and applies the circuit breaker\u001b[39;00m\n\u001b[0;32m 184\u001b[0m \u001b[38;5;124;03mrules on success or failure\u001b[39;00m\n\u001b[0;32m 185\u001b[0m \u001b[38;5;124;03m:param func: Decorated function\u001b[39;00m\n\u001b[0;32m 186\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m 187\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m \u001b[38;5;28mself\u001b[39m:\n\u001b[1;32m--> 188\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m func(\u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n", + "File \u001b[1;32mc:\\Users\\David\\miniconda3\\envs\\whatsNew\\lib\\site-packages\\oci\\base_client.py:846\u001b[0m, in \u001b[0;36mBaseClient.request\u001b[1;34m(self, request, allow_control_chars, operation_name, api_reference_link)\u001b[0m\n\u001b[0;32m 844\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mraise_transient_service_error(request, response, service_code, message, operation_name, api_reference_link, target_service, request_endpoint, client_version, timestamp, deserialized_data)\n\u001b[0;32m 845\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m--> 846\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mraise_service_error\u001b[49m\u001b[43m(\u001b[49m\u001b[43mrequest\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mresponse\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mservice_code\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmessage\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43moperation_name\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mapi_reference_link\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtarget_service\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mrequest_endpoint\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mclient_version\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtimestamp\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mdeserialized_data\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 848\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m stream:\n\u001b[0;32m 849\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m response\u001b[38;5;241m.\u001b[39mheaders\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcontent-type\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mempty\u001b[39m\u001b[38;5;124m\"\u001b[39m)\u001b[38;5;241m.\u001b[39mlower() \u001b[38;5;241m==\u001b[39m SSE_RESPONSE_HEADER_VALUE:\n", + "File \u001b[1;32mc:\\Users\\David\\miniconda3\\envs\\whatsNew\\lib\\site-packages\\oci\\base_client.py:1011\u001b[0m, in \u001b[0;36mBaseClient.raise_service_error\u001b[1;34m(self, request, response, service_code, message, operation_name, api_reference_link, target_service, request_endpoint, client_version, timestamp, deserialized_data)\u001b[0m\n\u001b[0;32m 1010\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;21mraise_service_error\u001b[39m(\u001b[38;5;28mself\u001b[39m, request, response, service_code, message, operation_name\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m, api_reference_link\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m, target_service\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m, request_endpoint\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m, client_version\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m, timestamp\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m, deserialized_data\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m):\n\u001b[1;32m-> 1011\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m exceptions\u001b[38;5;241m.\u001b[39mServiceError(\n\u001b[0;32m 1012\u001b[0m response\u001b[38;5;241m.\u001b[39mstatus_code,\n\u001b[0;32m 1013\u001b[0m service_code,\n\u001b[0;32m 1014\u001b[0m response\u001b[38;5;241m.\u001b[39mheaders,\n\u001b[0;32m 1015\u001b[0m message,\n\u001b[0;32m 1016\u001b[0m original_request\u001b[38;5;241m=\u001b[39mrequest,\n\u001b[0;32m 1017\u001b[0m operation_name\u001b[38;5;241m=\u001b[39moperation_name,\n\u001b[0;32m 1018\u001b[0m api_reference_link\u001b[38;5;241m=\u001b[39mapi_reference_link,\n\u001b[0;32m 1019\u001b[0m target_service\u001b[38;5;241m=\u001b[39mtarget_service,\n\u001b[0;32m 1020\u001b[0m request_endpoint\u001b[38;5;241m=\u001b[39mrequest_endpoint,\n\u001b[0;32m 1021\u001b[0m client_version\u001b[38;5;241m=\u001b[39mclient_version,\n\u001b[0;32m 1022\u001b[0m timestamp\u001b[38;5;241m=\u001b[39mtimestamp,\n\u001b[0;32m 1023\u001b[0m deserialized_data\u001b[38;5;241m=\u001b[39mdeserialized_data)\n", + "\u001b[1;31mServiceError\u001b[0m: {'target_service': 'ai_service_vision', 'status': 405, 'code': 'MethodNotAllowed', 'opc-request-id': '76AFD9D5F3104BB396A587347A013AA2/15A93B1B18D9FAFB9993156949414455/5563022A3161180CFF0662C43F4F36D0', 'message': 'Cannot stop already Updating resource', 'operation_name': 'stop_stream_job', 'timestamp': '2025-11-13T08:15:21.312952+00:00', 'client_version': 'Oracle-PythonSDK/2.156.1+preview.1.257', 'request_endpoint': 'POST https://vision.aiservice.us-ashburn-1.oci.oraclecloud.com/20220125/streamJobs/ocid1.aivisionstreamjob.oc1..aaaaaaaawcophuezqz7kewd2g4dioaxh4cbc5laf474enhfc4f5ue3yaycqa/actions/stop', 'logging_tips': 'To get more info on the failing request, refer to https://docs.oracle.com/en-us/iaas/tools/python/latest/logging.html for ways to log the request/response details.', 'troubleshooting_tips': 'See https://docs.oracle.com/iaas/Content/API/References/apierrors.htm#apierrors_405__405_methodnotallowed for more information about resolving this error. If you are unable to resolve this ai_service_vision issue, please contact Oracle support and provide them this full error message.'}" + ] + } + ], + "source": [ + "ai_service_vision_client.stop_stream_job(job_id)\n", + "stream_job = ai_service_vision_client.get_stream_job(job_id)\n", + "\n", + "while stream_job.data.lifecycle_state == 'UPDATING':\n", + " stream_job = ai_service_vision_client.get_stream_job(job_id)\n", + " time.sleep(2)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2249a4755b6c7f3", + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "print(job_id)\n", + "ai_service_vision_client.delete_stream_job(job_id)\n", + "stream_job = ai_service_vision_client.get_stream_job(job_id)\n", + "while stream_job.data.lifecycle_state == 'DELETING':\n", + " stream_job = ai_service_vision_client.get_stream_job(job_id)\n", + " time.sleep(2)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "77917ea3", + "metadata": {}, + "outputs": [], + "source": [ + "print(stream_source.data.id)\n", + "ai_service_vision_client.delete_stream_source(stream_source.data.id)\n", + "stream_job = ai_service_vision_client.get_stream_job(job_id)\n", + "\n", + "while stream_job.data.lifecycle_state == 'DELETING':\n", + " stream_job = ai_service_vision_client.get_stream_source(stream_source.data.id)\n", + " time.sleep(2)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8833dfa8", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "whatsNew", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.18" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/ai/ai-vision/video-stream-analysis/files/stream-analysis.py b/ai/ai-vision/video-stream-analysis/files/stream-analysis.py new file mode 100644 index 000000000..b002f00eb --- /dev/null +++ b/ai/ai-vision/video-stream-analysis/files/stream-analysis.py @@ -0,0 +1,295 @@ +import time +import base64 +import json +import oci +import streamlit as st +from PIL import Image +from io import BytesIO +import numpy as np +import cv2 +from datetime import datetime, timezone, timedelta +import logging, warnings +import pandas as pd +import altair as alt +from enum import Enum + +#------------------ Constants ----------------- +OBJECT_LIMIT = 500 +OCCUPANCY_WINDOW_SEC = 20 +FRAME_WIDTH = 700 +FRAME_HEIGHT = 350 + +# ----------------- Enum ----------------- +class DetectionMode(Enum): + OBJECT = "Object Detection" + FACE = "Face Detection" + +# ----------------- Setup ----------------- + +logging.basicConfig(level=logging.INFO) +logger = logging.getLogger(__name__) +warnings.filterwarnings("ignore") + +st.set_page_config(page_title="OCI Vision Streaming", layout="wide", initial_sidebar_state="expanded") + +with open("style.css") as f: + st.markdown(f"", unsafe_allow_html=True) + +# ----------------- Session Defaults ----------------- +defaults = { + "stream_job_ocid": "", + "bucket": "", + "prefix": "", + "os_namespace": "", + "streaming": False, + "occupancy_count": 0, + "peak_occupancy": {"timestamp": "", "count": 0}, + "face_detection_timestamps": [], + "occupancy_history": [], + "object_counts": {}, + "mode": DetectionMode.OBJECT.value, # default + "start_stop_label": "▶️ Start Consumption" +} +for k, v in defaults.items(): + if k not in st.session_state: + st.session_state[k] = v + +# OCI Config +oci_config = oci.config.from_file("~/.oci/config", profile_name="DEFAULT") +service_endpoint = f"https://vision.aiservice.{oci_config.get('region')}.oci.oraclecloud.com" + +# ----------------- Helpers ----------------- +def get_base64_image(image_path): + with open(image_path, "rb") as f: + return base64.b64encode(f.read()).decode() + +#--------------------------------------------------------------------------------------# +def get_current_time(): + return datetime.now(timezone.utc) + +#--------------------------------------------------------------------------------------# +def decode_image(image_data): + image_bytes = base64.b64decode(image_data) + image = Image.open(BytesIO(image_bytes)) + if image.mode not in ("RGB", "RGBA"): + image = image.convert("RGB") + return np.array(image) + +#--------------------------------------------------------------------------------------# + +def draw_objects_with_boxes(image, objects): + h, w, _ = image.shape + for obj in objects: + pts = [(int(v['x'] * w), int(v['y'] * h)) for v in obj['boundingPolygon']['normalizedVertices']] + x_coords = [pt[0] for pt in pts] + y_coords = [pt[1] for pt in pts] + x1, y1, x2, y2 = min(x_coords), min(y_coords), max(x_coords), max(y_coords) + cv2.rectangle(image, (x1, y1), (x2, y2), (0, 255, 0), 2) + label = f"{obj['name']} ({obj['confidence']:.2f})" + cv2.putText(image, label, (x1, y1 - 10), + cv2.FONT_HERSHEY_SIMPLEX, 0.6, (0, 255, 0), 2, cv2.LINE_AA) + return image + +#--------------------------------------------------------------------------------------# + +def blur_faces(image, faces): + h, w, _ = image.shape + for face in faces: + pts = [(int(v['x'] * w), int(v['y'] * h)) for v in face['boundingPolygon']['normalizedVertices']] + x_coords = [pt[0] for pt in pts] + y_coords = [pt[1] for pt in pts] + x1, y1, x2, y2 = min(x_coords), min(y_coords), max(x_coords), max(y_coords) + face_region = image[y1:y2, x1:x2] + if face_region.size > 0: + blurred = cv2.GaussianBlur(face_region, (51, 51), 30) + image[y1:y2, x1:x2] = blurred + return image + +#--------------------------------------------------------------------------------------# + +def process_frame(message, mode): + data = json.loads(message.replace("'", '"')) + image = decode_image(data['imageData']) + if mode == DetectionMode.OBJECT.value: + objects = data.get("detectedObjects", []) + if objects: + image = draw_objects_with_boxes(image, objects) + return image, objects + elif mode == DetectionMode.FACE.value: + faces = data.get("detectedFaces", []) + if faces: + image = blur_faces(image, faces) + return image, faces + +#--------------------------------------------------------------------------------------# + +def update_analytics(faces): + current_time = get_current_time() + occupancy = len(faces) + st.session_state.occupancy_history.append((current_time, occupancy)) + cutoff = current_time - timedelta(seconds=OCCUPANCY_WINDOW_SEC) + st.session_state.occupancy_history = [ + (t, o) for t, o in st.session_state.occupancy_history if t >= cutoff + ] + st.session_state.occupancy_count = occupancy + +#--------------------------------------------------------------------------------------# + +def update_object_counts(objects): + """Accumulate detected object counts with up to last 5 timestamps each.""" + current_time = get_current_time() + # Initialize dict if not exists + if "object_counts" not in st.session_state: + st.session_state.object_counts = {} + + for obj in objects: + name = obj["name"] + if name not in st.session_state.object_counts: + st.session_state.object_counts[name] = {"timestamps": []} + st.session_state.object_counts[name]["timestamps"].append(current_time) + + # Keep only last 5 timestamps + st.session_state.object_counts[name]["timestamps"] = st.session_state.object_counts[name]["timestamps"][-5:] + + +#--------------------------------------------------------------------------------------# + +def consume_stream(namespace, bucket, prefix, client, frame_placeholder, chart_placeholder, mode, delay=0): + try: + objs = client.list_objects(namespace, bucket, prefix=prefix, limit=OBJECT_LIMIT).data.objects + if not objs: + frame_placeholder.markdown('

⚠️ No frames found.

', unsafe_allow_html=True) + return + + chart_ph = chart_placeholder.empty() + objs = sorted(objs, key=lambda o: o.name) + + for obj in objs: + content = client.get_object(namespace, bucket, obj.name).data.content.decode("utf-8") + frame, detections = process_frame(content, mode) + + if mode == DetectionMode.OBJECT.value: + update_object_counts(detections) + elif mode == DetectionMode.FACE.value: + update_analytics(detections) + + rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) + _, buffer = cv2.imencode(".jpg", rgb_frame) + frame_base64 = base64.b64encode(buffer).decode() + + frame_placeholder.markdown( + f'
', + unsafe_allow_html=True + ) + + # Different detections require different Analytics + if mode == DetectionMode.OBJECT.value and st.session_state.object_counts: + data = [] + for obj_name, info in st.session_state.object_counts.items(): + timestamps_str = ", ".join([t.strftime("%H:%M:%S") for t in info["timestamps"]]) + data.append([obj_name, timestamps_str]) + df_counts = pd.DataFrame(data, columns=["Object Detected", "Timestamps"]) + chart_ph.dataframe(df_counts, use_container_width=True) + + elif mode == DetectionMode.FACE.value and st.session_state.occupancy_history: + df_occupancy = pd.DataFrame(st.session_state.occupancy_history, columns=["Time", "Count"]) + df_occupancy["Time"] = pd.to_datetime(df_occupancy["Time"]) + peak_row = df_occupancy.loc[df_occupancy["Count"].idxmax()] + peak_time = peak_row["Time"] + peak_count = peak_row["Count"] + + col1, col2 = chart_ph.columns([2, 1]) + with col1: + chart = alt.Chart(df_occupancy).mark_line().encode( + x="Time:T", + y=alt.Y("Count:Q", scale=alt.Scale(domain=[0, 10])) + ).properties(width=FRAME_WIDTH, height=FRAME_HEIGHT, title="Occupancy Over Time") + col1.altair_chart(chart, use_container_width=False) + with col2: + col2.markdown("### Peak Occupancy") + col2.markdown(f"**Count:** {peak_count}") + col2.markdown(f"**Time:** {peak_time.strftime('%Y-%m-%d %H:%M:%S')}") + + time.sleep(delay) + + except Exception as e: + st.error(f"Error reading stored frames: {e}") + + + +#--------------------------------------------------------------------------------------# +#-----------------------------------PAGE SETUP-----------------------------------------# +#--------------------------------------------------------------------------------------# + + + +logo_base64 = get_base64_image('../media/oracle_logo.png') +st.markdown( + f""" + + """, + unsafe_allow_html=True +) +st.markdown("


", unsafe_allow_html=True) + +col1, col2 = st.columns([1, 3]) + +with col1: + st.session_state.mode = st.radio( + "Detection Mode", + [DetectionMode.OBJECT.value, DetectionMode.FACE.value], + index=0 + ) + + st.session_state.stream_job_ocid = st.text_input("Stream Job OCID", value=st.session_state.stream_job_ocid) + st.session_state.bucket = st.text_input("Bucket Name") + st.session_state.prefix = st.text_input("Prefix") + st.session_state.os_namespace = st.text_input("Object Storage Namespace") + +with col2: + frame_placeholder = st.empty() + frame_placeholder.markdown('

🎥 Waiting for stream...

', unsafe_allow_html=True) + +def toggle_streaming(): + st.session_state.streaming = not st.session_state.streaming + st.session_state.start_stop_label = "⏹️ Stop Consumption" if st.session_state.streaming else "▶️ Start Consumption" + +st.button(st.session_state.start_stop_label, on_click=toggle_streaming) + +st.markdown("---") +chart_placeholder = st.empty() + +try: + token_file = oci_config["security_token_file"] + with open(token_file, "r") as f: + token = f.read() + + private_key = oci.signer.load_private_key_from_file(oci_config["key_file"]) + config = oci.config.from_file() + signer = oci.auth.signers.SecurityTokenSigner(token, private_key) + vision_client = oci.ai_vision.AIServiceVisionClient(config=config, signer=signer, service_endpoint=service_endpoint) + + if st.session_state.streaming: + if not all([st.session_state.stream_job_ocid, st.session_state.bucket, st.session_state.prefix, st.session_state.os_namespace]): + st.error("Please provide all required Stream Job and Object Storage details") + else: + storage_client = oci.object_storage.ObjectStorageClient(config, signer=signer) + consume_stream( + st.session_state.os_namespace, + st.session_state.bucket, + st.session_state.prefix, + storage_client, + frame_placeholder, + chart_placeholder, + st.session_state.mode + ) + else: + frame_placeholder.markdown('

⏹️ Stream stopped

', unsafe_allow_html=True) + +except Exception as e: + st.error(f"Operation failed: {e}") + diff --git a/ai/ai-vision/video-stream-analysis/files/style.css b/ai/ai-vision/video-stream-analysis/files/style.css new file mode 100644 index 000000000..c11e66485 --- /dev/null +++ b/ai/ai-vision/video-stream-analysis/files/style.css @@ -0,0 +1,54 @@ +[data-testid="collapsedControl"] { display: none; } +header, footer, #MainMenu { visibility: hidden; } + +.video-box { + width: 100%; + max-width: 800px; + height: 397px; + border: 3px solid #00ccff; + border-radius: 10px; + background-color: black; + display: flex; + align-items: center; + justify-content: center; + margin: 20px auto; +} +.video-box p { color: white; font-size: 20px; } + +button[kind="primary"] { + background-color: #c83530 !important; + color: white !important; + font-weight: bold !important; + border-radius: 8px !important; + padding: 0.6rem 1.2rem !important; + font-size: 1rem !important; + width: 200px; +} +button[kind="primary"]:hover { + background-color: #a42b26 !important; +} + +.banner { + position: fixed; + top: 0px; + width: 100%; + background-color: #454E50; + padding: 15px; + border-radius: 0 0 10px 10px; + display: flex; + align-items: center; + justify-content: center; + z-index: 1000; + left: 0; +} +.banner h1 { + color: #fff; + font-size: 2rem !important; + font-weight: 700 !important; + margin: 0; +} +.banner img { + height: 60px; + width: 60px; + margin-right: 15px; +} diff --git a/ai/ai-vision/video-stream-analysis/media/appUI.png b/ai/ai-vision/video-stream-analysis/media/appUI.png new file mode 100644 index 000000000..789a8ff65 Binary files /dev/null and b/ai/ai-vision/video-stream-analysis/media/appUI.png differ diff --git a/ai/ai-vision/video-stream-analysis/media/oracle_logo.png b/ai/ai-vision/video-stream-analysis/media/oracle_logo.png new file mode 100644 index 000000000..2dd799542 Binary files /dev/null and b/ai/ai-vision/video-stream-analysis/media/oracle_logo.png differ diff --git a/ai/ai-vision/video-stream-analysis/requirements.txt b/ai/ai-vision/video-stream-analysis/requirements.txt new file mode 100644 index 000000000..4ba8bffd9 --- /dev/null +++ b/ai/ai-vision/video-stream-analysis/requirements.txt @@ -0,0 +1,6 @@ +altair==5.5.0 +numpy==2.3.4 +oci==2.155.2 +pandas==1.5.3 +Pillow==12.0.0 +streamlit==1.47.0