Moharek commited on
Commit ·
a00029a
1
Parent(s): c170ed5
Fix routing: Mount Gradio at /gradio, serve frontend at root
Browse files
app.py
CHANGED
|
@@ -8,7 +8,7 @@ from pathlib import Path
|
|
| 8 |
sys.path.insert(0, str(Path(__file__).parent))
|
| 9 |
|
| 10 |
import gradio as gr
|
| 11 |
-
from fastapi import FastAPI
|
| 12 |
from fastapi.staticfiles import StaticFiles
|
| 13 |
from fastapi.responses import FileResponse
|
| 14 |
|
|
@@ -18,24 +18,38 @@ from server.api import app as fastapi_app
|
|
| 18 |
# Frontend path
|
| 19 |
frontend_path = Path(__file__).parent / "frontend"
|
| 20 |
|
| 21 |
-
# Serve
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
return FileResponse(str(file_path))
|
| 37 |
-
|
| 38 |
-
return {"ok": False, "error": "not found"}
|
| 39 |
|
| 40 |
# Gradio interface
|
| 41 |
with gr.Blocks(title="Moharek GEO Platform") as demo:
|
|
@@ -82,8 +96,13 @@ with gr.Blocks(title="Moharek GEO Platform") as demo:
|
|
| 82 |
|
| 83 |
analyze_btn.click(analyze, [website_url, org_name, max_pages], [output_status, output_json])
|
| 84 |
|
| 85 |
-
# Mount Gradio to FastAPI
|
| 86 |
-
app = gr.mount_gradio_app(fastapi_app, demo, path="/")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
|
| 88 |
if __name__ == "__main__":
|
| 89 |
import uvicorn
|
|
|
|
| 8 |
sys.path.insert(0, str(Path(__file__).parent))
|
| 9 |
|
| 10 |
import gradio as gr
|
| 11 |
+
from fastapi import FastAPI, Request
|
| 12 |
from fastapi.staticfiles import StaticFiles
|
| 13 |
from fastapi.responses import FileResponse
|
| 14 |
|
|
|
|
| 18 |
# Frontend path
|
| 19 |
frontend_path = Path(__file__).parent / "frontend"
|
| 20 |
|
| 21 |
+
# Serve frontend files with higher priority
|
| 22 |
+
@fastapi_app.get("/portal.html")
|
| 23 |
+
@fastapi_app.get("/index.html")
|
| 24 |
+
@fastapi_app.get("/dashboard.html")
|
| 25 |
+
@fastapi_app.get("/jobs.html")
|
| 26 |
+
@fastapi_app.get("/content_v2.html")
|
| 27 |
+
@fastapi_app.get("/ads.html")
|
| 28 |
+
@fastapi_app.get("/tavily-search.html")
|
| 29 |
+
@fastapi_app.get("/competitor-intel.html")
|
| 30 |
+
@fastapi_app.get("/regional.html")
|
| 31 |
+
@fastapi_app.get("/geo-toolkit.html")
|
| 32 |
+
async def serve_html(request):
|
| 33 |
+
filename = request.url.path.lstrip('/')
|
| 34 |
+
file_path = frontend_path / filename
|
| 35 |
+
if file_path.exists():
|
| 36 |
+
return FileResponse(str(file_path))
|
| 37 |
+
return {"ok": False, "error": "not found"}
|
| 38 |
+
|
| 39 |
+
@fastapi_app.get("/assets/{filepath:path}")
|
| 40 |
+
async def serve_assets(filepath: str):
|
| 41 |
+
file_path = frontend_path / "assets" / filepath
|
| 42 |
+
if file_path.exists():
|
| 43 |
+
return FileResponse(str(file_path))
|
| 44 |
+
return {"ok": False, "error": "not found"}
|
| 45 |
+
|
| 46 |
+
@fastapi_app.get("/{filename}")
|
| 47 |
+
async def serve_static(filename: str):
|
| 48 |
+
if filename.endswith((".js", ".css", ".svg")):
|
| 49 |
+
file_path = frontend_path / filename
|
| 50 |
+
if file_path.exists():
|
| 51 |
return FileResponse(str(file_path))
|
| 52 |
+
return {"ok": False, "error": "not found"}
|
|
|
|
| 53 |
|
| 54 |
# Gradio interface
|
| 55 |
with gr.Blocks(title="Moharek GEO Platform") as demo:
|
|
|
|
| 96 |
|
| 97 |
analyze_btn.click(analyze, [website_url, org_name, max_pages], [output_status, output_json])
|
| 98 |
|
| 99 |
+
# Mount Gradio to FastAPI at /gradio
|
| 100 |
+
app = gr.mount_gradio_app(fastapi_app, demo, path="/gradio")
|
| 101 |
+
|
| 102 |
+
# Root redirect to Gradio
|
| 103 |
+
@fastapi_app.get("/")
|
| 104 |
+
async def root():
|
| 105 |
+
return FileResponse(str(frontend_path / "index.html"))
|
| 106 |
|
| 107 |
if __name__ == "__main__":
|
| 108 |
import uvicorn
|