Spaces:
Running
on
T4
Running
on
T4
Update app.py
Browse files
app.py
CHANGED
|
@@ -457,6 +457,29 @@ async def face_swap_api(
|
|
| 457 |
}
|
| 458 |
}
|
| 459 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 460 |
|
| 461 |
logger.info(
|
| 462 |
"[MEDIA_CLICK] user=%s subCategory=%s ai_edit_complete++ daily_tracked",
|
|
@@ -602,7 +625,6 @@ fastapi_app = mount_gradio_app(fastapi_app, demo, path="/gradio")
|
|
| 602 |
if __name__ == "__main__":
|
| 603 |
uvicorn.run(fastapi_app, host="0.0.0.0", port=7860)
|
| 604 |
|
| 605 |
-
|
| 606 |
# # --------------------- List Images Endpoint ---------------------
|
| 607 |
# import os
|
| 608 |
# os.environ["OMP_NUM_THREADS"] = "1"
|
|
|
|
| 457 |
}
|
| 458 |
}
|
| 459 |
)
|
| 460 |
+
|
| 461 |
+
# -------------------------------------------------
|
| 462 |
+
# STEP 5: Sort subCategories by lastClickedAt (ascending - oldest first)
|
| 463 |
+
# -------------------------------------------------
|
| 464 |
+
user_doc = await media_clicks_col.find_one({"userId": user_oid})
|
| 465 |
+
if user_doc and "subCategories" in user_doc:
|
| 466 |
+
subcategories = user_doc["subCategories"]
|
| 467 |
+
# Sort by lastClickedAt in ascending order (oldest first)
|
| 468 |
+
# Handle missing or None dates by using datetime.min
|
| 469 |
+
subcategories_sorted = sorted(
|
| 470 |
+
subcategories,
|
| 471 |
+
key=lambda x: x.get("lastClickedAt") if x.get("lastClickedAt") is not None else datetime.min
|
| 472 |
+
)
|
| 473 |
+
# Update with sorted array
|
| 474 |
+
await media_clicks_col.update_one(
|
| 475 |
+
{"userId": user_oid},
|
| 476 |
+
{
|
| 477 |
+
"$set": {
|
| 478 |
+
"subCategories": subcategories_sorted,
|
| 479 |
+
"updatedAt": now
|
| 480 |
+
}
|
| 481 |
+
}
|
| 482 |
+
)
|
| 483 |
|
| 484 |
logger.info(
|
| 485 |
"[MEDIA_CLICK] user=%s subCategory=%s ai_edit_complete++ daily_tracked",
|
|
|
|
| 625 |
if __name__ == "__main__":
|
| 626 |
uvicorn.run(fastapi_app, host="0.0.0.0", port=7860)
|
| 627 |
|
|
|
|
| 628 |
# # --------------------- List Images Endpoint ---------------------
|
| 629 |
# import os
|
| 630 |
# os.environ["OMP_NUM_THREADS"] = "1"
|