Download app.py from Mr-Master/watermelon-leaf-classifier: direct link, hf CLI and curl.
- Browser
- Download file 946 Bytes
-
https://huggingface.co/spaces/Mr-Master/watermelon-leaf-classifier/resolve/main/app.py
- Command line
-
hf download hf://spaces/Mr-Master/watermelon-leaf-classifier/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Mr-Master/watermelon-leaf-classifier/resolve/main/app.py
946 Bytes
| import gradio as gr | |
| import tensorflow as tf | |
| import numpy as np | |
| from PIL import Image | |
| # Load your trained model | |
| model = tf.keras.models.load_model("watermelon_cnn_model.h5") # Ensure this matches the name in your repo | |
| # Define the prediction function | |
| def predict(image): | |
| # Resize the input image to match the model's input size | |
| image = image.resize((128, 128)) # Adjust dimensions to match your model | |
| image = np.array(image) / 255.0 # Normalize pixel values | |
| image = np.expand_dims(image, axis=0) # Add batch dimension | |
| prediction = model.predict(image) | |
| # Replace the below with your actual class names | |
| class_names = ["Anthracnose", "Downy Mildew", "Mosaic Virus", "Healthy"] | |
| return {class_names[i]: float(prediction[0][i]) for i in range(len(class_names))} | |
| # Create a Gradio interface | |
| interface = gr.Interface( | |
| fn=predict, | |
| inputs=gr.Image(type="pil"), | |
| outputs=gr.Label() | |
| ) | |
| interface.launch() | |