Vijay Kumar N commited on
Commit
72c8da2
·
1 Parent(s): e22f190

Update app

Browse files
Files changed (1) hide show
  1. app.py +8 -15
app.py CHANGED
@@ -1,5 +1,4 @@
1
  import os
2
- import gdown
3
  from fastapi import FastAPI, File, UploadFile
4
  from fastapi.responses import JSONResponse
5
  from tensorflow.keras.preprocessing.image import img_to_array
@@ -8,22 +7,16 @@ import tensorflow as tf
8
  import numpy as np
9
  import io
10
 
11
- # Create a FastAPI application
12
- app = FastAPI(title="Leaf Disease Classifier API")
13
-
14
- # Model URL (replace with your Google Drive file ID)
15
- MODEL_ID = '1OozLJT6agC3axNaVbJGbHvwRroaP4XbX'
16
- MODEL_PATH = 'Custom_layer.keras'
17
 
18
- def download_model():
19
- url = f'https://drive.google.com/uc?id={MODEL_ID}'
20
- gdown.download(url, MODEL_PATH, quiet=False)
21
 
22
- # Download and load the model
23
- if not os.path.exists(MODEL_PATH):
24
- download_model()
25
-
26
- model = tf.keras.models.load_model(MODEL_PATH, custom_objects={'Precision': tf.keras.metrics.Precision, 'Recall': tf.keras.metrics.Recall})
27
 
28
  def prepare_image(image, target_size):
29
  if image.mode != "RGB":
 
1
  import os
 
2
  from fastapi import FastAPI, File, UploadFile
3
  from fastapi.responses import JSONResponse
4
  from tensorflow.keras.preprocessing.image import img_to_array
 
7
  import numpy as np
8
  import io
9
 
10
+ # Verify the model file exists
11
+ model_path = 'Custom_layer.h5'
12
+ if not os.path.exists(model_path):
13
+ raise FileNotFoundError(f"Model file not found at {model_path}")
 
 
14
 
15
+ # Load the trained model
16
+ model = tf.keras.models.load_model(model_path, custom_objects={'Precision': tf.keras.metrics.Precision, 'Recall': tf.keras.metrics.Recall})
 
17
 
18
+ # Create a FastAPI application
19
+ app = FastAPI(title="Leaf Disease Classifier API")
 
 
 
20
 
21
  def prepare_image(image, target_size):
22
  if image.mode != "RGB":