summaryrefslogtreecommitdiffstats
path: root/g4f/image.py
diff options
context:
space:
mode:
authorH Lohaus <hlohaus@users.noreply.github.com>2024-11-23 00:17:35 +0100
committerGitHub <noreply@github.com>2024-11-23 00:17:35 +0100
commit431db7b8ea36667fe5dc4f7e4e5b740c6e8450e7 (patch)
tree6649d7d2c172709f11542f5a8bb2be6ab494bb83 /g4f/image.py
parentAdd speech synthesize from Gemini (#2404) (diff)
downloadgpt4free-0.3.6.2.tar
gpt4free-0.3.6.2.tar.gz
gpt4free-0.3.6.2.tar.bz2
gpt4free-0.3.6.2.tar.lz
gpt4free-0.3.6.2.tar.xz
gpt4free-0.3.6.2.tar.zst
gpt4free-0.3.6.2.zip
Diffstat (limited to 'g4f/image.py')
-rw-r--r--g4f/image.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/g4f/image.py b/g4f/image.py
index 114dcc13..e9abcb6e 100644
--- a/g4f/image.py
+++ b/g4f/image.py
@@ -33,10 +33,14 @@ EXTENSIONS_MAP: dict[str, str] = {
# Define the directory for generated images
images_dir = "./generated_images"
-def fix_url(url:str) -> str:
+def fix_url(url: str) -> str:
""" replace ' ' by '+' (to be markdown compliant)"""
return url.replace(" ","+")
+def fix_title(title: str) -> str:
+ if title:
+ return title.replace("\n", "").replace('"', '')
+
def to_image(image: ImageType, is_svg: bool = False) -> Image:
"""
Converts the input image to a PIL Image object.
@@ -226,12 +230,12 @@ def format_images_markdown(images: Union[str, list], alt: str, preview: Union[st
str: The formatted markdown string.
"""
if isinstance(images, str):
- result = f"[![{alt}]({fix_url(preview.replace('{image}', images) if preview else images)})]({fix_url(images)})"
+ result = f"[![{fix_title(alt)}]({fix_url(preview.replace('{image}', images) if preview else images)})]({fix_url(images)})"
else:
if not isinstance(preview, list):
preview = [preview.replace('{image}', image) if preview else image for image in images]
result = "\n".join(
- f"[![#{idx+1} {alt}]({fix_url(preview[idx])})]({fix_url(image)})"
+ f"[![#{idx+1} {fix_title(alt)}]({fix_url(preview[idx])})]({fix_url(image)})"
for idx, image in enumerate(images)
)
start_flag = "<!-- generated images start -->\n"