Spaces:
Sleeping
Sleeping
Download predict.py from AlonBBar/image_Classifier: direct link, hf CLI and curl.
- Browser
- Download file 766 Bytes
-
https://huggingface.co/spaces/AlonBBar/image_Classifier/resolve/adde12e85c427be8fa8fc9c4630b9ca41c8fa3b4/predict.py
- Command line
-
hf download hf://spaces/AlonBBar/image_Classifier@adde12e85c427be8fa8fc9c4630b9ca41c8fa3b4/predict.py
-
curl -L -o predict.py https://huggingface.co/spaces/AlonBBar/image_Classifier/resolve/adde12e85c427be8fa8fc9c4630b9ca41c8fa3b4/predict.py
766 Bytes
| 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) |