Fix bug related to preprocessing URLs for video (#4904)

* Support urls

* Add unit test

* CHANGELOG

* Bump client version

* use url_like
This commit is contained in:
Freddy Boulton 2023-07-12 21:46:54 -04:00 committed by GitHub
parent d3e1d272d5
commit 431140b903
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 6 deletions

View File

@ -7,6 +7,7 @@
* The `.change()` event is fixed in `Video` and `Image` so that it only fires once by [@abidlabs](https://github.com/abidlabs) in [PR 4793](https://github.com/gradio-app/gradio/pull/4793)
* The `.change()` event is fixed in `Audio` so that fires when the component value is programmatically updated by [@abidlabs](https://github.com/abidlabs) in [PR 4793](https://github.com/gradio-app/gradio/pull/4793)
- Fixed bug where `gr.Video` could not preprocess urls by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 4904](https://github.com/gradio-app/gradio/pull/4904)
## Other Changes:

View File

@ -194,7 +194,7 @@ class Audio(
)
crop_min, crop_max = x.get("crop_min", 0), x.get("crop_max", 100)
if is_file:
if utils.validate_url(file_name):
if client_utils.is_http_url_like(file_name):
temp_file_path = self.download_temp_copy_if_needed(file_name)
else:
temp_file_path = self.make_temp_copy_if_needed(file_name)
@ -322,7 +322,7 @@ class Audio(
"""
if y is None:
return None
if isinstance(y, str) and utils.validate_url(y):
if isinstance(y, str) and client_utils.is_http_url_like(y):
return {"name": y, "data": None, "is_file": True}
if isinstance(y, tuple):
sample_rate, data = y

View File

@ -204,7 +204,11 @@ class Video(
if is_file:
assert file_name is not None, "Received file data without a file name."
file_name = Path(self.make_temp_copy_if_needed(file_name))
if client_utils.is_http_url_like(file_name):
fn = self.download_temp_copy_if_needed
else:
fn = self.make_temp_copy_if_needed
file_name = Path(fn(file_name))
else:
assert file_data is not None, "Received empty file data."
file_name = Path(self.base64_to_temp_file_if_needed(file_data, file_name))
@ -312,12 +316,14 @@ class Video(
else:
conversion_needed = True
is_url = client_utils.is_http_url_like(video)
# For cases where the video is a URL and does not need to be converted to another format, we can just return the URL
if utils.validate_url(video) and not (conversion_needed):
if is_url and not (conversion_needed):
return {"name": video, "data": None, "is_file": True}
# For cases where the video needs to be converted to another format
if utils.validate_url(video):
if is_url:
video = self.download_temp_copy_if_needed(video)
if (
processing_utils.ffmpeg_installed()

View File

@ -3,7 +3,7 @@ aiohttp~=3.0
altair>=4.2.0,<6.0
fastapi
ffmpy
gradio_client>=0.2.7
gradio_client>=0.2.9
httpx
huggingface_hub>=0.14.0
Jinja2<4.0

View File

@ -1499,6 +1499,19 @@ class TestVideo:
assert ".avi" in list(output_params.keys())[0]
assert ".avi" in output_file
@pytest.mark.flaky
def test_preprocess_url(self):
output = gr.Video().preprocess(
{
"name": "https://gradio-builds.s3.amazonaws.com/demo-files/a.mp4",
"is_file": True,
"data": None,
"size": None,
"orig_name": "https://gradio-builds.s3.amazonaws.com/demo-files/a.mp4",
}
)
assert Path(output).name == "a.mp4" and not client_utils.probe_url(output)
class TestTimeseries:
def test_component_functions(self):