Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions veadk/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

import time
import requests


def read_file(file_path):
Expand All @@ -28,6 +29,14 @@ def formatted_timestamp():


def read_png_to_bytes(png_path: str) -> bytes:
with open(png_path, "rb") as f:
data = f.read()
# Determine whether it is a local file or a network file
if png_path.startswith(("http://", "https://")):
# Network file: Download via URL and return bytes
response = requests.get(png_path)
response.raise_for_status() # Check if the HTTP request is successful
return response.content
else:
# Local file
with open(png_path, "rb") as f:
data = f.read()
return data