Spaces:
Sleeping
Sleeping
Update backend/app.py
Browse files- backend/app.py +14 -7
backend/app.py
CHANGED
|
@@ -23,13 +23,13 @@ app.add_middleware(
|
|
| 23 |
)
|
| 24 |
|
| 25 |
# --- MODEL LOADING ---
|
| 26 |
-
|
| 27 |
-
MODEL_PATH = "
|
| 28 |
|
| 29 |
if not os.path.exists(MODEL_PATH):
|
| 30 |
-
print(f"❌ ERROR: Model folder not found at {
|
| 31 |
else:
|
| 32 |
-
print(f"✅ SUCCESS: Model folder found at {
|
| 33 |
|
| 34 |
# Use local_files_only=True to prevent internet lookup
|
| 35 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH, local_files_only=True)
|
|
@@ -79,12 +79,19 @@ def health():
|
|
| 79 |
return {"status": "ok"}
|
| 80 |
|
| 81 |
# --- SERVE FRONTEND ---
|
| 82 |
-
|
| 83 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
|
| 85 |
@app.get("/")
|
| 86 |
def serve_home():
|
| 87 |
-
return FileResponse("
|
| 88 |
|
| 89 |
if __name__ == "__main__":
|
|
|
|
| 90 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
|
| 23 |
)
|
| 24 |
|
| 25 |
# --- MODEL LOADING ---
|
| 26 |
+
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
| 27 |
+
MODEL_PATH = os.path.join(BASE_DIR, "privacy-detector-model")
|
| 28 |
|
| 29 |
if not os.path.exists(MODEL_PATH):
|
| 30 |
+
print(f"❌ ERROR: Model folder not found at {MODEL_PATH}")
|
| 31 |
else:
|
| 32 |
+
print(f"✅ SUCCESS: Model folder found at {MODEL_PATH}")
|
| 33 |
|
| 34 |
# Use local_files_only=True to prevent internet lookup
|
| 35 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH, local_files_only=True)
|
|
|
|
| 79 |
return {"status": "ok"}
|
| 80 |
|
| 81 |
# --- SERVE FRONTEND ---
|
| 82 |
+
# Assuming app.py is in /app/backend and HTML/CSS/JS are in /app/frontend
|
| 83 |
+
FRONTEND_PATH = os.path.join(BASE_DIR, "..", "frontend")
|
| 84 |
+
|
| 85 |
+
if os.path.exists(FRONTEND_PATH):
|
| 86 |
+
# Mount at root (/) so style.css and script.js are found at the top level
|
| 87 |
+
app.mount("/", StaticFiles(directory=FRONTEND_PATH, html=True), name="frontend")
|
| 88 |
+
else:
|
| 89 |
+
print(f"❌ ERROR: Frontend folder not found at {FRONTEND_PATH}")
|
| 90 |
|
| 91 |
@app.get("/")
|
| 92 |
def serve_home():
|
| 93 |
+
return FileResponse(os.path.join(FRONTEND_PATH, "index.html"))
|
| 94 |
|
| 95 |
if __name__ == "__main__":
|
| 96 |
+
# Hugging Face MUST use port 7860
|
| 97 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|