Spaces:
Sleeping
Sleeping
Add full project files
Browse files- predict.py +32 -0
- requirements.txt +5 -0
predict.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
import numpy as np
|
| 3 |
+
from PIL import Image
|
| 4 |
+
import sys
|
| 5 |
+
|
| 6 |
+
# Load the trained Keras model (adjust path as needed)
|
| 7 |
+
model = tf.keras.models.load_model('plantvillage_model.keras', compile=False)
|
| 8 |
+
|
| 9 |
+
# Class names matching the model output order
|
| 10 |
+
class_names = [
|
| 11 |
+
'Pepper__bell___Bacterial_spot',
|
| 12 |
+
'Pepper__bell___healthy',
|
| 13 |
+
'Potato___Early_blight',
|
| 14 |
+
'Potato___healthy'
|
| 15 |
+
]
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
if __name__ == "__main__":
|
| 19 |
+
if len(sys.argv) < 2:
|
| 20 |
+
print("Usage: python predict.py <image_path>")
|
| 21 |
+
sys.exit(1)
|
| 22 |
+
|
| 23 |
+
image_path = sys.argv[1]
|
| 24 |
+
|
| 25 |
+
try:
|
| 26 |
+
image = Image.open(image_path)
|
| 27 |
+
except Exception as e:
|
| 28 |
+
print(f"Error opening image: {e}")
|
| 29 |
+
sys.exit(1)
|
| 30 |
+
|
| 31 |
+
result = predict(image)
|
| 32 |
+
print("Prediction:", result)
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
tensorflow
|
| 2 |
+
numpy
|
| 3 |
+
pillow
|
| 4 |
+
gradio
|
| 5 |
+
|