vision-agent 0.2.238__py3-none-any.whl → 0.2.240__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,7 +8,7 @@ from base64 import b64encode
8
8
  from concurrent.futures import ThreadPoolExecutor, as_completed
9
9
  from importlib import resources
10
10
  from pathlib import Path
11
- from typing import Any, Callable, Dict, List, Optional, Tuple, Union, cast
11
+ from typing import IO, Any, Callable, Dict, List, Optional, Tuple, Union, cast
12
12
  from uuid import UUID
13
13
 
14
14
  import cv2
@@ -2797,16 +2797,17 @@ def save_video(
2797
2797
  ):
2798
2798
  raise ValueError("A frame is not a valid NumPy array with shape (H, W, C)")
2799
2799
 
2800
+ output_file: IO[bytes]
2800
2801
  if output_video_path is None:
2801
- output_video_path = tempfile.NamedTemporaryFile(
2802
- delete=False, suffix=".mp4"
2803
- ).name
2802
+ output_file = tempfile.NamedTemporaryFile(delete=False, suffix=".mp4")
2804
2803
  else:
2805
2804
  Path(output_video_path).parent.mkdir(parents=True, exist_ok=True)
2805
+ output_file = open(output_video_path, "wb")
2806
2806
 
2807
- output_video_path = video_writer(frames, fps, output_video_path)
2808
- _save_video_to_result(output_video_path)
2809
- return output_video_path
2807
+ with output_file as file:
2808
+ video_writer(frames, fps, file=file)
2809
+ _save_video_to_result(output_file.name)
2810
+ return output_file.name
2810
2811
 
2811
2812
 
2812
2813
  def _save_video_to_result(video_uri: str) -> None:
@@ -1,8 +1,7 @@
1
- import base64
2
1
  import logging
3
2
  import tempfile
4
3
  from functools import lru_cache
5
- from typing import List, Optional, Tuple
4
+ from typing import IO, List, Optional, Tuple
6
5
 
7
6
  import av # type: ignore
8
7
  import cv2
@@ -15,37 +14,6 @@ _DEFAULT_VIDEO_FPS = 24
15
14
  _DEFAULT_INPUT_FPS = 1.0
16
15
 
17
16
 
18
- def play_video(video_base64: str) -> None:
19
- """Play a video file"""
20
- video_data = base64.b64decode(video_base64)
21
- with tempfile.NamedTemporaryFile(delete=False, suffix=".mp4") as temp_video:
22
- temp_video.write(video_data)
23
- temp_video_path = temp_video.name
24
-
25
- cap = cv2.VideoCapture(temp_video_path)
26
- if not cap.isOpened():
27
- _LOGGER.error("Error: Could not open video.")
28
- return
29
-
30
- # Display the first frame and wait for any key press to start the video
31
- ret, frame = cap.read()
32
- if ret:
33
- cv2.imshow("Video Player", frame)
34
- _LOGGER.info(f"Press any key to start playing the video: {temp_video_path}")
35
- cv2.waitKey(0) # Wait for any key press
36
-
37
- while cap.isOpened():
38
- ret, frame = cap.read()
39
- if not ret:
40
- break
41
- cv2.imshow("Video Player", frame)
42
- # Press 'q' to exit the video
43
- if cv2.waitKey(200) & 0xFF == ord("q"):
44
- break
45
- cap.release()
46
- cv2.destroyAllWindows()
47
-
48
-
49
17
  def _resize_frame(frame: np.ndarray) -> np.ndarray:
50
18
  height, width = frame.shape[:2]
51
19
  new_width = width - (width % 2)
@@ -56,33 +24,32 @@ def _resize_frame(frame: np.ndarray) -> np.ndarray:
56
24
  def video_writer(
57
25
  frames: List[np.ndarray],
58
26
  fps: float = _DEFAULT_INPUT_FPS,
59
- filename: Optional[str] = None,
27
+ file: Optional[IO[bytes]] = None,
60
28
  ) -> str:
61
29
  if isinstance(fps, str):
62
30
  # fps could be a string when it's passed in from a web endpoint deployment
63
31
  fps = float(fps)
64
- if filename is None:
65
- filename = tempfile.NamedTemporaryFile(delete=False, suffix=".mp4").name
66
- container = av.open(filename, mode="w")
67
- stream = container.add_stream("h264", rate=fps)
68
- height, width = frames[0].shape[:2]
69
- stream.height = height - (height % 2)
70
- stream.width = width - (width % 2)
71
- stream.pix_fmt = "yuv420p"
72
- stream.options = {"crf": "10"}
73
- for frame in frames:
74
- # Remove the alpha channel (convert RGBA to RGB)
75
- frame_rgb = frame[:, :, :3]
76
- # Resize the frame to make dimensions divisible by 2
77
- frame_rgb = _resize_frame(frame_rgb)
78
- av_frame = av.VideoFrame.from_ndarray(frame_rgb, format="rgb24")
79
- for packet in stream.encode(av_frame):
32
+ if file is None:
33
+ file = tempfile.NamedTemporaryFile(delete=False, suffix=".mp4")
34
+ with av.open(file, "w") as container:
35
+ stream = container.add_stream("h264", rate=fps)
36
+ height, width = frames[0].shape[:2]
37
+ stream.height = height - (height % 2)
38
+ stream.width = width - (width % 2)
39
+ stream.pix_fmt = "yuv420p"
40
+ stream.options = {"crf": "10"}
41
+ for frame in frames:
42
+ # Remove the alpha channel (convert RGBA to RGB)
43
+ frame_rgb = frame[:, :, :3]
44
+ # Resize the frame to make dimensions divisible by 2
45
+ frame_rgb = _resize_frame(frame_rgb)
46
+ av_frame = av.VideoFrame.from_ndarray(frame_rgb, format="rgb24")
47
+ for packet in stream.encode(av_frame):
48
+ container.mux(packet)
49
+
50
+ for packet in stream.encode():
80
51
  container.mux(packet)
