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

Fixed a type bug where the validation was "binary" #2727

Merged
merged 3 commits into from
Nov 28, 2022
Merged

Fixed a type bug where the validation was "binary" #2727

merged 3 commits into from
Nov 28, 2022

Conversation

CoffeeVampir3
Copy link
Contributor

@CoffeeVampir3 CoffeeVampir3 commented Nov 27, 2022

Bugfix for the type component, without this fix it is impossible to pick "binary" or "bytes" files because one is thrown out by the validator and one is thrown out by the type check in the process single file loop.

In line 2113 the type was validated as either file or binary:

        valid_types = ["file", "binary"]
        if type not in valid_types:
            raise ValueError(
                f"Invalid value for parameter `type`: {type}. Please choose from one of: {valid_types}"
            )

However line 2183 preprocess single file wanted either "file" or "bytes"

            elif self.type == "bytes":

I have picked binary as the one to match because the documentation currently reflects the choice of "file" or "binary". No changes should be needed to existing docs.

Please see the following errors for reference:

Process single file value error:

  File "x/gradio/components.py", line 2189, in process_single_file
    raise ValueError(
ValueError: Unknown type: binary. Please choose from: 'file', 'bytes'.

Initialization error

  File "x/gradio/components.py", line 2115, in __init__
    raise ValueError(
ValueError: Invalid value for parameter `type`: bytes. Please choose from one of: ['file', 'binary']

Description

Please include:

  • relevant motivation
  • a summary of the change
  • which issue is fixed.
  • any additional dependencies that are required for this change.

Closes: # (issue)

Checklist:

  • I have performed a self-review of my own code
  • I have added a short summary of my change to the CHANGELOG.md
  • My code follows the style guidelines of this project
  • I have commented my code in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

A note about the CHANGELOG

Hello 👋 and thank you for contributing to Gradio!

All pull requests must update the change log located in CHANGELOG.md, unless the pull request is labeled with the "no-changelog-update" label.

Please add a brief summary of the change to the Upcoming Release > Full Changelog section of the CHANGELOG.md file and include
a link to the PR (formatted in markdown) and a link to your github profile (if you like). For example, "* Added a cool new feature by [@myusername](link-to-your-github-profile) in [PR 11111](https://github.com/gradio-app/gradio/pull/11111)".

If you would like to elaborate on your change further, feel free to include a longer explanation in the other sections.
If you would like an image/gif/video showcasing your feature, it may be best to edit the CHANGELOG file using the
GitHub web UI since that lets you upload files directly via drag-and-drop.

In line 2113 the type was validated as either file or binary:
```python
        valid_types = ["file", "binary"]
        if type not in valid_types:
            raise ValueError(
                f"Invalid value for parameter `type`: {type}. Please choose from one of: {valid_types}"
            )
```

However line 2183 preprocess single file wanted either "file" or "bytes"
```python
            elif self.type == "bytes":
```

I have arbitrarily picked binary as the one to match, but now they are both consistent.
@abidlabs
Copy link
Member

abidlabs commented Nov 28, 2022

Thank you for catching this @CoffeeVampir3. I'll add a test, and then credit you in the changelog and then go ahead and merge this

@abidlabs abidlabs merged commit 6c73e79 into gradio-app:main Nov 28, 2022
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

Successfully merging this pull request may close these issues.

2 participants