-
Notifications
You must be signed in to change notification settings - Fork 244
feat: image url #811
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat: image url #811
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
941c0f9
feat: add tensor type for ndarray
JohannesMessner 4a0f7bf
fix: fix mypy typing
JohannesMessner f451044
Merge remote-tracking branch 'origin/feat-rewrite-v2' into feat-rewri…
JohannesMessner 04583d4
Merge remote-tracking branch 'origin/feat-rewrite-v2' into feat-rewri…
JohannesMessner 1d9eaaf
feat: torch tensor type
JohannesMessner e820675
fix: protobuf for pytorch type
JohannesMessner 4b449aa
ci: install all extras in the ci
JohannesMessner 633b701
refactor: make nice looking
JohannesMessner 492659e
docs: update docarray/typing/tensor/torch_tensor.py
JohannesMessner a5c1a31
refactor: code style
JohannesMessner 8df13c1
fix: black and mypy
JohannesMessner 28f1ed0
fix: suppress mypy import error
JohannesMessner 4df03ef
ci: fix ci install
JohannesMessner 81f7810
feat: add new type for image urls
JohannesMessner d14d4af
feat: add new type for image urls
JohannesMessner 370b7fa
Merge branch 'feat-rewrite-v2' into feat-image-url
JohannesMessner 3b6d5b9
test: add real existing url to test
JohannesMessner ba8adf0
test: test output of image buffer loading
JohannesMessner 75a440c
feat: add validation for image url
JohannesMessner 5b90769
feat: specify image axis permutation
JohannesMessner 289ee15
docs: add docstrings
JohannesMessner f8a8129
docs: make strings uniform
JohannesMessner 4512286
test: pass valid url as imageurl
JohannesMessner 5ed9ec1
Merge branch 'feat-rewrite-v2' into feat-image-url
JohannesMessner 5452e09
Merge branch 'feat-rewrite-v2' into feat-image-url
JohannesMessner d9cbef6
chore: fix dependencies
JohannesMessner ec6ac68
chore(ci): add extras to mypy ci
samsja File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import os | ||
| import urllib.parse | ||
| import urllib.request | ||
| from contextlib import nullcontext | ||
|
|
||
|
|
||
| def _uri_to_blob(uri: str, timeout=None) -> bytes: | ||
| """Convert uri to blob | ||
| Internally it reads uri into blob. | ||
| :param uri: the uri of Document | ||
| :param timeout: timeout for urlopen. Only relevant if uri is not local | ||
| :return: blob bytes. | ||
| """ | ||
| if urllib.parse.urlparse(uri).scheme in {'http', 'https', 'data'}: | ||
| req = urllib.request.Request(uri, headers={'User-Agent': 'Mozilla/5.0'}) | ||
| urlopen_kwargs = {'timeout': timeout} if timeout is not None else {} | ||
| with urllib.request.urlopen(req, **urlopen_kwargs) as fp: | ||
| return fp.read() | ||
| elif os.path.exists(uri): | ||
| with open(uri, 'rb') as fp: | ||
| return fp.read() | ||
| else: | ||
| raise FileNotFoundError(f'`{uri}` is not a URL or a valid local path') | ||
|
|
||
|
|
||
| def _get_file_context(file): | ||
| if hasattr(file, 'write'): | ||
| file_ctx = nullcontext(file) | ||
| else: | ||
| file_ctx = open(file, 'wb') | ||
|
|
||
| return file_ctx | ||
|
|
||
|
|
||
| def _is_uri(value: str) -> bool: | ||
| scheme = urllib.parse.urlparse(value).scheme | ||
| return ( | ||
| (scheme in {'http', 'https'}) | ||
| or (scheme in {'data'}) | ||
| or os.path.exists(value) | ||
| or os.access(os.path.dirname(value), os.W_OK) | ||
| ) | ||
|
|
||
|
|
||
| def _is_datauri(value: str) -> bool: | ||
| scheme = urllib.parse.urlparse(value).scheme | ||
| return scheme in {'data'} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.