81
-
82
- for packet in stream.encode():
83
- container.mux(packet)
84
- container.close()
85
- return filename
52
+ return file.name
86
53
 
87
54
 
88
55
  def frames_to_bytes(
@@ -98,11 +65,10 @@ def frames_to_bytes(
98
65
  if isinstance(fps, str):
99
66
  # fps could be a string when it's passed in from a web endpoint deployment
100
67
  fps = float(fps)
101
- with tempfile.NamedTemporaryFile(delete=True, suffix=file_ext) as temp_file:
102
- video_writer(frames, fps, temp_file.name)
103
-
104
- with open(temp_file.name, "rb") as f:
105
- buffer_bytes = f.read()
68
+ with tempfile.NamedTemporaryFile(delete=True, suffix=file_ext) as f:
69
+ video_writer(frames, fps, f)
70
+ f.seek(0)
71
+ buffer_bytes = f.read()
106
72
  return buffer_bytes
107
73
 
108
74
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: vision-agent
3
- Version: 0.2.238
3
+ Version: 0.2.240
4
4
  Summary: Toolset for Vision Agent
5
5
  Author: Landing AI
6
6
  Author-email: dev@landing.ai
@@ -38,7 +38,7 @@ vision_agent/tools/__init__.py,sha256=T-MPNBVbvWtfo71hobaZsdYzQ52oyymolk_OAb2Pq_
38
38
  vision_agent/tools/meta_tools.py,sha256=-heMwGkx0hX_9zUp1dgBqsJpVnl6Y6tErMsjFy0dwLM,28652
39
39
  vision_agent/tools/planner_tools.py,sha256=orBTdJQz2NKoLuX9WE6XixaYuG305xz0UBYvZOiuquQ,19474
40
40
  vision_agent/tools/prompts.py,sha256=V1z4YJLXZuUl_iZ5rY0M5hHc_2tmMEUKr0WocXKGt4E,1430
41
- vision_agent/tools/tools.py,sha256=-xg5Msq5ZtHgaISpHnbq5rJ5MIERwfH6wPHg6KpaYjg,111457
41
+ vision_agent/tools/tools.py,sha256=8J-SYpyUeqMDajF7kp2aiTeBBQrJEWGVdEsQLPAc-OM,111511
42
42
  vision_agent/utils/__init__.py,sha256=mANUs_84VL-3gpZbXryvV2mWU623eWnRlJCSUHtMjuw,122
43
43
  vision_agent/utils/agent.py,sha256=QGKcbzpAjcVj0958bXYLv07-d2i1GU7-bXVG7bTGRMA,14619
44
44
  vision_agent/utils/exceptions.py,sha256=booSPSuoULF7OXRr_YbC4dtKt6gM_HyiFQHBuaW86C4,2052
@@ -47,9 +47,9 @@ vision_agent/utils/image_utils.py,sha256=bJM2mEvB6E__M9pxi74yQYzAiZ7mu3KE2ptyVrp
47
47
  vision_agent/utils/tools.py,sha256=USZL0MKsiJgqA8RFiYRTcj_Kn2FVYKLHK4wIk0gP1Ow,7694
48
48
  vision_agent/utils/tools_doc.py,sha256=yFue6KSXoa_Z1ngCdBEc4SdPZOWF1rVLeaHu02I8Wis,2523
49
49
  vision_agent/utils/type_defs.py,sha256=BE12s3JNQy36QvauXHjwyeffVh5enfcvd4vTzSwvEZI,1384
50
- vision_agent/utils/video.py,sha256=Dt9_pqGgr63gmpurzisnpF6d9tr65-zxS1CccXdVuxk,6458
50
+ vision_agent/utils/video.py,sha256=rjsQ1sKKisaQ6AVjJz0zd_G4g-ovRweS_rs4JEhenoI,5340
51
51
  vision_agent/utils/video_tracking.py,sha256=GM9qfeawqhmZVWoKrzw5-NETd4gEo7ImMfWtBnhC3bw,12086
52
- vision_agent-0.2.238.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
53
- vision_agent-0.2.238.dist-info/METADATA,sha256=VnupHm4Iav889sO4JPGeWYM7902KwPKaJYem81_EDCk,5712
54
- vision_agent-0.2.238.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
55
- vision_agent-0.2.238.dist-info/RECORD,,
52
+ vision_agent-0.2.240.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
53
+ vision_agent-0.2.240.dist-info/METADATA,sha256=l9FlzNIT3ncQNxkIlTTUsB1aaL-7u2b1OtvYcRv0AIE,5712
54
+ vision_agent-0.2.240.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
55
+ vision_agent-0.2.240.dist-info/RECORD,,