amar6de2 commited on
Commit
605888c
Β·
verified Β·
1 Parent(s): 879ab6d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -3
app.py CHANGED
@@ -34,11 +34,10 @@ def predict(img) -> Tuple[Dict, float]:
34
  """Transforms and performs a prediction on img and returns prediction and time taken."""
35
  start_time = timer()
36
 
37
- # βœ… Convert numpy image (dtype=uint8) to PIL.Image (RGB)
38
  if isinstance(img, np.ndarray):
39
- img = Image.fromarray(img.astype("uint8"), mode="RGB")
 
40
 
41
- # Now it's safe to use vit_transforms
42
  img = vit_transforms(img).unsqueeze(0)
43
 
44
  vit.eval()
@@ -52,6 +51,7 @@ def predict(img) -> Tuple[Dict, float]:
52
  pred_time = round(timer() - start_time, 5)
53
  return pred_labels_and_probs, pred_time
54
 
 
55
  ### 4. Gradio app ###
56
 
57
  title = "VisionBite πŸ”πŸ‘"
 
34
  """Transforms and performs a prediction on img and returns prediction and time taken."""
35
  start_time = timer()
36
 
 
37
  if isinstance(img, np.ndarray):
38
+ img = img.astype(np.uint8) # βœ… Ensure dtype is uint8
39
+ img = Image.fromarray(img, mode="RGB") # βœ… Safe conversion
40
 
 
41
  img = vit_transforms(img).unsqueeze(0)
42
 
43
  vit.eval()
 
51
  pred_time = round(timer() - start_time, 5)
52
  return pred_labels_and_probs, pred_time
53
 
54
+
55
  ### 4. Gradio app ###
56
 
57
  title = "VisionBite πŸ”πŸ‘"