Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from PIL import Image, UnidentifiedImageError
|
2 |
+
from transformers import ViTFeatureExtractor, ViTForImageClassification
|
3 |
+
feature_extractor = ViTFeatureExtractor.from_pretrained('wambugu71/crop_leaf_diseases_vit')
|
4 |
+
model = ViTForImageClassification.from_pretrained(
|
5 |
+
'wambugu1738/crop_leaf_diseases_vit',
|
6 |
+
ignore_mismatched_sizes=True
|
7 |
+
)
|
8 |
+
image = Image.open('<image_path>')
|
9 |
+
inputs = feature_extractor(images=image, return_tensors="pt")
|
10 |
+
outputs = model(**inputs)
|
11 |
+
logits = outputs.logits
|
12 |
+
predicted_class_idx = logits.argmax(-1).item()
|
13 |
+
print("Predicted class:", model.config.id2label[predicted_class_idx])
|