Spaces:
Sleeping
Sleeping
Update app.py
Browse files1234566789103 unmodified lines1415161617181918202122232425262327282912 unmodified lines4243444245464748import gradio as grimport tensorflow as tffrom tensorflow.keras.models import load_modelfrom tensorflow.keras import backend as K # <--- 1. IMPORT THE KERAS BACKENDimport numpy as npfrom PIL import Imageimport time # Import the time library for diagnosticsimport time
print("[INFO] app.py script started at {}.".format(time.ctime()))
3 unmodified lines
# --- Load the Model (this will happen once when the app starts) ---print("[INFO] Attempting to load the trained model from: {}".format(MODEL_PATH))# This is the most likely point of failure.try: # --- 2. THE CRITICAL FIX IS HERE --- # We must tell load_model what 'K' means in our custom layers. model = load_model(MODEL_PATH) model = load_model(MODEL_PATH, custom_objects={"K": K}) # --- END OF FIX --- print("[SUCCESS] Model loaded successfully into memory.")except Exception as e: print("[FATAL ERROR] Failed to load the model.") print("Error details: {}".format(e)) # If the model fails to load, raise the exception to stop the app raise e
def getLabel(class_id):12 unmodified lines # Preprocess the image image = input_image.convert("RGB").resize((IMAGE_SIZE, IMAGE_SIZE)) image_array = np.asarray(image) image_array = image_array / 255.0 # Use 255.0 for normalization image_array = image_array / 255.0 image_array = np.expand_dims(image_array, axis=0) # --- Make Prediction ---app.py+8-5