Vijay Kumar N commited on
Commit ·
72c8da2
1
Parent(s): e22f190
Update app
Browse files
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 |
-
#
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
MODEL_ID = '1OozLJT6agC3axNaVbJGbHvwRroaP4XbX'
|
| 16 |
-
MODEL_PATH = 'Custom_layer.keras'
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
gdown.download(url, MODEL_PATH, quiet=False)
|
| 21 |
|
| 22 |
-
#
|
| 23 |
-
|
| 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":
|