Spaces:
Sleeping
Sleeping
alessandro trinca tornidor
commited on
Commit
·
a09b191
1
Parent(s):
242e2b7
feat: move the gradio_app block within a function
Browse files
app.py
CHANGED
@@ -16,28 +16,32 @@ logging.info("routes included, creating gradio app")
|
|
16 |
|
17 |
|
18 |
CUSTOM_GRADIO_PATH = "/"
|
19 |
-
|
20 |
-
gr.
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
38 |
|
39 |
logging.info("mounting gradio app within FastAPI...")
|
40 |
-
|
|
|
41 |
logging.info("gradio app mounted")
|
42 |
|
43 |
|
|
|
16 |
|
17 |
|
18 |
CUSTOM_GRADIO_PATH = "/"
|
19 |
+
def get_gradio_app():
|
20 |
+
with gr.Blocks() as gradio_app:
|
21 |
+
gr.Markdown(
|
22 |
+
"""
|
23 |
+
# Hello World!
|
24 |
+
|
25 |
+
Start typing below to _see_ the *output*.
|
26 |
+
|
27 |
+
Here a [link](https://huggingface.co/spaces/aletrn/gradio_with_fastapi).
|
28 |
+
""")
|
29 |
+
btn = gr.Button(value="Divide et Impera")
|
30 |
+
btn.click(
|
31 |
+
formatters.request_formatter,
|
32 |
+
inputs=[
|
33 |
+
gr.Textbox(lines=1, placeholder="10", label="write an integer to divide 100; 0 will raise ZeroDivisionError")
|
34 |
+
],
|
35 |
+
outputs=[
|
36 |
+
gr.Textbox(lines=1, placeholder=None, label="Text Output")
|
37 |
+
]
|
38 |
+
)
|
39 |
+
return gradio_app
|
40 |
+
|
41 |
|
42 |
logging.info("mounting gradio app within FastAPI...")
|
43 |
+
gradio_app_md = get_gradio_app()
|
44 |
+
app = gr.mount_gradio_app(app, gradio_app_md, path=CUSTOM_GRADIO_PATH)
|
45 |
logging.info("gradio app mounted")
|
46 |
|
47 |
|