Spaces:
Runtime error
Runtime error
aa
Browse files2 unmodified lines34567875 unmodified lines8485862 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/inceptionv3_-saved-model-59-val_accuracy-0.94.hdf5'75 unmodified lines)iface.launch(debug=True, share=True)2 unmodified lines345678975 unmodified lines8586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611622 unmodified linesimport numpy as npfrom tensorflow.keras.models import load_model"""class_folders = ["Ajloun Castle", "Jeresh", "Petra", "Roman amphitheater", "Umm_Qais", "Wadi_Rum"]Inception_path='./Models/inceptionv3_-saved-model-59-val_accuracy-0.94.hdf5'75 unmodified lines)iface.launch(debug=True, share=True)"""class_labels = ["Ajloun Castle", "Jeresh", "Petra", "Roman amphitheater", "Umm_Qais", "Wadi_Rum"]model_paths = {"InceptionV3": './Models/inceptionv3_-saved-model-59-val_accuracy-0.94.hdf5',"VGGNet": './Models/new_vgg_16.hdf5',"ResNet": './Models/new_resnet50.hdf5',"EfficientNet": './Models/new_efficientnet.h5'}models = {name: load_model(path) for name, path in model_paths.items()}def preprocess_image(image_path):try:image_array = cv2.imread(image_path)image_array = cv2.resize(image_array, (150, 150))image_array = cv2.cvtColor(image_array, cv2.COLOR_BGR2RGB)return np.expand_dims(image_array, axis=0)except Exception as e:raise ValueError(f"Error preprocessing image: {str(e)}")def classify_selected_model(image_path, model_name):try:img = preprocess_image(image_path)all_predictions = {}for model_key, model in models.items():predictions = model.predict(img)class_index = np.argmax(predictions[0])class_name = class_labels[class_index]probability = round(max(predictions[0]) * 100, 2)all_predictions[model_key] = probabilitymin_probability = min(all_predictions.values())if min_probability < 70: # Adjust the threshold as neededreturn None, None, "Can't detect this image. Please try another one."best_model = max(all_predictions, key=all_predictions.get)class_name = class_labels[np.argmax(models[best_model].predict(img)[0])]probability = max(all_predictions.values())result_str = f"{best_model}: {class_name} {probability}%"return class_name, probability, result_strexcept Exception as e:error_message = f"Error: {str(e)}"return None, None, error_messageimage_input = gr.Image(type='filepath', label="Input Image")model_dropdown = gr.Dropdown(["ResNet", "EfficientNet", "VGGNet", "InceptionV3"], label="Select Model")result_textbox = gr.Textbox("Error ", label="Error Message")iface = 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+76