Spaces:
Runtime error
Runtime error
Update app.py
Browse files4 unmodified lines567891011891011121314151617181819202110 unmodified lines3233343536373536383940414243384445464142474849505152535449555651525354555657575859606162636465666768596069707163724 unmodified lines
class_folders = ["Ajloun Castle", "Jeresh", "Petra", "Roman amphitheater", "Umm_Qais", "Wadi_Rum"]
Inception_path='./Models/inceptionv3_-saved-model-59-val_accuracy-0.94.hdf5'VGGNet_path='./Models/vgg_16_-saved-model-89-acc-0.93.hdf5'ResNet_path= './Models/resnet50-saved-model-79-val_acc-1.00.hdf5'EfficientNet_path= './Models/efficientnet-saved-model-06-val_acc-0.98.hdf5'Inception_path = './Models/inceptionv3_-saved-model-59-val_accuracy-0.94.hdf5'VGGNet_path = './Models/vgg_16_-saved-model-89-acc-0.93.hdf5'ResNet_path = './Models/resnet50-saved-model-79-val_acc-1.00.hdf5'EfficientNet_path = './Models/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):def classify_selected_model(image, model_name, confidence_threshold): try: img = cv2.imread(image) img = cv2.resize(img, (150, 150))10 unmodified lines predictions = Inception_model.predict(img)
class_index = np.argmax(predictions[0]) confidence = max(predictions[0]) if confidence >= confidence_threshold: class_name = class_folders[class_index] probability = round(max(predictions[0]) * 100, 2) class_name = class_folders[class_index] probability = round(confidence * 100, 2) else: class_name = "Unknown" probability = 0.0
return class_name, probability return class_name, probability
except Exception as e: return str(e), None
return str(e), None
image_input = gr.Image(type='filepath', label="Input Image")model_dropdown = gr.Dropdown(["ResNet", "EfficientNet", "VGGNet", "InceptionV3"], label="Select Model")confidence_slider = gr.Slider(minimum=0, maximum=1, default=0.5, label="Confidence Threshold")
iface = gr.Interface( fn=classify_selected_model, inputs=[image_input, model_dropdown], inputs=[image_input, model_dropdown, confidence_slider], outputs=[ gr.Label(value="Archaeological Site"), gr.Label(value="Probability")], examples=[ ["Sites/Ajloun.png", "ResNet"], ["Sites/Jeresh.png", "VGGNet"], ["Sites/Umm Qais.png", "EfficientNet"], ["Sites/Petra.png", "InceptionV3"]], gr.Label(value="Archaeological Site"), gr.Label(value="Probability") ], examples=[ ["Sites/Ajloun.png", "ResNet", 0.5], ["Sites/Jeresh.png", "VGGNet", 0.5], ["Sites/Umm Qais.png", "EfficientNet", 0.5], ["Sites/Petra.png", "InceptionV3", 0.5], ["Sites/Wadi Rum.png", "ResNet", 0.5], ["Sites/Roman Amphitheater.png", "VGGNet", 0.5] ], live=True, title="Image Classification for Archaeological Sites Interface", title="Image Classification for Archaeological Sites Interface")
iface.launch(debug=True, share=True )iface.launch(debug=True, share=True)app.py+30-21