Spaces:
Running
on
T4
Running
on
T4
Update app.py
Browse files
app.py
CHANGED
|
@@ -1719,6 +1719,7 @@
|
|
| 1719 |
# uvicorn.run(fastapi_app, host="0.0.0.0", port=7860)
|
| 1720 |
|
| 1721 |
|
|
|
|
| 1722 |
# --------------------- List Images Endpoint ---------------------
|
| 1723 |
import os
|
| 1724 |
os.environ["OMP_NUM_THREADS"] = "1"
|
|
@@ -1913,13 +1914,13 @@ async def startup_db():
|
|
| 1913 |
@fastapi_app.on_event("shutdown")
|
| 1914 |
async def shutdown_db():
|
| 1915 |
global client, admin_client, collage_maker_client
|
| 1916 |
-
if client:
|
| 1917 |
client.close()
|
| 1918 |
logger.info("MongoDB connection closed")
|
| 1919 |
-
if admin_client:
|
| 1920 |
admin_client.close()
|
| 1921 |
logger.info("Admin MongoDB connection closed")
|
| 1922 |
-
if collage_maker_client:
|
| 1923 |
collage_maker_client.close()
|
| 1924 |
logger.info("Collage Maker MongoDB connection closed")
|
| 1925 |
|
|
@@ -1941,7 +1942,7 @@ def get_media_clicks_collection(appname: Optional[str] = None):
|
|
| 1941 |
if appname:
|
| 1942 |
normalized = appname.strip().lower()
|
| 1943 |
if normalized == "collage-maker":
|
| 1944 |
-
if collage_media_clicks_col:
|
| 1945 |
return collage_media_clicks_col
|
| 1946 |
logger.warning("COLLAGE_MAKER_DB_URL not configured; falling back to default media_clicks collection")
|
| 1947 |
return media_clicks_col
|
|
@@ -2302,7 +2303,7 @@ async def face_swap_api(
|
|
| 2302 |
# ------------------------------------------------------------------#
|
| 2303 |
# # MEDIA_CLICKS (ONLY IF user_id PRESENT)
|
| 2304 |
# ------------------------------------------------------------------#
|
| 2305 |
-
if user_id and media_clicks_collection:
|
| 2306 |
try:
|
| 2307 |
user_id_clean = user_id.strip()
|
| 2308 |
if not user_id_clean:
|
|
@@ -2462,7 +2463,7 @@ async def face_swap_api(
|
|
| 2462 |
|
| 2463 |
except Exception as media_err:
|
| 2464 |
logger.error(f"MEDIA_CLICK ERROR: {media_err}")
|
| 2465 |
-
elif user_id and
|
| 2466 |
logger.warning("Media clicks collection unavailable; skipping media click tracking")
|
| 2467 |
|
| 2468 |
# # ------------------------------------------------------------------
|
|
@@ -2764,7 +2765,7 @@ async def face_swap_api(
|
|
| 2764 |
target_url = asset["url"]
|
| 2765 |
subcategory_oid = doc["_id"]
|
| 2766 |
|
| 2767 |
-
if user_id and media_clicks_collection:
|
| 2768 |
try:
|
| 2769 |
user_id_clean = user_id.strip()
|
| 2770 |
if not user_id_clean:
|
|
@@ -2897,7 +2898,7 @@ async def face_swap_api(
|
|
| 2897 |
|
| 2898 |
except Exception as media_err:
|
| 2899 |
logger.error(f"MEDIA_CLICK ERROR: {media_err}")
|
| 2900 |
-
elif user_id and
|
| 2901 |
logger.warning("Media clicks collection unavailable; skipping media click tracking")
|
| 2902 |
|
| 2903 |
if target_category_id:
|
|
@@ -3084,3 +3085,4 @@ fastapi_app = mount_gradio_app(
|
|
| 3084 |
if __name__ == "__main__":
|
| 3085 |
uvicorn.run(fastapi_app, host="0.0.0.0", port=7860)
|
| 3086 |
|
|
|
|
|
|
| 1719 |
# uvicorn.run(fastapi_app, host="0.0.0.0", port=7860)
|
| 1720 |
|
| 1721 |
|
| 1722 |
+
# --------------------- List Images Endpoint ---------------------
|
| 1723 |
# --------------------- List Images Endpoint ---------------------
|
| 1724 |
import os
|
| 1725 |
os.environ["OMP_NUM_THREADS"] = "1"
|
|
|
|
| 1914 |
@fastapi_app.on_event("shutdown")
|
| 1915 |
async def shutdown_db():
|
| 1916 |
global client, admin_client, collage_maker_client
|
| 1917 |
+
if client is not None:
|
| 1918 |
client.close()
|
| 1919 |
logger.info("MongoDB connection closed")
|
| 1920 |
+
if admin_client is not None:
|
| 1921 |
admin_client.close()
|
| 1922 |
logger.info("Admin MongoDB connection closed")
|
| 1923 |
+
if collage_maker_client is not None:
|
| 1924 |
collage_maker_client.close()
|
| 1925 |
logger.info("Collage Maker MongoDB connection closed")
|
| 1926 |
|
|
|
|
| 1942 |
if appname:
|
| 1943 |
normalized = appname.strip().lower()
|
| 1944 |
if normalized == "collage-maker":
|
| 1945 |
+
if collage_media_clicks_col is not None:
|
| 1946 |
return collage_media_clicks_col
|
| 1947 |
logger.warning("COLLAGE_MAKER_DB_URL not configured; falling back to default media_clicks collection")
|
| 1948 |
return media_clicks_col
|
|
|
|
| 2303 |
# ------------------------------------------------------------------#
|
| 2304 |
# # MEDIA_CLICKS (ONLY IF user_id PRESENT)
|
| 2305 |
# ------------------------------------------------------------------#
|
| 2306 |
+
if user_id and media_clicks_collection is not None:
|
| 2307 |
try:
|
| 2308 |
user_id_clean = user_id.strip()
|
| 2309 |
if not user_id_clean:
|
|
|
|
| 2463 |
|
| 2464 |
except Exception as media_err:
|
| 2465 |
logger.error(f"MEDIA_CLICK ERROR: {media_err}")
|
| 2466 |
+
elif user_id and media_clicks_collection is None:
|
| 2467 |
logger.warning("Media clicks collection unavailable; skipping media click tracking")
|
| 2468 |
|
| 2469 |
# # ------------------------------------------------------------------
|
|
|
|
| 2765 |
target_url = asset["url"]
|
| 2766 |
subcategory_oid = doc["_id"]
|
| 2767 |
|
| 2768 |
+
if user_id and media_clicks_collection is not None:
|
| 2769 |
try:
|
| 2770 |
user_id_clean = user_id.strip()
|
| 2771 |
if not user_id_clean:
|
|
|
|
| 2898 |
|
| 2899 |
except Exception as media_err:
|
| 2900 |
logger.error(f"MEDIA_CLICK ERROR: {media_err}")
|
| 2901 |
+
elif user_id and media_clicks_collection is None:
|
| 2902 |
logger.warning("Media clicks collection unavailable; skipping media click tracking")
|
| 2903 |
|
| 2904 |
if target_category_id:
|
|
|
|
| 3085 |
if __name__ == "__main__":
|
| 3086 |
uvicorn.run(fastapi_app, host="0.0.0.0", port=7860)
|
| 3087 |
|
| 3088 |
+
|