jarif commited on
Commit
5f86926
1 Parent(s): 47f2e71

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -13
app.py CHANGED
@@ -40,25 +40,16 @@ def classify_food_vs_nonfood(image):
40
  # Create a draw object
41
  draw = ImageDraw.Draw(image)
42
 
43
- # Specify font and size
44
- font = ImageFont.load_default()
45
-
46
- # Get text size
47
- text_font = ImageFont.truetype("Hack-Regular.ttf", 24)
48
- text_bbox = draw.textbbox((0, 0), label, font=text_font)
49
- text_size = (text_bbox[2] - text_bbox[0], text_bbox[3] - text_bbox[1])
50
-
51
- # Calculate text position
52
- text_position = ((image_size[0] - text_size[0]) // 2, 10)
53
-
54
  # Determine label color and font size based on prediction
55
  if final_prediction == 0:
56
  label_color = (255, 0, 0) # Red for "Food"
57
  text_font = ImageFont.truetype("Hack-Regular.ttf", 24) # Font size for "Food"
 
 
 
58
  else:
59
  label_color = (0, 255, 0) # Green for "Non Food"
60
- text_font = ImageFont.truetype("Hack-Regular.ttf", 36) # Font size for "Non Food"
61
- # Calculate text position for larger font size
62
  text_bbox = draw.textbbox((0, 0), label, font=text_font)
63
  text_size = (text_bbox[2] - text_bbox[0], text_bbox[3] - text_bbox[1])
64
  text_position = ((image_size[0] - text_size[0]) // 2, (image_size[1] - text_size[1]) // 2)
 
40
  # Create a draw object
41
  draw = ImageDraw.Draw(image)
42
 
 
 
 
 
 
 
 
 
 
 
 
43
  # Determine label color and font size based on prediction
44
  if final_prediction == 0:
45
  label_color = (255, 0, 0) # Red for "Food"
46
  text_font = ImageFont.truetype("Hack-Regular.ttf", 24) # Font size for "Food"
47
+ text_bbox = draw.textbbox((0, 0), label, font=text_font)
48
+ text_size = (text_bbox[2] - text_bbox[0], text_bbox[3] - text_bbox[1])
49
+ text_position = ((image_size[0] - text_size[0]) // 2, 10)
50
  else:
51
  label_color = (0, 255, 0) # Green for "Non Food"
52
+ text_font = ImageFont.truetype("Hack-Regular.ttf", 48) # Increased font size for "Non Food"
 
53
  text_bbox = draw.textbbox((0, 0), label, font=text_font)
54
  text_size = (text_bbox[2] - text_bbox[0], text_bbox[3] - text_bbox[1])
55
  text_position = ((image_size[0] - text_size[0]) // 2, (image_size[1] - text_size[1]) // 2)