chimithecat commited on
Commit
075b0b7
·
verified ·
1 Parent(s): d8298da

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ import numpy as np
4
+ from PIL import Image
5
+
6
+ # Download and load model
7
+ model_url = "https://huggingface.co/chimithecat/penyakit_tomat/resolve/main/Tomato_Models.h5"
8
+ model_path = tf.keras.utils.get_file("Tomato_Models.h5", model_url)
9
+ model = tf.keras.models.load_model(model_path)
10
+
11
+ # Define class names (update based on your training labels)
12
+ class_names = [
13
+ "Bacterial Spot", "Early Blight", "Healthy", "Late Blight"
14
+ ]
15
+
16
+ def predict(img: Image.Image):
17
+ img = img.resize((224, 224)) # Resize to match training size
18
+ img = np.array(img) / 255.0
19
+ img = np.expand_dims(img, axis=0) # Add batch dimension
20
+ predictions = model.predict(img)[0]
21
+ return {class_names[i]: float(predictions[i]) for i in range(len(class_names))}
22
+
23
+ gr.Interface(
24
+ fn=predict,
25
+ inputs=gr.Image(type="pil"),
26
+ outputs=gr.Label(num_top_classes=4),
27
+ title="Tomato Leaf Disease Classifier",
28
+ description="Upload a tomato leaf image to detect its disease"
29
+ ).launch()