Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -24,8 +24,15 @@ app.add_middleware(
|
|
| 24 |
labels = ['butterfly', 'cow', 'dog', 'elephant', 'goat', 'hen', 'horse', 'spyder']
|
| 25 |
|
| 26 |
# 🔥 load model (Keras 3 fix)
|
| 27 |
-
model =
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
def preprocess(image):
|
| 30 |
image = image.resize((224, 224))
|
| 31 |
image = np.array(image).astype("float32")
|
|
@@ -46,7 +53,7 @@ async def predict(file: UploadFile = File(...)):
|
|
| 46 |
input_data = preprocess(image)
|
| 47 |
|
| 48 |
# 🔥 inference
|
| 49 |
-
pred =
|
| 50 |
|
| 51 |
# handle dict output
|
| 52 |
if isinstance(pred, dict):
|
|
|
|
| 24 |
labels = ['butterfly', 'cow', 'dog', 'elephant', 'goat', 'hen', 'horse', 'spyder']
|
| 25 |
|
| 26 |
# 🔥 load model (Keras 3 fix)
|
| 27 |
+
model = None
|
| 28 |
+
|
| 29 |
+
def get_model():
|
| 30 |
+
global model
|
| 31 |
+
if model is None:
|
| 32 |
+
print("🔥 Loading model...")
|
| 33 |
+
model = TFSMLayer("saved_model", call_endpoint="serving_default")
|
| 34 |
+
return model
|
| 35 |
+
|
| 36 |
def preprocess(image):
|
| 37 |
image = image.resize((224, 224))
|
| 38 |
image = np.array(image).astype("float32")
|
|
|
|
| 53 |
input_data = preprocess(image)
|
| 54 |
|
| 55 |
# 🔥 inference
|
| 56 |
+
pred = get_model()(input_data)
|
| 57 |
|
| 58 |
# handle dict output
|
| 59 |
if isinstance(pred, dict):
|