summaryrefslogtreecommitdiffstats
path: root/g4f/image.py
diff options
context:
space:
mode:
authorHeiner Lohaus <hlohaus@users.noreply.github.com>2024-01-21 02:20:23 +0100
committerHeiner Lohaus <hlohaus@users.noreply.github.com>2024-01-21 02:20:23 +0100
commit9cbe9c1ccb2381e37402a36297f11a0f96b1b557 (patch)
treed5c8f96e7a5b774c1a8af923f8346e1633a3d1f3 /g4f/image.py
parentFix permissions (diff)
downloadgpt4free-9cbe9c1ccb2381e37402a36297f11a0f96b1b557.tar
gpt4free-9cbe9c1ccb2381e37402a36297f11a0f96b1b557.tar.gz
gpt4free-9cbe9c1ccb2381e37402a36297f11a0f96b1b557.tar.bz2
gpt4free-9cbe9c1ccb2381e37402a36297f11a0f96b1b557.tar.lz
gpt4free-9cbe9c1ccb2381e37402a36297f11a0f96b1b557.tar.xz
gpt4free-9cbe9c1ccb2381e37402a36297f11a0f96b1b557.tar.zst
gpt4free-9cbe9c1ccb2381e37402a36297f11a0f96b1b557.zip
Diffstat (limited to '')
-rw-r--r--g4f/image.py14
1 files changed, 7 insertions, 7 deletions
diff --git a/g4f/image.py b/g4f/image.py
index cfa22ab1..24ded915 100644
--- a/g4f/image.py
+++ b/g4f/image.py
@@ -112,7 +112,7 @@ def get_orientation(image: Image.Image) -> int:
"""
exif_data = image.getexif() if hasattr(image, 'getexif') else image._getexif()
if exif_data is not None:
- orientation = exif_data.get(274) # 274 corresponds to the orientation tag in EXIF
+ orientation = exif_data.get(274) # 274 corresponds to the orientation tag in EXIF
if orientation is not None:
return orientation
@@ -156,23 +156,23 @@ def to_base64(image: 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, prompt: str, preview: str="{image}?w=200&h=200") -> str:
+def format_images_markdown(images, alt: str, preview: str="{image}?w=200&h=200") -> str:
"""
Formats the given images as a markdown string.
Args:
images: The images to format.
- prompt (str): The prompt for the images.
+ alt (str): The alt for the images.
preview (str, optional): The preview URL format. Defaults to "{image}?w=200&h=200".
Returns:
str: The formatted markdown string.
"""
- if isinstance(images, list):
- images = [f"[![#{idx+1} {prompt}]({preview.replace('{image}', image)})]({image})" for idx, image in enumerate(images)]
- images = "\n".join(images)
+ if isinstance(images, str):
+ images = f"[![{alt}]({preview.replace('{image}', images)})]({images})"
else:
- images = f"[![{prompt}]({images})]({images})"
+ images = [f"[![#{idx+1} {alt}]({preview.replace('{image}', image)})]({image})" for idx, image in enumerate(images)]
+ images = "\n".join(images)
start_flag = "<!-- generated images start -->\n"
end_flag = "<!-- generated images end -->\n"
return f"\n{start_flag}{images}\n{end_flag}\n"