Spaces:
Sleeping
Sleeping
| import tensorflow as tf | |
| import numpy as np | |
| from PIL import Image | |
| import sys | |
| # Load the trained Keras model (adjust path as needed) | |
| model = tf.keras.models.load_model('plantvillage_model.keras', compile=False) | |
| # Class names matching the model output order | |
| class_names = [ | |
| 'Pepper__bell___Bacterial_spot', | |
| 'Pepper__bell___healthy', | |
| 'Potato___Early_blight', | |
| 'Potato___healthy' | |
| ] | |
| if __name__ == "__main__": | |
| if len(sys.argv) < 2: | |
| print("Usage: python predict.py <image_path>") | |
| sys.exit(1) | |
| image_path = sys.argv[1] | |
| try: | |
| image = Image.open(image_path) | |
| except Exception as e: | |
| print(f"Error opening image: {e}") | |
| sys.exit(1) | |
| result = predict(image) | |
| print("Prediction:", result) |