Skip to content

Commit

Permalink
Fixes method to resolve the root URLs (#7565)
Browse files Browse the repository at this point in the history
* fix

* fix

* add changeset

* fix test

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
  • Loading branch information
abidlabs and gradio-pr-bot committed Mar 4, 2024
1 parent 3940490 commit 1c22123
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/deep-teeth-sleep.md
@@ -0,0 +1,5 @@
---
"gradio": patch
---

fix:Fixes method to resolve the `root` URLs
9 changes: 5 additions & 4 deletions gradio/processing_utils.py
Expand Up @@ -299,10 +299,11 @@ def _move_to_cache(d: dict):

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)
Expand Down
4 changes: 2 additions & 2 deletions test/test_processing_utils.py
Expand Up @@ -361,13 +361,13 @@ 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",
"url": "https://www.gradio.app",
},
}
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
)

0 comments on commit 1c22123

Please sign in to comment.