nakas commited on
Commit
add86c7
·
verified ·
1 Parent(s): 6bc2781

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -9
app.py CHANGED
@@ -1,22 +1,24 @@
1
  import gradio as gr
 
 
2
  import subprocess
3
- import threading
4
 
5
- # Function to launch the new Gradio app
6
  def launch_new_gradio_app():
7
- # Use subprocess to run the new Gradio app (new_gradio_app.py)
8
- subprocess.Popen(["python", "new_gradio_app.py"])
9
 
10
- return "New Gradio app is now running. Check the space to see the result!"
 
11
 
12
- # Main Gradio UI with a button to start the new Gradio app
13
  with gr.Blocks() as ui:
14
  gr.Markdown("### Dynamic Gradio App Loader")
15
  launch_button = gr.Button("Launch New Gradio App")
16
- status = gr.Textbox(label="Status")
17
 
18
- launch_button.click(launch_new_gradio_app, outputs=status)
19
 
20
- # Launch the initial UI
21
  if __name__ == "__main__":
22
  ui.launch(server_name="0.0.0.0", server_port=7860)
 
1
  import gradio as gr
2
+ import os
3
+ import signal
4
  import subprocess
5
+ import sys
6
 
7
+ # Function to stop the current Gradio app and launch a new one
8
  def launch_new_gradio_app():
9
+ # Start the new Gradio app in the same process space
10
+ subprocess.Popen(["python", "new_gradio_app.py"], stdout=sys.stdout, stderr=sys.stderr)
11
 
12
+ # Gracefully exit the current Gradio app
13
+ os.kill(os.getpid(), signal.SIGTERM)
14
 
15
+ # Gradio UI with a button to switch apps
16
  with gr.Blocks() as ui:
17
  gr.Markdown("### Dynamic Gradio App Loader")
18
  launch_button = gr.Button("Launch New Gradio App")
 
19
 
20
+ launch_button.click(launch_new_gradio_app, outputs=[])
21
 
22
+ # Start the initial Gradio UI
23
  if __name__ == "__main__":
24
  ui.launch(server_name="0.0.0.0", server_port=7860)