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) |