Spaces:
Build error
Build error
Delete app.py
Browse files
app.py
DELETED
@@ -1,51 +0,0 @@
|
|
1 |
-
import os
|
2 |
-
import sys
|
3 |
-
from fastapi import FastAPI, Request
|
4 |
-
from fastapi.middleware.cors import CORSMiddleware
|
5 |
-
from fastapi.staticfiles import StaticFiles
|
6 |
-
from fastapi.responses import FileResponse, HTMLResponse
|
7 |
-
import uvicorn
|
8 |
-
|
9 |
-
# Add server directory to path
|
10 |
-
sys.path.insert(0, 'server')
|
11 |
-
|
12 |
-
# Import the original app
|
13 |
-
from server.app import app as server_app
|
14 |
-
|
15 |
-
# Create the main app
|
16 |
-
app = FastAPI()
|
17 |
-
|
18 |
-
# Configure CORS
|
19 |
-
app.add_middleware(
|
20 |
-
CORSMiddleware,
|
21 |
-
allow_origins=["*"],
|
22 |
-
allow_credentials=True,
|
23 |
-
allow_methods=["*"],
|
24 |
-
allow_headers=["*"],
|
25 |
-
)
|
26 |
-
|
27 |
-
# Mount the original server app
|
28 |
-
app.mount("/api", server_app)
|
29 |
-
|
30 |
-
# Mount static directories
|
31 |
-
app.mount("/uploaded_images", StaticFiles(directory="server/uploaded_images"), name="uploaded_images")
|
32 |
-
app.mount("/static", StaticFiles(directory="server/static"), name="static")
|
33 |
-
app.mount("/assets", StaticFiles(directory="frontend/dist/assets"), name="assets")
|
34 |
-
|
35 |
-
# Serve frontend
|
36 |
-
@app.get("/{path:path}")
|
37 |
-
async def serve_frontend(path: str):
|
38 |
-
# First check if the path exists in the frontend dist
|
39 |
-
if os.path.exists(f"frontend/dist/{path}"):
|
40 |
-
return FileResponse(f"frontend/dist/{path}")
|
41 |
-
|
42 |
-
# Otherwise return the index.html
|
43 |
-
return FileResponse("frontend/dist/index.html")
|
44 |
-
|
45 |
-
@app.get("/", response_class=HTMLResponse)
|
46 |
-
async def root():
|
47 |
-
return FileResponse("frontend/dist/index.html")
|
48 |
-
|
49 |
-
if __name__ == "__main__":
|
50 |
-
# Use port 7860 for Hugging Face Spaces
|
51 |
-
uvicorn.run("app:app", host="0.0.0.0", port=7860)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|