Repository: gradio-app/gradio

Issue:
Video fails when value is a URL.
### Describe the bug

I am using a Video component with the value set as a public video URL. But the pre-process function is throwing the below error:
```
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/gradio/routes.py", line 439, in run_predict
    output = await app.get_blocks().process_api(
  File "/usr/local/lib/python3.10/dist-packages/gradio/blocks.py", line 1382, in process_api
    inputs = self.preprocess_data(fn_index, inputs, state)
  File "/usr/local/lib/python3.10/dist-packages/gradio/blocks.py", line 1225, in preprocess_data
    processed_input.append(block.preprocess(inputs[i]))
  File "/usr/local/lib/python3.10/dist-packages/gradio/components/video.py", line 207, in preprocess
    file_name = Path(self.make_temp_copy_if_needed(file_name))
  File "/usr/local/lib/python3.10/dist-packages/gradio/components/base.py", line 220, in make_temp_copy_if_needed
    temp_dir = self.hash_file(file_path)
  File "/usr/local/lib/python3.10/dist-packages/gradio/components/base.py", line 184, in hash_file
    with open(file_path, "rb") as f:
FileNotFoundError: [Errno 2] No such file or directory: 'public-url'
```

### Have you searched existing issues?  🔎

- [X] I have searched and found no existing issues

### Reproduction

```
import gradio

url: str = "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"

with gradio.Blocks() as interface:
  video_in: gradio.Video = gradio.Video(value=url, autoplay=False)
  video_out: gradio.Video = gradio.Video()
  run: gradio.Button = gradio.Button()
  run.click(lambda x: x, video_in, video_out)

interface.launch(debug=True, share=True)
```

### Screenshot

_No response_

### Logs

```shell
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/gradio/routes.py", line 439, in run_predict
    output = await app.get_blocks().process_api(
  File "/usr/local/lib/python3.10/dist-packages/gradio/blocks.py", line 1382, in process_api
    inputs = self.preprocess_data(fn_index, inputs, state)
  File "/usr/local/lib/python3.10/dist-packages/gradio/blocks.py", line 1225, in preprocess_data
    processed_input.append(block.preprocess(inputs[i]))
  File "/usr/local/lib/python3.10/dist-packages/gradio/components/video.py", line 207, in preprocess
    file_name = Path(self.make_temp_copy_if_needed(file_name))
  File "/usr/local/lib/python3.10/dist-packages/gradio/components/base.py", line 220, in make_temp_copy_if_needed
    temp_dir = self.hash_file(file_path)
  File "/usr/local/lib/python3.10/dist-packages/gradio/components/base.py", line 184, in hash_file
    with open(file_path, "rb") as f:
FileNotFoundError: [Errno 2] No such file or directory: 'public-url'
```


### System Info

```shell
1. Gradio version: 3.36.1
2. Ubuntu: 22.04
```


### Severity

I can work around it


Discussion:
Thanks for filing @Sreerag-ibtl . We should pass through the URL in this case.

Resolving patch:
diff --git a/gradio/components/audio.py b/gradio/components/audio.py
--- a/gradio/components/audio.py
+++ b/gradio/components/audio.py
@@ -194,7 +194,7 @@ def preprocess(
         )
         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 @@ def postprocess(
         """
         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
diff --git a/gradio/components/video.py b/gradio/components/video.py
--- a/gradio/components/video.py
+++ b/gradio/components/video.py
@@ -204,7 +204,11 @@ def preprocess(
 
         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 @@ def _format_video(self, video: str | Path | None) -> FileData | None:
         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()


Test patch:
diff --git a/test/test_components.py b/test/test_components.py
--- a/test/test_components.py
+++ b/test/test_components.py
@@ -1499,6 +1499,19 @@ def test_video_preprocessing_flips_video_for_webcam(self, mock_ffmpeg):
         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):