Spaces:
Runtime error
Runtime error
Update app.py
Browse files2 unmodified lines345678910111213141 unmodified line161718192021222324252627282930313233343536373811 unmodified lines50515253545556575859606162636465666768697071727374757677787980818283848586878889902 unmodified linesimport numpy as npfrom tensorflow.keras.models import load_modelclass_folders = ["Ajloun Castle", "Jerash", "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_model = load_model(Inception_path)VGGNet_model = load_model(VGGNet_path)1 unmodified lineEfficient_model = load_model(EfficientNet_path)def links_info(class_name):links_dict = {"Ajloun Castle": "https://ar.tripadvisor.com/Attraction_Review-g293988-d1549575-Reviews-Ajloun_Castle-Jerash_Jerash_Governorate.html","Jerash": "https://ar.tripadvisor.com/Tourism-g293988-Jerash_Jerash_Governorate-Vacations.html","Petra": "https://ar.tripadvisor.com/Tourism-g318895-Petra_Wadi_Musa_Ma_an_Governorate-Vacations.html","Roman amphitheater": "https://ar.tripadvisor.com/Attraction_Review-g295398-d553291-Reviews-Ancient_Roman_Amphitheater-Alexandria_Alexandria_Governorate.html","Umm Qais": "https://ar.tripadvisor.com/Tourism-g318874-Umm_Qais_Irbid_Governorate-Vacations.html","Wadi Rum": "https://ar.tripadvisor.com/Tourism-g303973-Wadi_Rum_Al_Aqabah_Governorate-Vacations.html"}return links_dict.get(class_name, "")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)11 unmodified linesclass_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)links = links_info(class_name)return class_name, model_name, probability, linksexcept Exception as e:error_message = f"Error: {str(e)}"return None, None, None, Noneimage_input = gr.Image(type='filepath', label="Input Image")model_dropdown = gr.Dropdown(["ResNet", "EfficientNet", "VGGNet", "InceptionV3"], label="Select Model")info_html = gr.HTML(label="Tripadvisor website")result_textbox = gr.Textbox("Results", label="History Results")iface = gr.Interface(fn=classify_selected_model,inputs=[image_input, model_dropdown],outputs=[gr.Label(value="Archaeological Site"),info_html,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 lines345678910111213141516171 unmodified line19202122232425262728293031323334353637383940414243444511 unmodified lines575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121132 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'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)1 unmodified lineEfficient_model = load_model(EfficientNet_path)def links_info(class_name):if class_name == "Ajloun Castle":link = "https://ar.tripadvisor.com/Attraction_Review-g293988-d1549575-Reviews-Ajloun_Castle-Jerash_Jerash_Governorate.html"elif class_name == "Jerash":link ="https://ar.tripadvisor.com/Tourism-g293988-Jerash_Jerash_Governorate-Vacations.html"elif class_name == "Petra":link ="https://ar.tripadvisor.com/Tourism-g318895-Petra_Wadi_Musa_Ma_an_Governorate-Vacations.html"elif class_name == "Roman amphitheater":link ="https://ar.tripadvisor.com/Attraction_Review-g295398-d553291-Reviews-Ancient_Roman_Amphitheater-Alexandria_Alexandria_Governorate.html"elif class_name == "Umm Qais":link = "https://ar.tripadvisor.com/Tourism-g318874-Umm_Qais_Irbid_Governorate-Vacations.html"elif class_name == "Wadi Rum":link = "https://ar.tripadvisor.com/Tourism-g303973-Wadi_Rum_Al_Aqabah_Governorate-Vacations.html"return linkhistory=[]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)11 unmodified linesclass_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)links = links_info(class_name)return class_name ,model_name , prediction , linksexcept Exception as e:error_message = f"Error: {str(e)}"return None, None, None,Noneinfo_html = f'''<!DOCTYPE html><html><body><h1></h1><ul><li><a href="{links[0]}" target="_blank">{links[0]}</a></li></ul></body></html>'''image_input = gr.Image(type='filepath', label="Input Image")model_dropdown = gr.Dropdown(["ResNet", "EfficientNet", "VGGNet", "InceptionV3"], label="Select Model")info_html=gr.HTML(label="Tripadvisor website")result_textbox = gr.Textbox("Results", label="history Results")iface = gr.Interface(fn=classify_selected_model,inputs=[image_input, model_dropdown ],outputs=[gr.Label(value="Archaeological Site"),info_html,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"]] ,#,gr.Text(["Ajloun","Jeresh","Umm Qais","Petra","Roman Amphitheater","Wadi Rum"] )live=True,title="Image Classification for Archaeological Sites Interface",)iface.launch(debug=True, share=True )
app.py+57-34