Spaces:
Build error
Build error
Create app.py
Browse files1234567891011121314151617181920212223242526272829303132333435363738import gradio as grimport tensorflow as tfimport numpy as npfrom PIL import Imagefrom io import BytesIO
# Load ModelMODEL = tf.keras.models.load_model("new_cnn_model_tf.h5")CLASS_NAMES = ["Early Blight", "Late Blight", "Healthy"]
# Function to process and predictdef predict(image): # Convert image to numpy array image = np.array(image) # Expand dimensions to match model input shape img_batch = np.expand_dims(image, 0) # Make prediction predictions = MODEL.predict(img_batch) # Get class and confidence predicted_class = CLASS_NAMES[np.argmax(predictions[0])] confidence = float(np.max(predictions[0])) return f"Prediction: {predicted_class} (Confidence: {confidence:.2f})"
# Create Gradio Interfaceiface = gr.Interface( fn=predict, # Function to call inputs=gr.Image(type="pil"), # Image input (PIL format) outputs="text", # Text output (prediction result) title="Potato Disease Classifier", description="Upload an image of a potato leaf, and the model will predict whether it's Healthy, Early Blight, or Late Blight.")
# Launch the appiface.launch()app.pyAdded+38