ECCesA commited on
Commit
f2cd35d
·
verified ·
1 Parent(s): 2a02793

Upload 3 files

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ plantvillage_efficientnet_b0.keras filter=lfs diff=lfs merge=lfs -text
app.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ import numpy as np
4
+ import os
5
+
6
+ # 1. Load the model with error handling
7
+ try:
8
+ model_path = 'plantvillage_efficientnet_b0.keras'
9
+ if not os.path.exists(model_path):
10
+ raise FileNotFoundError(f"Model file {model_path} not found in Space!")
11
+
12
+ model = tf.keras.models.load_model(model_path, compile=False)
13
+ print("Model loaded successfully!")
14
+ except Exception as e:
15
+ print(f"CRITICAL ERROR LOADING MODEL: {e}")
16
+ model = None
17
+
18
+ classes = [
19
+ 'Pepper__bell___Bacterial_spot', 'Pepper__bell___healthy', 'Potato___Early_blight',
20
+ 'Potato___Late_blight', 'Potato___healthy', 'Tomato_Bacterial_spot',
21
+ 'Tomato_Early_blight', 'Tomato_Late_blight', 'Tomato_Leaf_Mold',
22
+ 'Tomato_Septoria_leaf_spot', 'Tomato_Spider_mites_Two_spotted_spider_mite',
23
+ 'Tomato__Target_Spot', 'Tomato__Tomato_YellowLeaf__Curl_Virus',
24
+ 'Tomato__Tomato_mosaic_virus', 'Tomato_healthy'
25
+ ]
26
+
27
+ def predict(image):
28
+ if model is None:
29
+ return "Error: Model failed to load. Check Space logs."
30
+
31
+ img = tf.cast(image, tf.float32)
32
+ img = tf.image.resize(img, (224, 224))
33
+ img = tf.keras.applications.efficientnet.preprocess_input(img)
34
+ img = tf.expand_dims(img, axis=0)
35
+
36
+ preds = model.predict(img)[0]
37
+ return {classes[i]: float(preds[i]) for i in range(len(classes))}
38
+
39
+ demo = gr.Interface(
40
+ fn=predict,
41
+ inputs=gr.Image(),
42
+ outputs=gr.Label(num_top_classes=3),
43
+ title="Plant Disease Detector",
44
+ description="Identify plant leaf diseases."
45
+ )
46
+
47
+ if __name__ == '__main__':
48
+ demo.launch()
plantvillage_efficientnet_b0.keras ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1db71d8fafcc5a0b0d7868dc3227310972017ab27ebefb7ebfa0d90e85e9bb18
3
+ size 59863969
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ tensorflow
2
+ gradio
3
+ numpy