Skip to content

Commit

Permalink
Support presigned URLs with gr.Video, gr.Model3D, and other components (
Browse files Browse the repository at this point in the history
#10406)

* thanks cursor

* add changeset

* add changeset

* add changeset

* changes

* changes

* video

* changes

---------

Co-authored-by: gradio-pr-bot <[email protected]>
  • Loading branch information
abidlabs and gradio-pr-bot authored Jan 23, 2025
1 parent 7377055 commit b7a7e59
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/lemon-hotels-retire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"gradio": patch
---

fix:Support presigned URLs with gr.Video, gr.Model3D, and other components
11 changes: 7 additions & 4 deletions gradio/processing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,15 +328,18 @@ def wrapper(*args: Any, **kwargs: Any) -> Awaitable[T]:
async def async_ssrf_protected_download(url: str, cache_dir: str) -> str:
temp_dir = Path(cache_dir) / hash_url(url)
temp_dir.mkdir(exist_ok=True, parents=True)
filename = client_utils.strip_invalid_filename_characters(Path(url).name)
full_temp_file_path = str(abspath(temp_dir / filename))

parsed_url = urlparse(url)
base_path = parsed_url.path.rstrip("/")
filename = (
client_utils.strip_invalid_filename_characters(Path(base_path).name) or "file"
)

full_temp_file_path = str(abspath(temp_dir / filename))
if Path(full_temp_file_path).exists():
return full_temp_file_path

parsed_url = urlparse(url)
hostname = parsed_url.hostname

response = await sh.get(
url, domain_whitelist=PUBLIC_HOSTNAME_WHITELIST, _transport=async_transport
)
Expand Down
11 changes: 11 additions & 0 deletions test/components/test_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,21 @@ async def test_component_functions(self):
output_with_subtitles = output_with_subtitles.model_dump()
assert output_with_subtitles["subtitles"]["path"].endswith(".vtt")

video = gr.Video(format="wav")
video_url_with_query_param = "https://github.com/gradio-app/gradio/raw/refs/heads/main/test/test_files/playable_but_bad_container.mp4?query=fake"
postprocessed_video_with_query_param = video.postprocess(
video_url_with_query_param
)
assert postprocessed_video_with_query_param
assert postprocessed_video_with_query_param.model_dump()["video"][
"path"
].endswith("playable_but_bad_container.wav")

p_video = gr.Video()
video_with_subtitle = gr.Video()
postprocessed_video = p_video.postprocess(Path(y_vid_path))
assert postprocessed_video

postprocessed_video = postprocessed_video.model_dump()
postprocessed_video_with_subtitle = video_with_subtitle.postprocess(
(Path(y_vid_path), Path(subtitles_path))
Expand Down

0 comments on commit b7a7e59

Please sign in to comment.