Spaces:
Runtime error
Runtime error
Update app.py
Browse files2 unmodified lines34567891011121314151617181920212223242526279 unmodified lines37383940414243444546474849505152535455561 unmodified line5859606162636465666768697071727374757677787980812 unmodified linesimport numpy as npfrom tensorflow.keras.models import load_modelclass_folders = ["Ajloun Castle", "Jeresh", "Petra", "Roman amphitheater", "Umm_Qais", "Wadi_Rum"]Inception_path='./Models/new_efficientnet.h5'VGGNet_path='./Models/new_vgg_16.hdf5'ResNet_path= './Models/new_resnet50.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)history=[]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)9 unmodified linespredictions = Inception_model.predict(img)class_index = np.argmax(predictions[0])class_name = class_folders[class_index]probability = round(max(predictions[0]) * 100, 2)result_str = f" {model_name} : {class_name} {probability}% "history.append(result_str)return class_name, probability, history[-3:-1]except Exception as e:error_message = f"Error: {str(e)}"return None, None, Noneimage_input = gr.Image(type='filepath', label="Input Image")model_dropdown = gr.Dropdown(["ResNet", "EfficientNet", "VGGNet", "InceptionV3"], label="Select Model")1 unmodified lineiface = gr.Interface(fn=classify_selected_model,inputs=[image_input, model_dropdown ,],outputs=[gr.Label(value="Archaeological Site"),gr.Label(value="Probability"),result_textbox],examples=[["Sites/Ajloun.png" ],["Sites/Jeresh.png"],["Sites/Umm Qais.png"],["Sites/Petra.png"],["Sites/Roman Amphitheater.png"],["Sites/Wadi Rum.png"]] ,live=True,title="Image Classification for Archaeological Sites Interface",)iface.launch(debug=True, share=True )2 unmodified lines3456789101112131415161718192021222324259 unmodified lines35363738394041424344454647484950515253545556571 unmodified line596061626364656667686970717273747576777879802 unmodified linesimport numpy as npfrom tensorflow.keras.models import load_modelclass_folders = ["Ajloun Castle", "Jeresh", "Petra", "Roman amphitheater", "Umm_Qais", "Wadi_Rum"]Inception_path = './Models/new_efficientnet.h5'VGGNet_path = './Models/new_vgg_16.hdf5'ResNet_path = './Models/new_resnet50.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)history = []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)9 unmodified linespredictions = Inception_model.predict(img)class_index = np.argmax(predictions[0])probability = max(predictions[0]) * 100if probability >= 50: # Threshold to consider as a valid predictionclass_name = class_folders[class_index]result_str = f" {model_name} : {class_name} {probability:.2f}% "else:class_name = "Unknown"result_str = f" {model_name} : {class_name} Probability below threshold"history.append(result_str)return class_name, probability, history[-3:-1]except Exception as e:error_message = f"Error: {str(e)}"return None, None, Noneimage_input = gr.Image(type='filepath', label="Input Image")model_dropdown = gr.Dropdown(["ResNet", "EfficientNet", "VGGNet", "InceptionV3"], label="Select Model")1 unmodified lineiface = gr.Interface(fn=classify_selected_model,inputs=[image_input, model_dropdown, ],outputs=[gr.Label(value="Archaeological Site"),gr.Label(value="Probability"),result_textbox],examples=[["Sites/Ajloun.png"],["Sites/Jeresh.png"],["Sites/Umm Qais.png"],["Sites/Petra.png"],["Sites/Roman Amphitheater.png"],["Sites/Wadi Rum.png"]],live=True,title="Image Classification for Archaeological Sites Interface",)iface.launch(debug=True, share=True)
app.py+25-26