Update run.py
Browse files
run.py
CHANGED
@@ -1,57 +1,36 @@
|
|
1 |
-
import importlib
|
2 |
import gradio as gr
|
3 |
-
import
|
4 |
-
import
|
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 |
-
all_demos = []
|
38 |
-
demo_module = None
|
39 |
-
for p in sorted(os.listdir("./demos")):
|
40 |
-
old_path = copy.deepcopy(sys.path)
|
41 |
-
sys.path = [os.path.join(demo_dir, p)] + sys.path
|
42 |
-
try: # Some demos may not be runnable because of 429 timeouts, etc.
|
43 |
-
if demo_module is None:
|
44 |
-
demo_module = importlib.import_module("run")
|
45 |
-
else:
|
46 |
-
demo_module = importlib.reload(demo_module)
|
47 |
-
all_demos.append((p, demo_module.demo, False))
|
48 |
-
except Exception as e:
|
49 |
-
with gr.Blocks() as demo:
|
50 |
-
gr.Markdown(f"Error loading demo: {e}")
|
51 |
-
all_demos.append((p, demo, True))
|
52 |
-
|
53 |
-
for demo_name, demo, _ in all_demos:
|
54 |
-
app = gr.mount_gradio_app(app, demo, f"/demo/{demo_name}")
|
55 |
|
56 |
if __name__ == "__main__":
|
57 |
-
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import random
|
3 |
+
import time
|
4 |
+
|
5 |
+
with gr.Blocks() as demo:
|
6 |
+
name = gr.Textbox(label="Name")
|
7 |
+
output = gr.Textbox(label="Output Box")
|
8 |
+
greet_btn = gr.Button("Greet")
|
9 |
+
@gr.on([greet_btn.click, name.submit], inputs=name, outputs=output)
|
10 |
+
def greet(name):
|
11 |
+
return "Hello " + name + "!"
|
12 |
+
|
13 |
+
with demo.route("Up") as incrementer_demo:
|
14 |
+
num = gr.Number()
|
15 |
+
incrementer_demo.load(lambda: time.sleep(1) or random.randint(10, 40), None, num)
|
16 |
+
|
17 |
+
with gr.Row():
|
18 |
+
inc_btn = gr.Button("Increase")
|
19 |
+
dec_btn = gr.Button("Decrease")
|
20 |
+
inc_btn.click(fn=lambda x: x + 1, inputs=num, outputs=num, api_name="increment")
|
21 |
+
dec_btn.click(fn=lambda x: x - 1, inputs=num, outputs=num, api_name="decrement")
|
22 |
+
for i in range(100):
|
23 |
+
gr.Textbox()
|
24 |
+
|
25 |
+
def wait(x):
|
26 |
+
time.sleep(2)
|
27 |
+
return x
|
28 |
+
|
29 |
+
identity_iface = gr.Interface(wait, "image", "image")
|
30 |
+
|
31 |
+
with demo.route("Interface") as incrementer_demo:
|
32 |
+
identity_iface.render()
|
33 |
+
gr.Interface(lambda x, y: x * y, ["number", "number"], "number")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
if __name__ == "__main__":
|
36 |
+
demo.launch(ssr_mode=True)
|