File size: 896 Bytes
d5d3bd0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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)