Spaces:
Runtime error
Runtime error
Update app.py
Browse files12345678910111213141516172 unmodified lines2021222324252627282930313213 unmodified lines4647484950import gradio as grimport cv2import numpy as npfrom tensorflow.keras.models import load_model# Load HDF5 modelsresnet_model = load_model('/content/drive/MyDrive/best_model/resnet50-saved-model-79-val_acc-1.00.hdf5')efficientnet_model = load_model('/content/drive/MyDrive/best_model/efficientnet-saved-model-06-val_acc-0.98.hdf5')vggnet_model = load_model('/content/drive/MyDrive/Saved Model/vgg_16_-saved-model-89-acc-0.93.hdf5')inceptionv3_model = load_model('/content/drive/MyDrive/best_model/vgg_16_-saved-model-89-acc-0.93.hdf5')# Define class names corresponding to your datasetclass_names = ["Ajloun Castle", "Jeresh", "Petra", "Roman amphitheater", "Umm_Qais", "Wadi_Rum"] # Replace with your actual class names# Define the classify_image functiondef classify_image(img, model_choice):try:2 unmodified linesimg = img.astype(np.float32) / 255.0if model_choice == "ResNet":predictions = resnet_model.predict(img)elif model_choice == "EfficientNet":predictions = efficientnet_model.predict(img)elif model_choice == "VGGNet":predictions = vggnet_model.predict(img)elif model_choice == "InceptionV3":predictions = inceptionv3_model.predict(img)else:return "Invalid model choice"13 unmodified lineslive=True)# Launch the Gradio interface and deploy on Gradio's public sharing serviceiface.launch(share=True)1234567891011121314151617181920212223242 unmodified lines272829303132333435363738394041424313 unmodified lines5758596061import gradio as grimport cv2import numpy as npfrom transformers import TFAutoModelForImageClassification, AutoTokenizer# Define class names corresponding to your datasetclass_names = ["Ajloun Castle", "Jeresh", "Petra", "Roman amphitheater", "Umm_Qais", "Wadi_Rum"] # Replace with your actual class names# Define the Hugging Face Model Hub names for your modelsresnet_model_name = './resnet50-saved-model-79-val_acc-1.00.hdf5'efficientnet_model_name = './efficientnet-saved-model-06-val_acc-0.98.hdf5'vggnet_model_name = './vgg_16_-saved-model-89-acc-0.93.hdf5'inceptionv3_model_name = './inceptionv3_-saved-model-59-val_accuracy-0.94.hdf5'# Load models from Hugging Face Model Hubtokenizer = AutoTokenizer.from_pretrainedresnet_model = TFAutoModelForImageClassification.from_pretrained(resnet_model_name)efficientnet_model = TFAutoModelForImageClassification.from_pretrained(efficientnet_model_name)vggnet_model = TFAutoModelForImageClassification.from_pretrained(vggnet_model_name)inceptionv3_model = TFAutoModelForImageClassification.from_pretrained(inceptionv3_model_name)# Define the classify_image functiondef classify_image(img, model_choice):try:2 unmodified linesimg = img.astype(np.float32) / 255.0if model_choice == "ResNet":inputs = tokenizer(images=img, return_tensors="tf")predictions = resnet_model(**inputs).logitselif model_choice == "EfficientNet":inputs = tokenizer(images=img, return_tensors="tf")predictions = efficientnet_model(**inputs).logitselif model_choice == "VGGNet":inputs = tokenizer(images=img, return_tensors="tf")predictions = vggnet_model(**inputs).logitselif model_choice == "InceptionV3":inputs = tokenizer(images=img, return_tensors="tf")predictions = inceptionv3_model(**inputs).logitselse:return "Invalid model choice"13 unmodified lineslive=True)# Launch the Gradio interfaceiface.launch()
app.py+24-13