Skip to content

Commit f3a818f

Browse files
authored
Feat/load env variables (#754)
* remove extra api key usage * auto load env variables
1 parent 07e3de6 commit f3a818f

File tree

13 files changed

+22
-44
lines changed

13 files changed

+22
-44
lines changed

apps/default-app/README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ Here is a list of all available parameters:
1717
```
1818
-d DEVICE, --device DEVICE
1919
Optional name, DeviceID or IP of the camera to connect to. (default: None)
20-
-api API_KEY, --api_key API_KEY
21-
HubAI API key to access private model. (default: )
2220
```
2321

2422
## Peripheral Mode

apps/default-app/main.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,7 @@
2525
f"yolov6_nano_r2_coco.{platform.name}.yaml"
2626
)
2727

28-
nn_archive = dai.NNArchive(
29-
dai.getModelFromZoo(
30-
model_description,
31-
apiKey=args.api_key,
32-
)
33-
)
28+
nn_archive = dai.NNArchive(dai.getModelFromZoo(model_description))
3429
cameraNode = pipeline.create(dai.node.Camera).build(dai.CameraBoardSocket.CAM_A)
3530

3631
if platform == dai.Platform.RVC2:

apps/default-app/utils/arguments.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,6 @@ def initialize_argparser():
1717
type=str,
1818
)
1919

20-
parser.add_argument(
21-
"-api",
22-
"--api_key",
23-
help="HubAI API key to access private model.",
24-
required=False,
25-
default="",
26-
type=str,
27-
)
28-
2920
args = parser.parse_args()
3021

3122
return parser, args

integrations/hub-snaps-events/main.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from pathlib import Path
33
from functools import partial
44
from typing import Dict
5+
from dotenv import load_dotenv
56

67
import depthai as dai
78
from depthai_nodes.node import (
@@ -11,6 +12,8 @@
1112
)
1213
from utils.arguments import initialize_argparser
1314

15+
load_dotenv(override=True)
16+
1417
_, args = initialize_argparser()
1518

1619
if args.fps_limit and args.media_path:
@@ -19,13 +22,12 @@
1922
"WARNING: FPS limit is set but media path is provided. FPS limit will be ignored."
2023
)
2124

25+
if args.api_key:
26+
os.environ["DEPTHAI_HUB_API_KEY"] = args.api_key
2227

2328
visualizer = dai.RemoteConnection(httpPort=8082)
2429
device = dai.Device(dai.DeviceInfo(args.device)) if args.device else dai.Device()
2530

26-
if args.api_key:
27-
os.environ["DEPTHAI_HUB_API_KEY"] = args.api_key
28-
2931

3032
def custom_snap_process(
3133
producer: SnapsProducer,

integrations/hub-snaps-events/oakapp.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ build_steps = []
1414

1515
depthai_models = { yaml_path = "./depthai_models" }
1616

17-
entrypoint = ["bash", "-c", "python3 -u /app/main.py --api-key <API_KEY>"]
17+
entrypoint = ["bash", "-c", "python3 -u /app/main.py"]
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
depthai==3.0.0rc2
22
depthai-nodes==0.3.0
3+
python-dotenv
4+

neural-networks/generic-example/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Here is a list of all available parameters:
2121
-media MEDIA_PATH, --media_path MEDIA_PATH
2222
Path to the media file you aim to run the model on. If not set, the model will run on the camera input. (default: None)
2323
-api API_KEY, --api_key API_KEY
24-
HubAI API key to access private model. (default: )
24+
HubAI API key to access private model. Can also use 'DEPTHAI_HUB_API_KEY' environment variable instead. (default: )
2525
-overlay OVERLAY_MODE, --overlay_mode
2626
If passed, overlays model output on the input image when the output is an array (e.g., depth maps, segmentation maps). Otherwise, displays outputs separately.
2727
```

neural-networks/generic-example/main.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
1+
import os
2+
from dotenv import load_dotenv
3+
14
import depthai as dai
25
from depthai_nodes.node import ParsingNeuralNetwork, ImgFrameOverlay, ApplyColormap
36

47
from utils.arguments import initialize_argparser
58
from utils.input import create_input_node
69

10+
load_dotenv(override=True)
11+
712
_, args = initialize_argparser()
813

14+
if args.api_key:
15+
os.environ["DEPTHAI_HUB_API_KEY"] = args.api_key
16+
917
visualizer = dai.RemoteConnection(httpPort=8082)
1018
device = dai.Device(dai.DeviceInfo(args.device)) if args.device else dai.Device()
1119
platform = device.getPlatformAsString()
@@ -18,13 +26,7 @@
1826
model_description = dai.NNModelDescription(f"yolov6_nano_r2_coco.{platform}.yaml")
1927
if model_description.model != args.model:
2028
model_description = dai.NNModelDescription(args.model, platform=platform)
21-
22-
nn_archive = dai.NNArchive(
23-
dai.getModelFromZoo(
24-
model_description,
25-
apiKey=args.api_key,
26-
)
27-
)
29+
nn_archive = dai.NNArchive(dai.getModelFromZoo(model_description))
2830

2931
# media/camera input
3032
input_node = create_input_node(

neural-networks/generic-example/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ depthai==3.0.0rc2
22
depthai-nodes==0.3.2
33
opencv-python-headless~=4.10.0
44
numpy>=1.22
5+
python-dotenv

neural-networks/generic-example/utils/arguments.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def initialize_argparser():
5151
parser.add_argument(
5252
"-api",
5353
"--api_key",
54-
help="HubAI API key to access private model.",
54+
help="HubAI API key to access private model. Can also use 'DEPTHAI_HUB_API_KEY' environment variable instead.",
5555
required=False,
5656
default="",
5757
type=str,

0 commit comments

Comments
 (0)