Spaces:
Running
on
T4
Running
on
T4
Update app.py
Browse files
app.py
CHANGED
|
@@ -346,49 +346,6 @@ async def face_swap_api(
|
|
| 346 |
except Exception as media_err:
|
| 347 |
logger.error(f"MEDIA_CLICK ERROR: {media_err}")
|
| 348 |
|
| 349 |
-
# if user_id:
|
| 350 |
-
# try:
|
| 351 |
-
# user_oid = ObjectId(user_id.strip())
|
| 352 |
-
# now = datetime.utcnow()
|
| 353 |
-
|
| 354 |
-
# update_result = await media_clicks_col.update_one(
|
| 355 |
-
# #{"userId": user_oid, "categories.categoryId": category_oid},
|
| 356 |
-
# {"userId": user_oid, "categories.subcategoryId": subcategory_oid},
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
# {
|
| 360 |
-
# "$set": {
|
| 361 |
-
# "updatedAt": now,
|
| 362 |
-
# "categories.$.lastClickedAt": now
|
| 363 |
-
# },
|
| 364 |
-
# "$inc": {"categories.$.click_count": 1}
|
| 365 |
-
# }
|
| 366 |
-
# )
|
| 367 |
-
|
| 368 |
-
# if update_result.matched_count == 0:
|
| 369 |
-
# # category does not exist → push new entry
|
| 370 |
-
# await media_clicks_col.update_one(
|
| 371 |
-
# {"userId": user_oid},
|
| 372 |
-
# {
|
| 373 |
-
# "$setOnInsert": {"createdAt": now},
|
| 374 |
-
# "$set": {"updatedAt": now},
|
| 375 |
-
# "$push": {
|
| 376 |
-
# "categories": {
|
| 377 |
-
# #"categoryId": category_oid,
|
| 378 |
-
# #categoryId": subcategory_oid,
|
| 379 |
-
# "subCategoryId": subcategory_oid,
|
| 380 |
-
# "click_count": 1,
|
| 381 |
-
# "lastClickedAt": now
|
| 382 |
-
# }
|
| 383 |
-
# }
|
| 384 |
-
# },
|
| 385 |
-
# upsert=True
|
| 386 |
-
# )
|
| 387 |
-
|
| 388 |
-
# except Exception as media_err:
|
| 389 |
-
# logger.error(f"MEDIA_CLICK ERROR: {media_err}")
|
| 390 |
-
# do NOT interrupt faceswap flow
|
| 391 |
-
|
| 392 |
# ------------------------------------------------------------------
|
| 393 |
# CASE 2 : target_category_id → DigitalOcean path (unchanged logic)
|
| 394 |
# ------------------------------------------------------------------
|
|
@@ -448,18 +405,43 @@ async def face_swap_api(
|
|
| 448 |
|
| 449 |
result_key = f"faceswap/result/{uuid.uuid4().hex}_enhanced.png"
|
| 450 |
result_url = upload_to_spaces(result_bytes, result_key)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 451 |
|
| 452 |
return {
|
| 453 |
"result_key": result_key,
|
| 454 |
"result_url": result_url
|
| 455 |
}
|
|
|
|
| 456 |
|
| 457 |
except Exception as e:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 458 |
raise HTTPException(500, f"Face swap failed: {str(e)}")
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
|
|
|
| 463 |
# @fastapi_app.post("/face-swap", dependencies=[Depends(verify_token)])
|
| 464 |
# async def face_swap_api(
|
| 465 |
# source: UploadFile = File(...),
|
|
|
|
| 346 |
except Exception as media_err:
|
| 347 |
logger.error(f"MEDIA_CLICK ERROR: {media_err}")
|
| 348 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 349 |
# ------------------------------------------------------------------
|
| 350 |
# CASE 2 : target_category_id → DigitalOcean path (unchanged logic)
|
| 351 |
# ------------------------------------------------------------------
|
|
|
|
| 405 |
|
| 406 |
result_key = f"faceswap/result/{uuid.uuid4().hex}_enhanced.png"
|
| 407 |
result_url = upload_to_spaces(result_bytes, result_key)
|
| 408 |
+
end_time = datetime.utcnow()
|
| 409 |
+
response_time_ms = (end_time - start_time).total_seconds() * 1000
|
| 410 |
+
|
| 411 |
+
if database is not None:
|
| 412 |
+
await database.api_logs.insert_one({
|
| 413 |
+
"endpoint": "/face-swap",
|
| 414 |
+
"status": "success",
|
| 415 |
+
"response_time_ms": response_time_ms,
|
| 416 |
+
"timestamp": end_time
|
| 417 |
+
})
|
| 418 |
+
|
| 419 |
|
| 420 |
return {
|
| 421 |
"result_key": result_key,
|
| 422 |
"result_url": result_url
|
| 423 |
}
|
| 424 |
+
|
| 425 |
|
| 426 |
except Exception as e:
|
| 427 |
+
end_time = datetime.utcnow()
|
| 428 |
+
response_time_ms = (end_time - start_time).total_seconds() * 1000
|
| 429 |
+
|
| 430 |
+
if database is not None:
|
| 431 |
+
await database.api_logs.insert_one({
|
| 432 |
+
"endpoint": "/face-swap",
|
| 433 |
+
"status": "fail",
|
| 434 |
+
"response_time_ms": response_time_ms,
|
| 435 |
+
"timestamp": end_time,
|
| 436 |
+
"error": str(e)
|
| 437 |
+
})
|
| 438 |
+
|
| 439 |
raise HTTPException(500, f"Face swap failed: {str(e)}")
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
+
|
| 445 |
# @fastapi_app.post("/face-swap", dependencies=[Depends(verify_token)])
|
| 446 |
# async def face_swap_api(
|
| 447 |
# source: UploadFile = File(...),
|