aniket-manhas commited on
Commit
c8d5463
·
verified ·
1 Parent(s): bdf9b20

Upload 6 files

Browse files
Files changed (2) hide show
  1. app.py +13 -3
  2. requirements.txt +0 -0
app.py CHANGED
@@ -6,10 +6,20 @@ import numpy as np
6
  from PIL import Image
7
  import io
8
  import uvicorn
 
9
 
10
- # Load model
 
 
 
11
  MODEL_PATH = "best_model.keras"
12
- model = load_model(MODEL_PATH)
 
 
 
 
 
 
13
  class_names = ["Early Blight", "Late Blight", "Healthy"]
14
 
15
  # Preprocess image
@@ -22,7 +32,7 @@ def preprocess(img):
22
  img = img.resize((256, 256))
23
  img_array = image.img_to_array(img) / 255.0
24
  img_array = np.expand_dims(img_array, axis=0)
25
- prediction = model.predict(img_array)
26
  class_index = np.argmax(prediction[0])
27
  return class_names[class_index]
28
 
 
6
  from PIL import Image
7
  import io
8
  import uvicorn
9
+ import tensorflow as tf
10
 
11
+ # Configure TensorFlow to use CPU only
12
+ tf.config.set_visible_devices([], 'GPU')
13
+
14
+ # Load model with custom_objects to handle version compatibility
15
  MODEL_PATH = "best_model.keras"
16
+ try:
17
+ model = load_model(MODEL_PATH, compile=False)
18
+ except Exception as e:
19
+ print(f"Error loading model: {str(e)}")
20
+ # Try loading with custom_objects
21
+ model = load_model(MODEL_PATH, compile=False, custom_objects={'tf': tf})
22
+
23
  class_names = ["Early Blight", "Late Blight", "Healthy"]
24
 
25
  # Preprocess image
 
32
  img = img.resize((256, 256))
33
  img_array = image.img_to_array(img) / 255.0
34
  img_array = np.expand_dims(img_array, axis=0)
35
+ prediction = model.predict(img_array, verbose=0) # Added verbose=0 to reduce output
36
  class_index = np.argmax(prediction[0])
37
  return class_names[class_index]
38
 
requirements.txt CHANGED
Binary files a/requirements.txt and b/requirements.txt differ