Skip to content

Commit

Permalink
chg: more docker services
Browse files Browse the repository at this point in the history
  • Loading branch information
bossjones committed Aug 17, 2024
1 parent cb4d57f commit 63b26ac
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions REFERENCES.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,4 @@ source: <https://www.youtube.com/watch?v=AeASAsPp9LE>
- https://github.com/langchain-ai/langchain/tree/master/cookbook
- https://github.com/codingjoe/relint - `Write your own linting rules using regular expressions.`
- https://github.com/ionelmc/python-manhole/ - `Debugging manhole for python applications.`
- https://github.com/langchain-ai/langchain/blob/master/cookbook/Multi_modal_RAG.ipynb
34 changes: 34 additions & 0 deletions src/goob_ai/utils/imgops.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import os
import os.path
import pathlib
import re
import sys
import tempfile
import time
Expand Down Expand Up @@ -103,6 +104,39 @@ def setup_model() -> torch.nn.Module:
###########################################################################3


def looks_like_base64(sb):
"""Check if the string looks like base64"""
return re.match("^[A-Za-z0-9+/]+[=]{0,2}$", sb) is not None

Check warning on line 109 in src/goob_ai/utils/imgops.py

View check run for this annotation

Codecov / codecov/patch

src/goob_ai/utils/imgops.py#L109

Added line #L109 was not covered by tests


def is_image_data(b64data):
"""
Check if the base64 data is an image by looking at the start of the data
"""
image_signatures = {

Check warning on line 116 in src/goob_ai/utils/imgops.py

View check run for this annotation

Codecov / codecov/patch

src/goob_ai/utils/imgops.py#L116

Added line #L116 was not covered by tests
b"\xff\xd8\xff": "jpg",
b"\x89\x50\x4e\x47\x0d\x0a\x1a\x0a": "png",
b"\x47\x49\x46\x38": "gif",
b"\x52\x49\x46\x46": "webp",
}
try:
header = base64.b64decode(b64data)[:8] # Decode and get the first 8 bytes

Check warning on line 123 in src/goob_ai/utils/imgops.py

View check run for this annotation

Codecov / codecov/patch

src/goob_ai/utils/imgops.py#L122-L123

Added lines #L122 - L123 were not covered by tests
for sig, format in image_signatures.items():
if header.startswith(sig):
return True
return False
except Exception:
return False

Check warning on line 129 in src/goob_ai/utils/imgops.py

View check run for this annotation

Codecov / codecov/patch

src/goob_ai/utils/imgops.py#L126-L129

Added lines #L126 - L129 were not covered by tests


# SOURCE: https://github.com/langchain-ai/langchain/blob/master/cookbook/multi_modal_QA.ipynb
def encode_image(image_path: str):
"""Getting the base64 string"""

with open(image_path, "rb") as image_file:
return base64.b64encode(image_file.read()).decode("utf-8")

Check warning on line 137 in src/goob_ai/utils/imgops.py

View check run for this annotation

Codecov / codecov/patch

src/goob_ai/utils/imgops.py#L137

Added line #L137 was not covered by tests


def split_image_text_types(docs):
"""Split numpy array images and texts"""
images = []
Expand Down

0 comments on commit 63b26ac

Please sign in to comment.