UI2Code / utils /tools.py
3v324v23's picture
Initial commit with latest files
d5d3bd0
raw
history blame contribute delete
896 Bytes
from PIL import Image
import base64
import io
from typing import Union
import yaml
def txt2string(path):
with open(path, 'r', encoding='utf-8') as file:
file_content = file.read()
return file_content
def base64_convert(image):
if isinstance(image,str):
img=Image.open(image)
buffered = io.BytesIO()
img.save(buffered, format="PNG")
img_str = base64.b64encode(buffered.getvalue()).decode("utf-8")
else:
buffered = io.BytesIO()
image.save(buffered, format="PNG")
img_str = base64.b64encode(buffered.getvalue()).decode("utf-8")
return img_str
def readable_history(history):
'''remove picture in history to make it readable.'''
pass
def load_config():
# Open the YAML file
with open('./config.yaml', 'r') as file:
# Load the contents of the file
config = yaml.safe_load(file)