diff --git a/demo/blocks_scroll/run.py b/demo/blocks_scroll/run.py new file mode 100644 index 0000000000..2b2194dfb8 --- /dev/null +++ b/demo/blocks_scroll/run.py @@ -0,0 +1,24 @@ +import gradio as gr + + +demo = gr.Blocks() + +with demo: + inp = gr.Textbox(placeholder="Enter text.") + scroll_btn = gr.Button("Scroll") + no_scroll_btn = gr.Button("No Scroll") + big_block = gr.HTML(""" +
+ """) + out = gr.Textbox() + + scroll_btn.click(lambda x: x, + inputs=inp, + outputs=out, + scroll_to_output=True) + no_scroll_btn.click(lambda x: x, + inputs=inp, + outputs=out) + +if __name__ == "__main__": + demo.launch() \ No newline at end of file diff --git a/gradio/blocks.py b/gradio/blocks.py index 2318ef7ebc..41cebbf00f 100644 --- a/gradio/blocks.py +++ b/gradio/blocks.py @@ -85,6 +85,8 @@ class Block: outputs: Optional[Component | List[Component]], preprocess: bool = True, postprocess: bool = True, + scroll_to_output: bool = False, + show_progress: bool = True, api_name: Optional[AnyStr] = None, js: Optional[str] = False, no_target: bool = False, @@ -100,6 +102,8 @@ class Block: outputs: output list preprocess: whether to run the preprocess methods of components postprocess: whether to run the postprocess methods of components + scroll_to_output: whether to scroll to output of dependency on trigger + show_progress: whether to show progress animation while running. api_name: Defining this parameter exposes the endpoint in the api docs js: Optional frontend js method to run before running 'fn'. Input arguments for js method are values of 'inputs' and 'outputs', return should be a list of values for output components no_target: if True, sets "targets" to [], used for Blocks "load" event @@ -129,6 +133,8 @@ class Block: else None, "queue": queue, "api_name": api_name, + "scroll_to_output": scroll_to_output, + "show_progress": show_progress, } if api_name is not None: dependency["documentation"] = [ diff --git a/gradio/events.py b/gradio/events.py index a9199ca738..456d3df12f 100644 --- a/gradio/events.py +++ b/gradio/events.py @@ -14,8 +14,10 @@ class Changeable(Block): fn: Callable, inputs: List[Component], outputs: List[Component], - status_tracker: Optional[StatusTracker] = None, api_name: AnyStr = None, + status_tracker: Optional[StatusTracker] = None, + scroll_to_output: bool = False, + show_progress: bool = True, queue: Optional[bool] = None, _js: Optional[str] = None, _preprocess: bool = True, @@ -26,12 +28,14 @@ class Changeable(Block): or uploads an image) Parameters: - fn (Callable): Callable function - inputs (List[Component]): List of inputs - outputs (List[Component]): List of outputs - status_tracker (StatusTracker): StatusTracker to visualize function progress - api_name (str): Defining this parameter exposes the endpoint in the api docs - _js (str): Optional frontend js method to run before running 'fn'. Input arguments for js method are values of input and outputs components, return should be a list of values for output component. + fn: Callable function + inputs: List of inputs + outputs: List of outputs + api_name: Defining this parameter exposes the endpoint in the api docs + status_tracker: StatusTracker to visualize function progress + scroll_to_output: If True, will scroll to output component on completion + show_progress: If True, will show progress animation while pending + _js: Optional frontend js method to run before running 'fn'. Input arguments for js method are values of input and outputs components, return should be a list of values for output component. Returns: None """ self.set_event_trigger( @@ -39,8 +43,10 @@ class Changeable(Block): fn, inputs, outputs, - status_tracker=status_tracker, api_name=api_name, + status_tracker=status_tracker, + scroll_to_output=scroll_to_output, + show_progress=show_progress, js=_js, preprocess=_preprocess, postprocess=_postprocess, @@ -54,8 +60,10 @@ class Clickable(Block): fn: Callable, inputs: List[Component], outputs: List[Component], - status_tracker: Optional[StatusTracker] = None, api_name: AnyStr = None, + status_tracker: Optional[StatusTracker] = None, + scroll_to_output: bool = False, + show_progress: bool = True, queue=None, _js: Optional[str] = None, _preprocess: bool = True, @@ -68,8 +76,10 @@ class Clickable(Block): fn: Callable function inputs: List of inputs outputs: List of outputs - status_tracker: StatusTracker to visualize function progress api_name: Defining this parameter exposes the endpoint in the api docs + status_tracker: StatusTracker to visualize function progress + scroll_to_output: If True, will scroll to output component on completion + show_progress: If True, will show progress animation while pending _js: Optional frontend js method to run before running 'fn'. Input arguments for js method are values of 'inputs' and 'outputs', return should be a list of values for output components. _preprocess: If False, will not run preprocessing of component data before running 'fn'. _postprocess: If False, will not run postprocessing of component data before returning 'fn' output. @@ -80,8 +90,10 @@ class Clickable(Block): fn, inputs, outputs, - status_tracker=status_tracker, api_name=api_name, + status_tracker=status_tracker, + scroll_to_output=scroll_to_output, + show_progress=show_progress, queue=queue, js=_js, preprocess=_preprocess, @@ -95,8 +107,10 @@ class Submittable(Block): fn: Callable, inputs: List[Component], outputs: List[Component], - status_tracker: Optional[StatusTracker] = None, api_name: AnyStr = None, + status_tracker: Optional[StatusTracker] = None, + scroll_to_output: bool = False, + show_progress: bool = True, queue: Optional[bool] = None, _js: Optional[str] = None, _preprocess: bool = True, @@ -109,8 +123,10 @@ class Submittable(Block): fn: Callable function inputs: List of inputs outputs: List of outputs - status_tracker: StatusTracker to visualize function progress api_name: Defining this parameter exposes the endpoint in the api docs + status_tracker: StatusTracker to visualize function progress + scroll_to_output: If True, will scroll to output component on completion + show_progress: If True, will show progress animation while pending _js: Optional frontend js method to run before running 'fn'. Input arguments for js method are values of 'inputs' and 'outputs', return should be a list of values for output components. Returns: None """ @@ -121,6 +137,8 @@ class Submittable(Block): outputs, status_tracker=status_tracker, api_name=api_name, + scroll_to_output=scroll_to_output, + show_progress=show_progress, js=_js, preprocess=_preprocess, postprocess=_postprocess, @@ -313,6 +331,7 @@ class Streamable(Block): inputs: List[Component], outputs: List[Component], api_name: AnyStr = None, + show_progress: bool = False, queue: Optional[bool] = None, _js: Optional[str] = None, _preprocess: bool = True, @@ -341,4 +360,5 @@ class Streamable(Block): preprocess=_preprocess, postprocess=_postprocess, queue=queue, + show_progress=False, ) diff --git a/gradio/interface.py b/gradio/interface.py index 623ba1c85c..b709309757 100644 --- a/gradio/interface.py +++ b/gradio/interface.py @@ -545,6 +545,7 @@ class Interface(Blocks): self.input_components, self.output_components, api_name="predict", + scroll_to_output=True, status_tracker=status_tracker, ) clear_btn.click( diff --git a/ui/packages/app/src/Blocks.svelte b/ui/packages/app/src/Blocks.svelte index 85964e97ec..9c94f57546 100644 --- a/ui/packages/app/src/Blocks.svelte +++ b/ui/packages/app/src/Blocks.svelte @@ -3,7 +3,7 @@ import { onMount } from "svelte"; import { component_map } from "./components/directory"; import { loading_status } from "./stores"; - import type { LoadingStatus } from "./stores"; + import type { LoadingStatus } from "./components/StatusTracker/types"; import { _ } from "svelte-i18n"; import { setupi18n } from "./i18n"; @@ -42,6 +42,8 @@ outputs: Array