Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
|
@@ -4,7 +4,7 @@ from fastapi.responses import FileResponse
|
|
| 4 |
from pydantic import BaseModel
|
| 5 |
from typing import List, Optional
|
| 6 |
import os
|
| 7 |
-
|
| 8 |
import traceback
|
| 9 |
|
| 10 |
app = FastAPI()
|
|
@@ -98,30 +98,3 @@ async def speak_endpoint(request: VoiceRequest):
|
|
| 98 |
return FileResponse(audio_path, media_type="audio/mpeg", filename="response.mp3")
|
| 99 |
except Exception as e:
|
| 100 |
raise HTTPException(status_code=500, detail=str(e))
|
| 101 |
-
|
| 102 |
-
from fastapi.staticfiles import StaticFiles
|
| 103 |
-
from fastapi.responses import FileResponse
|
| 104 |
-
|
| 105 |
-
# Mount static files if they exist (for production/served build)
|
| 106 |
-
frontend_dist = os.path.join(os.path.dirname(__file__), "../frontend/dist")
|
| 107 |
-
assets_path = os.path.join(frontend_dist, "assets")
|
| 108 |
-
|
| 109 |
-
if os.path.exists(assets_path):
|
| 110 |
-
app.mount("/assets", StaticFiles(directory=assets_path), name="assets")
|
| 111 |
-
|
| 112 |
-
@app.get("/{full_path:path}")
|
| 113 |
-
async def serve_frontend(full_path: str):
|
| 114 |
-
# Only serve if dist exists
|
| 115 |
-
if os.path.exists(frontend_dist):
|
| 116 |
-
# Serve index.html for any other path (SPA routing)
|
| 117 |
-
# Check if file exists in dist, else serve index.html
|
| 118 |
-
target_file = os.path.join(frontend_dist, full_path)
|
| 119 |
-
if full_path and os.path.exists(target_file):
|
| 120 |
-
return FileResponse(target_file)
|
| 121 |
-
return FileResponse(os.path.join(frontend_dist, "index.html"))
|
| 122 |
-
|
| 123 |
-
# If dist doesn't exist, just return a message or 404 for frontend routes
|
| 124 |
-
# This allows backend to run even if frontend isn't built
|
| 125 |
-
if full_path == "":
|
| 126 |
-
return {"message": "Backend is running. Frontend build not found. Use 'npm run dev' for frontend development."}
|
| 127 |
-
raise HTTPException(status_code=404, detail="Frontend build not found")
|
|
|
|
| 4 |
from pydantic import BaseModel
|
| 5 |
from typing import List, Optional
|
| 6 |
import os
|
| 7 |
+
import chat, voice, database
|
| 8 |
import traceback
|
| 9 |
|
| 10 |
app = FastAPI()
|
|
|
|
| 98 |
return FileResponse(audio_path, media_type="audio/mpeg", filename="response.mp3")
|
| 99 |
except Exception as e:
|
| 100 |
raise HTTPException(status_code=500, detail=str(e))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|