Carlo (7shoe) commited on
Commit
ab9ad9b
·
1 Parent(s): 0d9aaf8

Serve React dist via Gradio/FastAPI

Browse files
Files changed (2) hide show
  1. README.md +2 -2
  2. app.py +6 -7
README.md CHANGED
@@ -1,8 +1,8 @@
1
  ---
2
  title: Aurora Training Workflow Diagram
3
  sdk: gradio
4
- app_build_command: npm ci && npm run build
5
- app_file: dist/index.html
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
- # Gradio "dummy" (HF wants a Gradio app for sdk: gradio)
12
  demo = gr.Blocks()
13
  with demo:
14
- gr.Markdown("Loading… If you see this, open `/site/`.")
15
 
16
  app = FastAPI()
17
 
18
- # Serve the React build at /site
19
- if DIST.exists():
20
- app.mount("/site", StaticFiles(directory=str(DIST), html=True), name="site")
21
 
22
- # Optional: send / to your React app
23
  @app.get("/")
24
  def root():
25
  return RedirectResponse(url="/site/")
26
 
27
- # Mount Gradio somewhere (not strictly necessary for your UI, but keeps sdk happy)
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")