Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,23 @@ In the example above, 16 requests could be processed in parallel (for a total in
time of 5 seconds), instead of each request being processed separately (for a total
inference time of 80 seconds).

### Load Event
### Upload Event

`Video`, `Audio`, `Image`, and `File` components now support a `upload` event that is triggered when a user uploads a file into any of these components.
`Video`, `Audio`, `Image`, and `File` components now support a `upload()` event that is triggered when a user uploads a file into any of these components.

Example usage:

```py
import gradio as gr

with gr.Blocks() as demo:
with gr.Row():
input_video = gr.Video()
output_video = gr.Video()

# Clears the output video when an input video is uploaded
input_video.upload(lambda : None, None, output_video)
```


## Bug Fixes:
Expand All @@ -77,6 +91,8 @@ No changes to highlight.
* Gradio now supports batched functions by [@abidlabs](https://github.com/abidlabs) in [PR 2218](https://github.com/gradio-app/gradio/pull/2218)
* Add `upload` event for `Video`, `Audio`, `Image`, and `File` components [@dawoodkhan82](https://github.com/dawoodkhan82) in [PR 2448](https://github.com/gradio-app/gradio/pull/2456)
* Changes websocket path for Spaces as it is no longer necessary to have a different URL for websocket connections on Spaces by [@abidlabs](https://github.com/abidlabs) in [PR 2528](https://github.com/gradio-app/gradio/pull/2528)
* Adds support for audio samples that are in `float64`, `float16`, or `uint16` formats by [@abidlabs](https://github.com/abidlabs) in [PR 2528](https://github.com/gradio-app/gradio/pull/2528)


## Contributors Shoutout:
No changes to highlight.
Expand Down
27 changes: 13 additions & 14 deletions gradio/processing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,32 +220,31 @@ def audio_to_file(sample_rate, data, filename):

def convert_to_16_bit_wav(data):
# Based on: https://docs.scipy.org/doc/scipy/reference/generated/scipy.io.wavfile.write.html
if data.dtype == np.float32:
warnings.warn(
"Audio data is not in 16-bit integer format."
"Trying to convert to 16-bit int format."
)
warning = "Trying to convert audio automatically from {} to 16-bit int format."
if data.dtype in [np.float64, np.float32, np.float16]:
warnings.warn(warning.format(data.dtype))
data = data / np.abs(data).max()
data = data * 32767
data = data.astype(np.int16)
elif data.dtype == np.int32:
warnings.warn(
"Audio data is not in 16-bit integer format."
"Trying to convert to 16-bit int format."
)
warnings.warn(warning.format(data.dtype))
data = data / 65538
data = data.astype(np.int16)
elif data.dtype == np.int16:
pass
elif data.dtype == np.uint16:
warnings.warn(warning.format(data.dtype))
data = data - 32768
data = data.astype(np.int16)
elif data.dtype == np.uint8:
warnings.warn(
"Audio data is not in 16-bit integer format."
"Trying to convert to 16-bit int format."
)
warnings.warn(warning.format(data.dtype))
data = data * 257 - 32768
data = data.astype(np.int16)
else:
raise ValueError("Audio data cannot be converted to " "16-bit int format.")
raise ValueError(
"Audio data cannot be converted automatically from "
f"{data.dtype} to 16-bit int format."
)
return data


Expand Down