Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -9,7 +9,6 @@ from fastapi import FastAPI, Request, Response
|
|
9 |
from fastapi.staticfiles import StaticFiles
|
10 |
import uvicorn
|
11 |
import httpx
|
12 |
-
from fastapi.middleware.base import BaseHTTPMiddleware
|
13 |
|
14 |
import spaces
|
15 |
from spaces.zero.client import _get_token
|
@@ -24,20 +23,21 @@ os.environ["GRADIO_ROOT_PATH"] = "/"
|
|
24 |
# Create FastAPI app
|
25 |
app = FastAPI()
|
26 |
|
27 |
-
#
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
|
|
|
|
|
|
37 |
|
38 |
-
|
39 |
-
|
40 |
-
# Create and configure static directory
|
41 |
static_dir = Path("./static")
|
42 |
static_dir.mkdir(parents=True, exist_ok=True)
|
43 |
app.mount("/static", StaticFiles(directory="static"), name="static")
|
@@ -64,7 +64,7 @@ with gr.Blocks() as demo:
|
|
64 |
output = gr.Textbox(label="Output")
|
65 |
submit_btn.click(fn=process_and_save, inputs=[text_input], outputs=output)
|
66 |
|
67 |
-
# Mount the Gradio app with SSR mode, using node_port 7861
|
68 |
app = gr.mount_gradio_app(app, demo, path="/", ssr_mode=True, node_port=7861)
|
69 |
|
70 |
if __name__ == "__main__":
|
|
|
9 |
from fastapi.staticfiles import StaticFiles
|
10 |
import uvicorn
|
11 |
import httpx
|
|
|
12 |
|
13 |
import spaces
|
14 |
from spaces.zero.client import _get_token
|
|
|
23 |
# Create FastAPI app
|
24 |
app = FastAPI()
|
25 |
|
26 |
+
# Add middleware using the decorator
|
27 |
+
@app.middleware("http")
|
28 |
+
async def ssr_path_rewrite(request: Request, call_next):
|
29 |
+
path = request.scope.get("path", "")
|
30 |
+
if path.startswith("/7861"):
|
31 |
+
remainder = path[len("/7861"):]
|
32 |
+
if not remainder.startswith("/"):
|
33 |
+
remainder = "/" + remainder
|
34 |
+
new_path = "/_app" + remainder
|
35 |
+
request.scope["path"] = new_path
|
36 |
+
print(f"Rewrote path from {path} to {new_path}")
|
37 |
+
response = await call_next(request)
|
38 |
+
return response
|
39 |
|
40 |
+
# Set up static files (if needed)
|
|
|
|
|
41 |
static_dir = Path("./static")
|
42 |
static_dir.mkdir(parents=True, exist_ok=True)
|
43 |
app.mount("/static", StaticFiles(directory="static"), name="static")
|
|
|
64 |
output = gr.Textbox(label="Output")
|
65 |
submit_btn.click(fn=process_and_save, inputs=[text_input], outputs=output)
|
66 |
|
67 |
+
# Mount the Gradio app with SSR mode, using node_port 7861
|
68 |
app = gr.mount_gradio_app(app, demo, path="/", ssr_mode=True, node_port=7861)
|
69 |
|
70 |
if __name__ == "__main__":
|