1

I am new to using Gradio. I am attempting to modify Google Colaboratory Notebook (i.e. a Jupyter Notebook) for my own purposes.

I would like to terminate Gradio from within a gradio.Column() that performs my function myfunc(), once the function has been executed.

How can I end Gradio (in this case, demo) gracefully from within the column? I have found references to gradio.Blocks.close() and gradio.Interface.close() but the sources I found are sparse on details on how to implement this in my example.

My structure is:

import gradio as gr
demo = gr.Blocks(title="title")
with demo:
    with gr.Tab("tab"):
        with gr.Row():
            with gr.Column():
                myfunc()
                # Quit Gradio here

# Continue code execution here
my_next_func()

Please note that the Notebook is supposed to continue execute code after closing Gradio. Therefore I don't believe I can use sys.exit() or something similar as I think it will stop all code execution in the Notebook cell.

P A N
  • 5,642
  • 15
  • 52
  • 103

1 Answers1

2

you can do this

import gradio as gr

def my_function(input):
    output = ...
    return output

iface = gr.Interface(fn=my_function, inputs="text", outputs="text")
def on_close():
iface.set_on_close(on_close)
iface.launch()
iface.close()

I believe this should work