Spaces:
Runtime error
Runtime error
Create app.py
Browse files12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758import gradio as grimport cv2import numpy as npfrom tensorflow.keras.models import load_model
class_folders = ["Ajloun Castle", "Jeresh", "Petra", "Roman amphitheater", "Umm_Qais", "Wadi_Rum"]
# Define paths for the HDF5 modelsInception_path='./inceptionv3_-saved-model-59-val_accuracy-0.94.hdf5'VGGNet_path='./vgg_16_-saved-model-89-acc-0.93.hdf5'ResNet_path= './resnet50-saved-model-79-val_acc-1.00.hdf5'EfficientNet_path= './efficientnet-saved-model-06-val_acc-0.98.hdf5'
Inception_model = load_model(Inception_path)VGGNet_model = load_model(VGGNet_path)ResNet_model = load_model(ResNet_path)Efficient_model = load_model(EfficientNet_path)
def classify_selected_model(image, model_name): try: img = cv2.imread(image) img = cv2.resize(img, (150, 150)) img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) img = np.expand_dims(img, axis=0)
if model_name == "ResNet": predictions = ResNet_model.predict(img) elif model_name == "EfficientNet": predictions = Efficient_model.predict(img) elif model_name == "VGGNet": predictions = VGGNet_model.predict(img) elif model_name == "InceptionV3": predictions = Inception_model.predict(img)
class_indices = np.argsort(predictions[0])[::-1] # Sort indices in descending order of probability class_probabilities = predictions[0][class_indices] class_names = [class_folders[idx] for idx in class_indices]
return class_names, class_probabilities.tolist()
except Exception as e: return [str(e)], [None] # Return an error message and None for probability
# Create Gradio interfaceimage_input = gr.Image(type='filepath', label="Input Image")model_dropdown = gr.Dropdown(["ResNet", "EfficientNet", "VGGNet", "InceptionV3"], label="Select Model")
iface = gr.Interface( fn=classify_selected_model, inputs=[image_input, model_dropdown], outputs=[ gr.Textbox(label="Predicted Classes"), gr.Table(label="Class Probabilities") ], live=True)
iface.launch(debug=True, share=True)app.pyAdded+58