Spaces:
Runtime error
Runtime error
Update app.py
Browse files12345678910111213141516171819202122233 unmodified lines2728293031323334353637383940414243import gradio as grimport cv2import numpy as npfrom transformers import TFAutoModelForImageClassification, AutoTokenizer# Define class names corresponding to your datasetsclass_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):3 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"12345678910111213141516171819202122232425263 unmodified lines30313233343536373839404142import gradio as grimport cv2import numpy as npfrom tensorflow.keras.models import load_modelfrom transformers import AutoTokenizer# Define class names corresponding to your datasetsclass_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_path = './resnet50-saved-model-79-val_acc-1.00.hdf5'efficientnet_model_path = './efficientnet-saved-model-06-val_acc-0.98.hdf5'vggnet_model_path = './vgg_16_-saved-model-89-acc-0.93.hdf5'inceptionv3_model_path = './inceptionv3_-saved-model-59-val_accuracy-0.94.hdf5'# Load modelsresnet_model = load_model(resnet_model_path)efficientnet_model = load_model(efficientnet_model_path)vggnet_model = load_model(vggnet_model_path)inceptionv3_model = load_model(inceptionv3_model_path)# Define the tokenizertokenizer = AutoTokenizer.from_pretrained("YOUR_TRANSFORMER_MODEL_NAME") # Replace with the actual transformer model name# Define the classify_image functiondef classify_image(img, model_choice):3 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"
app.py+19-20