Fixes method to resolve the root URLs (#7565)

* fix

* fix

* add changeset

* fix test

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
This commit is contained in:
Abubakar Abid 2024-03-04 07:52:49 -08:00 committed by GitHub
parent 3940490fc0
commit 1c22123268
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 12 additions and 6 deletions

View File

@ -0,0 +1,5 @@
---
"gradio": patch
---
fix:Fixes method to resolve the `root` URLs

View File

@ -299,10 +299,11 @@ def move_files_to_cache(
def add_root_url(data: dict, root_url: str, previous_root_url: str | None) -> dict:
def _add_root_url(file_dict: dict):
if not client_utils.is_http_url_like(file_dict["url"]):
if previous_root_url and file_dict["url"].startswith(previous_root_url):
file_dict["url"] = file_dict["url"][len(previous_root_url) :]
file_dict["url"] = f'{root_url}{file_dict["url"]}'
if previous_root_url and file_dict["url"].startswith(previous_root_url):
file_dict["url"] = file_dict["url"][len(previous_root_url) :]
elif client_utils.is_http_url_like(file_dict["url"]):
return file_dict
file_dict["url"] = f'{root_url}{file_dict["url"]}'
return file_dict
return client_utils.traverse(data, _add_root_url, client_utils.is_file_obj_with_url)

View File

@ -361,7 +361,7 @@ def test_add_root_url():
new_expected = {
"file": {
"path": "path",
"url": f"{root_url}/file=path",
"url": f"{new_root_url}/file=path",
},
"file2": {
"path": "path2",
@ -369,5 +369,5 @@ def test_add_root_url():
},
}
assert (
processing_utils.add_root_url(expected, root_url, new_root_url) == new_expected
processing_utils.add_root_url(expected, new_root_url, root_url) == new_expected
)