Spaces:
Sleeping
Sleeping
Commit
•
db7af4f
1
Parent(s):
7db2ce9
Optional
Browse files
app.py
CHANGED
@@ -20,8 +20,29 @@ with block:
|
|
20 |
btn = gr.Button("Generate")
|
21 |
btn.click(dream, inputs=prompt, outputs=[gallery])
|
22 |
|
23 |
-
gradio_app = gr.routes.App.create_app(block)
|
24 |
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
app.mount("/img", StaticFiles(directory="images", html=True), name="images")
|
27 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
20 |
btn = gr.Button("Generate")
|
21 |
btn.click(dream, inputs=prompt, outputs=[gallery])
|
22 |
|
|
|
23 |
|
24 |
+
def mount_gradio_app(
|
25 |
+
app: FastAPI, blocks: gr.Blocks, path: str, gradio_api: str
|
26 |
+
) -> FastAPI:
|
27 |
+
"""Mount a gradio application (created with gr.routes.App.create_app(block)) to an existing FastAPI application.
|
28 |
+
|
29 |
+
Parameters:
|
30 |
+
app: The parent FastAPI application.
|
31 |
+
blocks: The blocks application we want to moung
|
32 |
+
path: The path at which the gradio application will be mounted.
|
33 |
+
"""
|
34 |
+
|
35 |
+
gradio_app = gr.routes.App.create_app(blocks)
|
36 |
+
|
37 |
+
@app.on_event("startup")
|
38 |
+
async def start_queue():
|
39 |
+
if gradio_app.blocks.enable_queue:
|
40 |
+
gradio_app.blocks._queue.set_url(gradio_api)
|
41 |
+
gradio_app.blocks.startup_events()
|
42 |
+
|
43 |
+
app.mount(path, gradio_app)
|
44 |
+
return app
|
45 |
+
|
46 |
+
app = mount_gradio_app(app, block, "/", gradio_api="http://localhost:7860/")
|
47 |
app.mount("/img", StaticFiles(directory="images", html=True), name="images")
|
48 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|