diff options
author | H Lohaus <hlohaus@users.noreply.github.com> | 2024-02-11 09:28:50 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-11 09:28:50 +0100 |
commit | 27812c57e76f8b189efe9a26451374f9da160b6d (patch) | |
tree | 80ab5e213794a598e70b5c5020d05768f9f443ef /g4f/image.py | |
parent | Merge pull request #1574 from Simatwa/main (diff) | |
parent | Improve preview in image generation of Gemini (diff) | |
download | gpt4free-27812c57e76f8b189efe9a26451374f9da160b6d.tar gpt4free-27812c57e76f8b189efe9a26451374f9da160b6d.tar.gz gpt4free-27812c57e76f8b189efe9a26451374f9da160b6d.tar.bz2 gpt4free-27812c57e76f8b189efe9a26451374f9da160b6d.tar.lz gpt4free-27812c57e76f8b189efe9a26451374f9da160b6d.tar.xz gpt4free-27812c57e76f8b189efe9a26451374f9da160b6d.tar.zst gpt4free-27812c57e76f8b189efe9a26451374f9da160b6d.zip |
Diffstat (limited to 'g4f/image.py')
-rw-r--r-- | g4f/image.py | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/g4f/image.py b/g4f/image.py index 93922c2e..01d6ae50 100644 --- a/g4f/image.py +++ b/g4f/image.py @@ -187,7 +187,7 @@ def to_base64_jpg(image: Image, compression_rate: float) -> str: image.save(output_buffer, format="JPEG", quality=int(compression_rate * 100)) return base64.b64encode(output_buffer.getvalue()).decode() -def format_images_markdown(images, alt: str, preview: str = None) -> str: +def format_images_markdown(images: Union[str, list], alt: str, preview: Union[str, list] = None) -> str: """ Formats the given images as a markdown string. @@ -202,9 +202,10 @@ def format_images_markdown(images, alt: str, preview: str = None) -> str: if isinstance(images, str): images = f"[![{alt}]({preview.replace('{image}', images) if preview else images})]({images})" else: + if not isinstance(preview, list): + preview = [preview.replace('{image}', image) if preview else image for image in images] images = [ - f"[![#{idx+1} {alt}]({preview.replace('{image}', image) if preview else image})]({image})" - for idx, image in enumerate(images) + f"[![#{idx+1} {alt}]({preview[idx]})]({image})" for idx, image in enumerate(images) ] images = "\n".join(images) start_flag = "<!-- generated images start -->\n" |