Skip to content

Commit

Permalink
Merge pull request #459 from gitautoai/wes
Browse files Browse the repository at this point in the history
Fix an error in describe_image: You uploaded an unsupported image. Please make sure your image has of one the following formats: ['png', 'jpeg', 'gif', 'webp'].
  • Loading branch information
hiroshinishio authored Jan 7, 2025
2 parents a1e36c7 + 2b612de commit f586594
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions utils/extract_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@

@handle_exceptions(default_return_value=[], raise_on_error=False)
def extract_image_urls(text: str) -> list[dict[str, str]]:
"""Extract alt text and URLs from img tags in the given text.
"""Extract alt text and URLs from img tags in the given text. Excludes SVG images.
Example: <img width="1352" alt="Screenshot 2024-12-12 at 6 25 41 PM" src="https://github.com/user-attachments/assets/9f1e8ca9-068e-434d-b2f3-f438638268ef" />
"""
pattern = r'<img[^>]*alt="([^"]*)"[^>]*src="([^"]*)"[^>]*>'
matches = findall(pattern, text)
return [{"alt": alt, "url": url} for alt, url in matches]
return [
{"alt": alt, "url": url}
for alt, url in matches
if not url.lower().endswith(".svg")
]


def extract_urls(text: str) -> tuple[list[str], list[str]]:
Expand Down

0 comments on commit f586594

Please sign in to comment.