Skip to content
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

[ENHANCEMENT] Improve ImageField error messaging to deal with paths, urls, none #5513

Open
cceyda opened this issue Sep 19, 2024 · 2 comments
Milestone

Comments

@cceyda
Copy link
Contributor

cceyda commented Sep 19, 2024

Is your feature request related to a problem? Please describe.
I'm already hosting my images independently. I don't wanna save he image inside the argilla dataset just the url... there currently doesn't seem to be a way to do this using ImageField (I was hoping this was what was meant by image support but ended up having to rollback to markdown hack again)

Describe the solution you'd like
ImageField should support urls

Describe alternatives you've considered
Use markdown

Additional context

@burtenshaw
Copy link
Contributor

@cceyda Thanks for the issue. rg.ImageField already supports public urls, defined within the Record fields param. Do you have an example/error where you've tried this.

Here's the docs: https://docs.argilla.io/latest/reference/argilla/records/records/

@cceyda
Copy link
Contributor Author

cceyda commented Sep 19, 2024

For rg.ImageField(name="image",required=False) & and a record with fields = { "image": "https://..."}
I got an error complaining about paths so I assumed:

File ~/workspace/WORK/base_11/lib/python3.11/site-packages/argilla/records/_resource.py:281, in <dictcomp>(.0)
    [280](https://file+.vscode-resource.vscode-cdn.net/Users/ceyda.1/workspace/WORK/data-ml/title-attribute/notebooks/data/~/workspace/WORK/base_11/lib/python3.11/site-packages/argilla/records/_resource.py:280) def to_dict(self) -> dict:
--> [281](https://file+.vscode-resource.vscode-cdn.net/Users/ceyda.1/workspace/WORK/data-ml/title-attribute/notebooks/data/~/workspace/WORK/base_11/lib/python3.11/site-packages/argilla/records/_resource.py:281)     return {key: cast_image(value) if self._is_image(key) else value for key, value in self.items()}

File ~/workspace/WORK/base_11/lib/python3.11/site-packages/argilla/_helpers/_media.py:80, in cast_image(image)
     [78](https://file+.vscode-resource.vscode-cdn.net/Users/ceyda.1/workspace/WORK/data-ml/title-attribute/notebooks/data/~/workspace/WORK/base_11/lib/python3.11/site-packages/argilla/_helpers/_media.py:78)         return image
     [79](https://file+.vscode-resource.vscode-cdn.net/Users/ceyda.1/workspace/WORK/data-ml/title-attribute/notebooks/data/~/workspace/WORK/base_11/lib/python3.11/site-packages/argilla/_helpers/_media.py:79)     else:
---> [80](https://file+.vscode-resource.vscode-cdn.net/Users/ceyda.1/workspace/WORK/data-ml/title-attribute/notebooks/data/~/workspace/WORK/base_11/lib/python3.11/site-packages/argilla/_helpers/_media.py:80)         return filepath_to_data_uri(image)
     [81](https://file+.vscode-resource.vscode-cdn.net/Users/ceyda.1/workspace/WORK/data-ml/title-attribute/notebooks/data/~/workspace/WORK/base_11/lib/python3.11/site-packages/argilla/_helpers/_media.py:81) elif isinstance(image, Path):
     [82](https://file+.vscode-resource.vscode-cdn.net/Users/ceyda.1/workspace/WORK/data-ml/title-attribute/notebooks/data/~/workspace/WORK/base_11/lib/python3.11/site-packages/argilla/_helpers/_media.py:82)     return filepath_to_data_uri(image)

File ~/workspace/WORK/base_11/lib/python3.11/site-packages/argilla/_helpers/_media.py:59, in filepath_to_data_uri(file_path)
     [57](https://file+.vscode-resource.vscode-cdn.net/Users/ceyda.1/workspace/WORK/data-ml/title-attribute/notebooks/data/~/workspace/WORK/base_11/lib/python3.11/site-packages/argilla/_helpers/_media.py:57) file_path = Path(file_path)
     [58](https://file+.vscode-resource.vscode-cdn.net/Users/ceyda.1/workspace/WORK/data-ml/title-attribute/notebooks/data/~/workspace/WORK/base_11/lib/python3.11/site-packages/argilla/_helpers/_media.py:58) if file_path.exists():
---> [59](https://file+.vscode-resource.vscode-cdn.net/Users/ceyda.1/workspace/WORK/data-ml/title-attribute/notebooks/data/~/workspace/WORK/base_11/lib/python3.11/site-packages/argilla/_helpers/_media.py:59)     with open(file_path, "rb") as image_file:
     [60](https://file+.vscode-resource.vscode-cdn.net/Users/ceyda.1/workspace/WORK/data-ml/title-attribute/notebooks/data/~/workspace/WORK/base_11/lib/python3.11/site-packages/argilla/_helpers/_media.py:60)         img_str = base64.b64encode(image_file.read()).decode()
     [61](https://file+.vscode-resource.vscode-cdn.net/Users/ceyda.1/workspace/WORK/data-ml/title-attribute/notebooks/data/~/workspace/WORK/base_11/lib/python3.11/site-packages/argilla/_helpers/_media.py:61)         mimetype = f"image/{file_path.suffix[1:]}"

IsADirectoryError: [Errno 21] Is a directory: '.'

But now that I retried it, it was giving this error when image field was None. So I guess this just needs better error message or None handling when it is not a required field 👍

@burtenshaw burtenshaw added this to the v2.3.0 milestone Sep 24, 2024
@burtenshaw burtenshaw changed the title [FEATURE] ImageField allow url as input [ENHANCEMENT] Improve ImageField error messaging to deal with paths, urls, none Sep 24, 2024
@burtenshaw burtenshaw modified the milestones: v2.3.0, v2.4.0 Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants