Commit
Β·
077ba3b
1
Parent(s):
03751e1
Fix: Static file serving for frontend assets
Browse files- Dockerfile +6 -1
- backend/app/main.py +12 -6
Dockerfile
CHANGED
|
@@ -27,11 +27,16 @@ COPY backend/app ./app
|
|
| 27 |
COPY backend/models ./models
|
| 28 |
|
| 29 |
# Create necessary directories
|
| 30 |
-
RUN mkdir -p ./uploads
|
| 31 |
|
| 32 |
# Copy built frontend from builder stage
|
|
|
|
| 33 |
COPY --from=frontend-builder /frontend/dist ./static
|
| 34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
# Expose port 7860 (required by Hugging Face Spaces)
|
| 36 |
EXPOSE 7860
|
| 37 |
|
|
|
|
| 27 |
COPY backend/models ./models
|
| 28 |
|
| 29 |
# Create necessary directories
|
| 30 |
+
RUN mkdir -p ./uploads
|
| 31 |
|
| 32 |
# Copy built frontend from builder stage
|
| 33 |
+
# Vite builds to 'dist' folder
|
| 34 |
COPY --from=frontend-builder /frontend/dist ./static
|
| 35 |
|
| 36 |
+
# Debug: List static directory contents
|
| 37 |
+
RUN echo "π Static directory contents:" && ls -la ./static/ && \
|
| 38 |
+
if [ -d "./static/assets" ]; then echo "β
Assets directory exists"; ls -la ./static/assets/; fi
|
| 39 |
+
|
| 40 |
# Expose port 7860 (required by Hugging Face Spaces)
|
| 41 |
EXPOSE 7860
|
| 42 |
|
backend/app/main.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
# backend/app/main.py (for Hugging Face Spaces)
|
| 2 |
from fastapi import FastAPI, File, UploadFile, HTTPException
|
| 3 |
from fastapi.middleware.cors import CORSMiddleware
|
| 4 |
-
from fastapi.responses import JSONResponse, HTMLResponse
|
| 5 |
from fastapi.staticfiles import StaticFiles
|
| 6 |
import os
|
| 7 |
import shutil
|
|
@@ -42,6 +42,11 @@ async def startup_event():
|
|
| 42 |
"""Initialize model on startup"""
|
| 43 |
global inference_engine
|
| 44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
if not MODEL_PATH.exists():
|
| 46 |
print(f"β οΈ Model file not found at {MODEL_PATH}")
|
| 47 |
print("Please place your model_Full.pth in the backend/models/ directory")
|
|
@@ -53,9 +58,9 @@ async def startup_event():
|
|
| 53 |
print(f"β Failed to initialize inference engine: {e}")
|
| 54 |
|
| 55 |
|
| 56 |
-
#
|
| 57 |
if STATIC_DIR.exists():
|
| 58 |
-
app.mount("/
|
| 59 |
|
| 60 |
|
| 61 |
@app.get("/", response_class=HTMLResponse)
|
|
@@ -64,7 +69,7 @@ async def root():
|
|
| 64 |
html_file = STATIC_DIR / "index.html"
|
| 65 |
|
| 66 |
if html_file.exists():
|
| 67 |
-
return
|
| 68 |
|
| 69 |
# Fallback API info if no frontend
|
| 70 |
return HTMLResponse(content="""
|
|
@@ -137,7 +142,7 @@ async def root():
|
|
| 137 |
<h2>π Usage</h2>
|
| 138 |
<p>Send a POST request to <code>/api/predict</code> with an MRI image file:</p>
|
| 139 |
<pre style="background: rgba(0,0,0,0.3); padding: 15px; border-radius: 8px; overflow-x: auto;">
|
| 140 |
-
curl -X POST "https://
|
| 141 |
-F "mriImage=@your_mri_image.jpg"
|
| 142 |
</pre>
|
| 143 |
</div>
|
|
@@ -228,7 +233,8 @@ async def health_check():
|
|
| 228 |
"status": "healthy",
|
| 229 |
"model_loaded": inference_engine is not None,
|
| 230 |
"model_path": str(MODEL_PATH),
|
| 231 |
-
"model_exists": MODEL_PATH.exists()
|
|
|
|
| 232 |
}
|
| 233 |
|
| 234 |
|
|
|
|
| 1 |
# backend/app/main.py (for Hugging Face Spaces)
|
| 2 |
from fastapi import FastAPI, File, UploadFile, HTTPException
|
| 3 |
from fastapi.middleware.cors import CORSMiddleware
|
| 4 |
+
from fastapi.responses import JSONResponse, HTMLResponse, FileResponse
|
| 5 |
from fastapi.staticfiles import StaticFiles
|
| 6 |
import os
|
| 7 |
import shutil
|
|
|
|
| 42 |
"""Initialize model on startup"""
|
| 43 |
global inference_engine
|
| 44 |
|
| 45 |
+
print(f"π Static directory: {STATIC_DIR}")
|
| 46 |
+
print(f"π Static exists: {STATIC_DIR.exists()}")
|
| 47 |
+
if STATIC_DIR.exists():
|
| 48 |
+
print(f"π Static contents: {list(STATIC_DIR.iterdir())}")
|
| 49 |
+
|
| 50 |
if not MODEL_PATH.exists():
|
| 51 |
print(f"β οΈ Model file not found at {MODEL_PATH}")
|
| 52 |
print("Please place your model_Full.pth in the backend/models/ directory")
|
|
|
|
| 58 |
print(f"β Failed to initialize inference engine: {e}")
|
| 59 |
|
| 60 |
|
| 61 |
+
# Mount static files for assets (CSS, JS, etc.)
|
| 62 |
if STATIC_DIR.exists():
|
| 63 |
+
app.mount("/assets", StaticFiles(directory=STATIC_DIR / "assets"), name="assets")
|
| 64 |
|
| 65 |
|
| 66 |
@app.get("/", response_class=HTMLResponse)
|
|
|
|
| 69 |
html_file = STATIC_DIR / "index.html"
|
| 70 |
|
| 71 |
if html_file.exists():
|
| 72 |
+
return FileResponse(html_file)
|
| 73 |
|
| 74 |
# Fallback API info if no frontend
|
| 75 |
return HTMLResponse(content="""
|
|
|
|
| 142 |
<h2>π Usage</h2>
|
| 143 |
<p>Send a POST request to <code>/api/predict</code> with an MRI image file:</p>
|
| 144 |
<pre style="background: rgba(0,0,0,0.3); padding: 15px; border-radius: 8px; overflow-x: auto;">
|
| 145 |
+
curl -X POST "https://arghadip2002-mri-app.hf.space/api/predict" \\
|
| 146 |
-F "mriImage=@your_mri_image.jpg"
|
| 147 |
</pre>
|
| 148 |
</div>
|
|
|
|
| 233 |
"status": "healthy",
|
| 234 |
"model_loaded": inference_engine is not None,
|
| 235 |
"model_path": str(MODEL_PATH),
|
| 236 |
+
"model_exists": MODEL_PATH.exists(),
|
| 237 |
+
"static_dir_exists": STATIC_DIR.exists()
|
| 238 |
}
|
| 239 |
|
| 240 |
|