[Multimodal][Perf] Use pybase64 instead of base64 (#7724)
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
"""Common utilities"""
|
||||
|
||||
import base64
|
||||
import importlib
|
||||
import json
|
||||
import logging
|
||||
@@ -20,6 +19,7 @@ from json import dumps
|
||||
from typing import Any, Callable, List, Optional, Tuple, Type, Union
|
||||
|
||||
import numpy as np
|
||||
import pybase64
|
||||
import requests
|
||||
from IPython.display import HTML, display
|
||||
from pydantic import BaseModel
|
||||
@@ -148,15 +148,15 @@ def encode_image_base64(image_path: Union[str, bytes]):
|
||||
if isinstance(image_path, str):
|
||||
with open(image_path, "rb") as image_file:
|
||||
data = image_file.read()
|
||||
return base64.b64encode(data).decode("utf-8")
|
||||
return pybase64.b64encode(data).decode("utf-8")
|
||||
elif isinstance(image_path, bytes):
|
||||
return base64.b64encode(image_path).decode("utf-8")
|
||||
return pybase64.b64encode(image_path).decode("utf-8")
|
||||
else:
|
||||
# image_path is PIL.WebPImagePlugin.WebPImageFile
|
||||
image = image_path
|
||||
buffered = BytesIO()
|
||||
image.save(buffered, format="PNG")
|
||||
return base64.b64encode(buffered.getvalue()).decode("utf-8")
|
||||
return pybase64.b64encode(buffered.getvalue()).decode("utf-8")
|
||||
|
||||
|
||||
def encode_frame(frame):
|
||||
@@ -223,7 +223,7 @@ def encode_video_base64(video_path: str, num_frames: int = 16):
|
||||
video_bytes = b"".join(encoded_frames)
|
||||
|
||||
# Encode the concatenated bytes to base64
|
||||
video_base64 = "video:" + base64.b64encode(video_bytes).decode("utf-8")
|
||||
video_base64 = "video:" + pybase64.b64encode(video_bytes).decode("utf-8")
|
||||
|
||||
return video_base64
|
||||
|
||||
|
||||
Reference in New Issue
Block a user