Spaces:
Build error
Build error
| import os | |
| import sys | |
| from fastapi import FastAPI, Request | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from fastapi.staticfiles import StaticFiles | |
| from fastapi.responses import FileResponse, HTMLResponse | |
| import uvicorn | |
| # Add server directory to path | |
| sys.path.insert(0, 'server') | |
| # Import the original app | |
| from server.app import app as server_app | |
| # Create the main app | |
| app = FastAPI() | |
| # Configure CORS | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=["*"], | |
| allow_credentials=True, | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| # Mount the original server app | |
| app.mount("/api", server_app) | |
| # Mount static directories | |
| app.mount("/uploaded_images", StaticFiles(directory="server/uploaded_images"), name="uploaded_images") | |
| app.mount("/static", StaticFiles(directory="server/static"), name="static") | |
| app.mount("/assets", StaticFiles(directory="frontend/dist/assets"), name="assets") | |
| # Serve frontend | |
| async def serve_frontend(path: str): | |
| # First check if the path exists in the frontend dist | |
| if os.path.exists(f"frontend/dist/{path}"): | |
| return FileResponse(f"frontend/dist/{path}") | |
| # Otherwise return the index.html | |
| return FileResponse("frontend/dist/index.html") | |
| async def root(): | |
| return FileResponse("frontend/dist/index.html") | |
| if __name__ == "__main__": | |
| # Use port 7860 for Hugging Face Spaces | |
| uvicorn.run("app:app", host="0.0.0.0", port=7860) | |