chat-image-edit / src /utils.py
simonlee-cb's picture
feat: working gradio demo
c55fe6a
raw
history blame
443 Bytes
import base64
from fastapi import UploadFile
def image_path_to_base64(image_path: str) -> str:
with open(image_path, "rb") as image_file:
return base64.b64encode(image_file.read()).decode("utf-8")
def upload_file_to_base64(file: UploadFile) -> str:
return base64.b64encode(file.file.read()).decode("utf-8")
def image_path_to_uri(image_path: str) -> str:
return f"data:image/jpeg;base64,{image_path_to_base64(image_path)}"