diff --git a/modules/html_generator.py b/modules/html_generator.py index df92f2fd..2859265b 100644 --- a/modules/html_generator.py +++ b/modules/html_generator.py @@ -7,8 +7,11 @@ This is a library for formatting GPT-4chan and chat outputs as nice HTML. import base64 import copy import re +from io import BytesIO from pathlib import Path +from PIL import Image + def generate_basic_html(s): css = """ .container { @@ -178,6 +181,13 @@ def generate_4chan_html(f): return output +def image_to_base64(path): + img = Image.open(path) + img.thumbnail((100, 100)) + img_buffer = BytesIO() + img.convert('RGB').save(img_buffer, format='PNG') + return base64.b64encode(img_buffer.getvalue()).decode("utf-8") + def generate_chat_html(history, name1, name2, character): css = """ .chat { @@ -251,6 +261,7 @@ def generate_chat_html(history, name1, name2, character): output = '' output += f'