Update app.py
Browse files
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 =
|
|
|
|
| 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 ππ"
|