nakas commited on
Commit
5b43964
·
verified ·
1 Parent(s): 989b57a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -27
app.py CHANGED
@@ -1,37 +1,22 @@
1
  import gradio as gr
 
2
  import threading
3
 
4
- # Hello World Gradio app as a string
5
- hello_world_code = """
6
- import gradio as gr
7
-
8
- def greet(name):
9
- return f"Hello, {name}!"
10
-
11
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
12
- iface.launch(server_name="0.0.0.0", server_port=7860)
13
- """
14
-
15
- # Function to execute the Gradio app dynamically
16
- def run_gradio_app():
17
- try:
18
- exec(hello_world_code, {"gr": gr})
19
- except Exception as e:
20
- print(f"Error executing generated code: {e}")
21
 
22
- # Function triggered on button click
23
- def launch_app():
24
- threading.Thread(target=run_gradio_app, daemon=True).start()
25
- return "Hello World Gradio app launched! Refresh to see it."
26
 
27
- # Gradio UI
28
  with gr.Blocks() as ui:
29
- gr.Markdown("### Basic Dynamic Gradio Loader")
30
- launch_button = gr.Button("Launch Hello World App")
31
- output_text = gr.Textbox(label="Status")
32
 
33
- launch_button.click(launch_app, outputs=output_text)
34
 
35
- # Start the initial UI
36
  if __name__ == "__main__":
37
  ui.launch(server_name="0.0.0.0", server_port=7860)
 
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)