import gradio as gr import os import signal import subprocess import sys # Function to stop the current Gradio app and launch a new one def launch_new_gradio_app(): # Start the new Gradio app in the same process space subprocess.Popen(["python", "new_gradio_app.py"], stdout=sys.stdout, stderr=sys.stderr) # Gracefully exit the current Gradio app os.kill(os.getpid(), signal.SIGTERM) # Gradio UI with a button to switch apps with gr.Blocks() as ui: gr.Markdown("### Dynamic Gradio App Loader") launch_button = gr.Button("Launch New Gradio App") launch_button.click(launch_new_gradio_app, outputs=[]) # Start the initial Gradio UI if __name__ == "__main__": ui.launch(server_name="0.0.0.0", server_port=7860)