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

Quick fix to gr.utils.validate_url #2659

Merged
merged 4 commits into from
Nov 16, 2022
Merged

Quick fix to gr.utils.validate_url #2659

merged 4 commits into from
Nov 16, 2022

Conversation

abidlabs
Copy link
Member

@abidlabs abidlabs commented Nov 16, 2022

Context: we use gr.utils.validate_url to determine if a string is a URL or a filepath. The logic is quite simple -- we make a GET request to the URL and see if we get a result.

However, some common media hosting sites (e.g. WikiCommons) require a User Agent to be set when making a request -- otherwise, the request is immediately rejected. This fact causes gr.utils.validate_url to fail for these URLs. In addition, since we were checking for a strict 200 response, URLs that redirected to other URLs would fail.

This PR fixes those issues and add tests.

Code to reproduce:

import gradio as gr

with gr.Blocks() as demo:
    gr.Audio("https://upload.wikimedia.org/wikipedia/commons/e/ef/Yellowstone_sound_library_-_Grizzly_Bears_Roar_-_001.mp3")
    
demo.launch()

@github-actions
Copy link
Contributor

All the demos for this PR have been deployed at https://huggingface.co/spaces/gradio-pr-deploys/pr-2659-all-demos

Copy link
Collaborator

@freddyaboulton freddyaboulton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @abidlabs !

@@ -488,6 +489,20 @@ def test_list(self):
assert sanitize_list_for_csv([1, ["ab", "=de"]]) == [1, ["ab", "'=de"]]


class TestValidateURL:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably mark as flaky if for whatever reason these urls are unavailable

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks @freddyaboulton!

@abidlabs abidlabs merged commit 8ec0a1e into main Nov 16, 2022
@abidlabs abidlabs deleted the fix-validate branch November 16, 2022 20:21
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.

None yet

2 participants