Spaces:
Sleeping
Sleeping
Carlo (7shoe) commited on
Commit ·
ab9ad9b
1
Parent(s): 0d9aaf8
Serve React dist via Gradio/FastAPI
Browse files
README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
---
|
| 2 |
title: Aurora Training Workflow Diagram
|
| 3 |
sdk: gradio
|
| 4 |
-
|
| 5 |
-
|
| 6 |
---
|
| 7 |
|
| 8 |
# React + Vite
|
|
|
|
| 1 |
---
|
| 2 |
title: Aurora Training Workflow Diagram
|
| 3 |
sdk: gradio
|
| 4 |
+
app_file: app.py
|
| 5 |
+
pinned: false
|
| 6 |
---
|
| 7 |
|
| 8 |
# React + Vite
|
app.py
CHANGED
|
@@ -8,21 +8,20 @@ import gradio as gr
|
|
| 8 |
ROOT = Path(__file__).resolve().parent
|
| 9 |
DIST = ROOT / "dist"
|
| 10 |
|
| 11 |
-
#
|
| 12 |
demo = gr.Blocks()
|
| 13 |
with demo:
|
| 14 |
-
gr.Markdown("
|
| 15 |
|
| 16 |
app = FastAPI()
|
| 17 |
|
| 18 |
-
#
|
| 19 |
-
|
| 20 |
-
app.mount("/site", StaticFiles(directory=str(DIST), html=True), name="site")
|
| 21 |
|
| 22 |
-
#
|
| 23 |
@app.get("/")
|
| 24 |
def root():
|
| 25 |
return RedirectResponse(url="/site/")
|
| 26 |
|
| 27 |
-
#
|
| 28 |
app = gr.mount_gradio_app(app, demo, path="/gradio")
|
|
|
|
| 8 |
ROOT = Path(__file__).resolve().parent
|
| 9 |
DIST = ROOT / "dist"
|
| 10 |
|
| 11 |
+
# minimal gradio app (HF wants sdk: gradio to have a gradio app)
|
| 12 |
demo = gr.Blocks()
|
| 13 |
with demo:
|
| 14 |
+
gr.Markdown("React site is served at **/site/**")
|
| 15 |
|
| 16 |
app = FastAPI()
|
| 17 |
|
| 18 |
+
# serve the React build
|
| 19 |
+
app.mount("/site", StaticFiles(directory=str(DIST), html=True), name="site")
|
|
|
|
| 20 |
|
| 21 |
+
# make the Space root show the site
|
| 22 |
@app.get("/")
|
| 23 |
def root():
|
| 24 |
return RedirectResponse(url="/site/")
|
| 25 |
|
| 26 |
+
# keep gradio mounted (optional but nice)
|
| 27 |
app = gr.mount_gradio_app(app, demo, path="/gradio")
|