Spaces:
Paused
Paused
Fix: absolute path for FileResponse, skip pip if deps exist
Browse files
app.py
CHANGED
|
@@ -1,11 +1,18 @@
|
|
| 1 |
"""
|
| 2 |
-
Eye-Dentify FastAPI Backend — Hugging Face Spaces (Python SDK)
|
| 3 |
"""
|
| 4 |
-
import os, sys,
|
| 5 |
|
| 6 |
-
# Install deps on first run
|
| 7 |
def install_deps():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
print("📦 Installing dependencies...")
|
|
|
|
| 9 |
for dep in ["fastapi","uvicorn","python-multipart","pydantic","pydantic-settings",
|
| 10 |
"sqlalchemy","aiosqlite","yt-dlp","faiss-cpu","numpy","Pillow",
|
| 11 |
"opencv-python-headless","scikit-learn","httpx","aiofiles","loguru"]:
|
|
@@ -103,7 +110,11 @@ def video_to_dict(v):
|
|
| 103 |
# === Serve Frontend ===
|
| 104 |
@app.get("/")
|
| 105 |
async def serve_frontend():
|
| 106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
|
| 108 |
# === Schemas ===
|
| 109 |
class SubmitRequest(BaseModel):
|
|
|
|
| 1 |
"""
|
| 2 |
+
Eye-Dentify FastAPI Backend — Hugging Face Spaces (Python SDK / Docker)
|
| 3 |
"""
|
| 4 |
+
import os, sys, json, uuid, enum, datetime
|
| 5 |
|
| 6 |
+
# Install deps on first run (skip if already installed)
|
| 7 |
def install_deps():
|
| 8 |
+
try:
|
| 9 |
+
import fastapi, sqlalchemy, yt_dlp, faiss # Quick check
|
| 10 |
+
print("✅ Dependencies already installed")
|
| 11 |
+
return
|
| 12 |
+
except ImportError:
|
| 13 |
+
pass
|
| 14 |
print("📦 Installing dependencies...")
|
| 15 |
+
import subprocess
|
| 16 |
for dep in ["fastapi","uvicorn","python-multipart","pydantic","pydantic-settings",
|
| 17 |
"sqlalchemy","aiosqlite","yt-dlp","faiss-cpu","numpy","Pillow",
|
| 18 |
"opencv-python-headless","scikit-learn","httpx","aiofiles","loguru"]:
|
|
|
|
| 110 |
# === Serve Frontend ===
|
| 111 |
@app.get("/")
|
| 112 |
async def serve_frontend():
|
| 113 |
+
# Use absolute path to ensure it works in Docker
|
| 114 |
+
html_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "index.html")
|
| 115 |
+
if os.path.exists(html_path):
|
| 116 |
+
return FileResponse(html_path)
|
| 117 |
+
return {"error": "Frontend not found. Upload index.html to the Space."}
|
| 118 |
|
| 119 |
# === Schemas ===
|
| 120 |
class SubmitRequest(BaseModel):
|