github gradio-app/gradio v3.7

latest releases: @gradio/uploadbutton@0.6.13, @gradio/video@0.9.1, @gradio/upload@0.11.4...
20 months ago

Version 3.7

New Features:

Batched Functions

Gradio now supports the ability to pass batched functions. Batched functions are just
functions which take in a list of inputs and return a list of predictions.

For example, here is a batched function that takes in two lists of inputs (a list of
words and a list of ints), and returns a list of trimmed words as output:

import time

def trim_words(words, lens):
    trimmed_words = []
    time.sleep(5)
    for w, l in zip(words, lens):
        trimmed_words.append(w[:l])        
    return [trimmed_words]

The advantage of using batched functions is that if you enable queuing, the Gradio
server can automatically batch incoming requests and process them in parallel,
potentially speeding up your demo. Here's what the Gradio code looks like (notice
the batch=True and max_batch_size=16 -- both of these parameters can be passed
into event triggers or into the Interface class)

import gradio as gr

with gr.Blocks() as demo:
    with gr.Row():
        word = gr.Textbox(label="word", value="abc")
        leng = gr.Number(label="leng", precision=0, value=1)
        output = gr.Textbox(label="Output")
    with gr.Row():
        run = gr.Button()

    event = run.click(trim_words, [word, leng], output, batch=True, max_batch_size=16)

demo.queue()
demo.launch()

In the example above, 16 requests could be processed in parallel (for a total inference
time of 5 seconds), instead of each request being processed separately (for a total
inference time of 80 seconds).

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.

Example usage:

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:

  • Fixes issue where plotly animations, interactivity, titles, legends, were not working properly. @dawoodkhan82 in PR 2486
  • Prevent requests to the /api endpoint from skipping the queue if the queue is enabled for that event by @freddyaboulton in PR 2493
  • Fixes a bug with cancels in event triggers so that it works properly if multiple
    Blocks are rendered by @abidlabs in PR 2530
  • Prevent invalid targets of events from crashing the whole application. @pngwn in PR 2534
  • Properly dequeue cancelled events when multiple apps are rendered by @freddyaboulton in PR 2540

Documentation Changes:

  • Added an example interactive dashboard to the "Tabular & Plots" section of the Demos page by @freddyaboulton in PR 2508

Testing and Infrastructure Changes:

No changes to highlight.

Breaking Changes:

No changes to highlight.

Full Changelog:

  • Fixes the error message if a user builds Gradio locally and tries to use share=True by @abidlabs in PR 2502
  • Allows the render() function to return self by @Raul9595 in PR 2514
  • Fixes issue where plotly animations, interactivity, titles, legends, were not working properly. @dawoodkhan82 in PR 2486
  • Gradio now supports batched functions by @abidlabs in PR 2218
  • Add upload event for Video, Audio, Image, and File components @dawoodkhan82 in PR 2448
  • Changes websocket path for Spaces as it is no longer necessary to have a different URL for websocket connections on Spaces by @abidlabs in PR 2528
  • Clearer error message when events are defined outside of a Blocks scope, and a warning if you
    try to use Series or Parallel with Blocks by @abidlabs in PR 2543
  • Adds support for audio samples that are in float64, float16, or uint16 formats by @abidlabs in PR 2545

Contributors Shoutout:

No changes to highlight.

Don't miss a new gradio release

NewReleases is sending notifications on new releases.