Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,22 +1,24 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
import subprocess
|
3 |
-
import
|
4 |
|
5 |
-
# Function to
|
6 |
def launch_new_gradio_app():
|
7 |
-
#
|
8 |
-
subprocess.Popen(["python", "new_gradio_app.py"])
|
9 |
|
10 |
-
|
|
|
11 |
|
12 |
-
#
|
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=
|
19 |
|
20 |
-
#
|
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)
|