Spaces:
Sleeping
Sleeping
Update backend/app.py
Browse files- backend/app.py +6 -0
backend/app.py
CHANGED
|
@@ -231,6 +231,12 @@ async def predict(model_name: str = Form(...), file: UploadFile = File(...)):
|
|
| 231 |
else:
|
| 232 |
return JSONResponse(content={"error": "Invalid model name"}, status_code=400)
|
| 233 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 234 |
|
| 235 |
@app.get("/models")
|
| 236 |
def get_models():
|
|
|
|
| 231 |
else:
|
| 232 |
return JSONResponse(content={"error": "Invalid model name"}, status_code=400)
|
| 233 |
|
| 234 |
+
@app.on_event("startup")
|
| 235 |
+
async def cleanup_on_startup():
|
| 236 |
+
for d in ["/tmp/huggingface", "/tmp/Ultralytics", "/tmp/matplotlib", "/tmp/torch", "/root/.cache"]:
|
| 237 |
+
shutil.rmtree(d, ignore_errors=True)
|
| 238 |
+
print("✅ Cleaned caches on startup")
|
| 239 |
+
|
| 240 |
|
| 241 |
@app.get("/models")
|
| 242 |
def get_models():
|