File size: 1,029 Bytes
6e19f63
989b57a
cb42996
989b57a
 
cb42996
 
1f2f75f
 
 
989b57a
 
 
cb42996
989b57a
 
 
 
 
 
b867a1d
989b57a
 
 
 
cb42996
989b57a
 
 
 
 
70a718e
989b57a
e1c280b
989b57a
b54eb41
989b57a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import gradio as gr
import threading

# Hello World Gradio app as a string
hello_world_code = """
import gradio as gr

def greet(name):
    return f"Hello, {name}!"

iface = gr.Interface(fn=greet, inputs="text", outputs="text")
iface.launch(server_name="0.0.0.0", server_port=7860)
"""

# Function to execute the Gradio app dynamically
def run_gradio_app():
    try:
        exec(hello_world_code, {"gr": gr})
    except Exception as e:
        print(f"Error executing generated code: {e}")

# Function triggered on button click
def launch_app():
    threading.Thread(target=run_gradio_app, daemon=True).start()
    return "Hello World Gradio app launched! Refresh to see it."

# Gradio UI
with gr.Blocks() as ui:
    gr.Markdown("### Basic Dynamic Gradio Loader")
    launch_button = gr.Button("Launch Hello World App")
    output_text = gr.Textbox(label="Status")

    launch_button.click(launch_app, outputs=output_text)

# Start the initial UI
if __name__ == "__main__":
    ui.launch(server_name="0.0.0.0", server_port=7860)