alessandro trinca tornidor commited on
Commit
a09b191
·
1 Parent(s): 242e2b7

feat: move the gradio_app block within a function

Browse files
Files changed (1) hide show
  1. app.py +24 -20
app.py CHANGED
@@ -16,28 +16,32 @@ logging.info("routes included, creating gradio app")
16
 
17
 
18
  CUSTOM_GRADIO_PATH = "/"
19
- with gr.Blocks() as gradio_app:
20
- gr.Markdown(
21
- """
22
- # Hello World!
23
-
24
- Start typing below to _see_ the *output*.
25
-
26
- Here a [link](https://huggingface.co/spaces/aletrn/gradio_with_fastapi).
27
- """)
28
- btn = gr.Button(value="Divide et Impera")
29
- btn.click(
30
- formatters.request_formatter,
31
- inputs=[
32
- gr.Textbox(lines=1, placeholder="10", label="write an integer to divide 100; 0 will raise ZeroDivisionError")
33
- ],
34
- outputs=[
35
- gr.Textbox(lines=1, placeholder=None, label="Text Output")
36
- ]
37
- )
 
 
 
38
 
39
  logging.info("mounting gradio app within FastAPI...")
40
- app = gr.mount_gradio_app(app, gradio_app, path=CUSTOM_GRADIO_PATH)
 
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