cosmin1769 commited on
Commit
30bdbe8
·
verified ·
1 Parent(s): d1c7681

Update app/main.py

Browse files
Files changed (1) hide show
  1. app/main.py +9 -12
app/main.py CHANGED
@@ -339,10 +339,6 @@ async def predict(file: UploadFile=File(...),db:Session=Depends(get_db),current_
339
  status_code=500,
340
  detail="Analysis returned no result (internal error)"
341
  )
342
- try:
343
- os.remove(temp_path)
344
- except:
345
- pass
346
  if not result['success']:
347
  raise HTTPException(
348
  status_code=500,
@@ -365,7 +361,7 @@ async def predict(file: UploadFile=File(...),db:Session=Depends(get_db),current_
365
  carbs_g=macros.get('carbs_g',0.0) or 0.0
366
  fat_g=macros.get('fat_g',0.0) or 0.0
367
  foods_list.append({"name":food_name,
368
- "grams":estimated_grams,
369
  "calories":estimated_calories,
370
  "protein_g":protein_g,
371
  "carbs_g":carbs_g,
@@ -380,14 +376,15 @@ async def predict(file: UploadFile=File(...),db:Session=Depends(get_db),current_
380
  except HTTPException:
381
  raise
382
  except Exception as e:
383
- try:
384
- os.remove(temp_path)
385
- except:
386
- pass
387
  raise HTTPException(
388
  status_code=500,
389
  detail=f"Analysis failed: {str(e)}"
390
  )
 
 
 
 
 
391
  except HTTPException:
392
  raise
393
  except Exception as e:
@@ -514,7 +511,7 @@ def update_meal(meal_id:int,request:UpdateMealRequest,db:Session=Depends(get_db)
514
  }
515
 
516
  @app.delete("/history/item/{meal_id}")
517
- def update_meal(meal_id:int,db:Session=Depends(get_db),current_user: User = Depends(get_current_user)):
518
  meal = db.query(History).filter(History.id == meal_id, History.user_id == current_user.id).first()
519
  if not meal:
520
  raise HTTPException(
@@ -566,7 +563,7 @@ def get_profile(current_user:User=Depends(get_current_user)):
566
  @app.put("/profile")
567
  def update_profile(request:UpdateProfileRequest,db:Session=Depends(get_db),current_user:User=Depends(get_current_user)):
568
  if request.username and request.username!=current_user.username:
569
- existing=db.query(User).filter(User.username==request.username).firt()
570
  if existing:
571
  raise HTTPException(status_code=400, detail="Username already taken.")
572
  current_user.username = request.username
@@ -767,7 +764,7 @@ def get_progress(db:Session=Depends(get_db),current_user:User=Depends(get_curren
767
  today=date_type.today()
768
  streak=0
769
  check_day=today
770
- logged_days=set(h.log_date.date() for h in all_history)
771
  while check_day in logged_days:
772
  streak+=1
773
  check_day-=timedelta(days=1)
 
339
  status_code=500,
340
  detail="Analysis returned no result (internal error)"
341
  )
 
 
 
 
342
  if not result['success']:
343
  raise HTTPException(
344
  status_code=500,
 
361
  carbs_g=macros.get('carbs_g',0.0) or 0.0
362
  fat_g=macros.get('fat_g',0.0) or 0.0
363
  foods_list.append({"name":food_name,
364
+ "grams":int(round(estimated_grams)),
365
  "calories":estimated_calories,
366
  "protein_g":protein_g,
367
  "carbs_g":carbs_g,
 
376
  except HTTPException:
377
  raise
378
  except Exception as e:
 
 
 
 
379
  raise HTTPException(
380
  status_code=500,
381
  detail=f"Analysis failed: {str(e)}"
382
  )
383
+ finally:
384
+ try:
385
+ os.remove(temp_path)
386
+ except:
387
+ pass
388
  except HTTPException:
389
  raise
390
  except Exception as e:
 
511
  }
512
 
513
  @app.delete("/history/item/{meal_id}")
514
+ def delete_meal(meal_id:int,db:Session=Depends(get_db),current_user: User = Depends(get_current_user)):
515
  meal = db.query(History).filter(History.id == meal_id, History.user_id == current_user.id).first()
516
  if not meal:
517
  raise HTTPException(
 
563
  @app.put("/profile")
564
  def update_profile(request:UpdateProfileRequest,db:Session=Depends(get_db),current_user:User=Depends(get_current_user)):
565
  if request.username and request.username!=current_user.username:
566
+ existing=db.query(User).filter(User.username==request.username).first()
567
  if existing:
568
  raise HTTPException(status_code=400, detail="Username already taken.")
569
  current_user.username = request.username
 
764
  today=date_type.today()
765
  streak=0
766
  check_day=today
767
+ logged_days=set(h.log_date.date() for h in all_history if h.log_date)
768
  while check_day in logged_days:
769
  streak+=1
770
  check_day-=timedelta(days=1)