LogicGoInfotechSpaces commited on
Commit
fcf34e8
·
verified ·
1 Parent(s): c41d228

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -2
app.py CHANGED
@@ -105,6 +105,14 @@ def prepare_image(file_bytes: bytes) -> Image.Image:
105
  Open image and resize if larger than 1024x1024
106
  """
107
  img = Image.open(io.BytesIO(file_bytes)).convert("RGB")
 
 
 
 
 
 
 
 
108
  img = resize_image_if_needed(img, max_size=(1024, 1024))
109
  return img
110
 
@@ -222,6 +230,8 @@ async def generate(
222
  # --------------------------------------------------
223
  # DAILY COUNT LOGIC
224
  # --------------------------------------------------
 
 
225
  doc = media_clicks_col.find_one({"userId": user_oid}, {"ai_edit_daily_count": 1})
226
  daily_entries = doc.get("ai_edit_daily_count", []) if doc else []
227
 
@@ -231,8 +241,8 @@ async def generate(
231
  # First-ever usage → only today
232
  daily_updates.append({"date": today_date, "count": 1})
233
  else:
234
- existing_dates = {entry["date"].date(): entry["count"] for entry in daily_entries}
235
- last_date_in_db = max(entry["date"].date() for entry in daily_entries)
236
 
237
  # Fill all missing days between last_date_in_db and today-1 with 0
238
  next_day = last_date_in_db + timedelta(days=1)
 
105
  Open image and resize if larger than 1024x1024
106
  """
107
  img = Image.open(io.BytesIO(file_bytes)).convert("RGB")
108
+
109
+ # ✅ MIN SIZE CHECK
110
+ if img.width < 200 or img.height < 200:
111
+ raise HTTPException(
112
+ status_code=400,
113
+ detail="Image size is below 200x200 pixels. Please upload a larger image."
114
+ )
115
+ img = Image.open(io.BytesIO(file_bytes)).convert("RGB")
116
  img = resize_image_if_needed(img, max_size=(1024, 1024))
117
  return img
118
 
 
230
  # --------------------------------------------------
231
  # DAILY COUNT LOGIC
232
  # --------------------------------------------------
233
+ now = datetime.utcnow()
234
+ today_date = now.date()
235
  doc = media_clicks_col.find_one({"userId": user_oid}, {"ai_edit_daily_count": 1})
236
  daily_entries = doc.get("ai_edit_daily_count", []) if doc else []
237
 
 
241
  # First-ever usage → only today
242
  daily_updates.append({"date": today_date, "count": 1})
243
  else:
244
+ existing_dates = {entry["date"]: entry["count"] for entry in daily_entries}
245
+ last_date_in_db = max(existing_dates.keys())
246
 
247
  # Fill all missing days between last_date_in_db and today-1 with 0
248
  next_day = last_date_in_db + timedelta(days=1)