Commit
·
a7bdd75
1
Parent(s):
3bfb118
fix: resolve MongoDB collection boolean check errors
Browse files- Fix NotImplementedError when checking collection objects with bool()
- Change 'if collection:' to 'if collection is not None:'
- Fixes upload endpoint 500 errors on Hugging Face Spaces
- All MongoDB operations now work correctly
server.py
CHANGED
|
@@ -138,7 +138,7 @@ async def upload_image(image: UploadFile = File(...)):
|
|
| 138 |
with open(path, "wb") as f:
|
| 139 |
f.write(contents)
|
| 140 |
# Save metadata to Mongo
|
| 141 |
-
if uploads_col:
|
| 142 |
try:
|
| 143 |
uploads_col.insert_one({"_id": image_id, "filename": os.path.basename(path), "path": path})
|
| 144 |
except Exception:
|
|
@@ -198,7 +198,7 @@ def get_hairswap(req: HairSwapRequest):
|
|
| 198 |
out_img.save(out_path)
|
| 199 |
LOGGER.info(f"Result saved: {out_path}")
|
| 200 |
|
| 201 |
-
if results_col:
|
| 202 |
try:
|
| 203 |
results_col.insert_one({
|
| 204 |
"_id": result_id,
|
|
@@ -236,7 +236,7 @@ def logs(limit: int = 50, level: str = None, logger_name: str = None):
|
|
| 236 |
response_data = {}
|
| 237 |
|
| 238 |
# Get metadata (uploads and results)
|
| 239 |
-
if uploads_col and results_col:
|
| 240 |
uploads = list(uploads_col.find({}, {"_id": 1, "filename": 1}).limit(20))
|
| 241 |
results = list(results_col.find({}, {"_id": 1, "filename": 1, "source_id": 1, "reference_id": 1}).limit(20))
|
| 242 |
response_data["metadata"] = {"uploads": uploads, "results": results}
|
|
|
|
| 138 |
with open(path, "wb") as f:
|
| 139 |
f.write(contents)
|
| 140 |
# Save metadata to Mongo
|
| 141 |
+
if uploads_col is not None:
|
| 142 |
try:
|
| 143 |
uploads_col.insert_one({"_id": image_id, "filename": os.path.basename(path), "path": path})
|
| 144 |
except Exception:
|
|
|
|
| 198 |
out_img.save(out_path)
|
| 199 |
LOGGER.info(f"Result saved: {out_path}")
|
| 200 |
|
| 201 |
+
if results_col is not None:
|
| 202 |
try:
|
| 203 |
results_col.insert_one({
|
| 204 |
"_id": result_id,
|
|
|
|
| 236 |
response_data = {}
|
| 237 |
|
| 238 |
# Get metadata (uploads and results)
|
| 239 |
+
if uploads_col is not None and results_col is not None:
|
| 240 |
uploads = list(uploads_col.find({}, {"_id": 1, "filename": 1}).limit(20))
|
| 241 |
results = list(results_col.find({}, {"_id": 1, "filename": 1, "source_id": 1, "reference_id": 1}).limit(20))
|
| 242 |
response_data["metadata"] = {"uploads": uploads, "results": results}
|