Spaces:
Runtime error
Runtime error
Update app.py
Browse files10 unmodified lines11121314151617181920212223242526272829303132333435363738394041424344454647484950511 unmodified line5354555657585910 unmodified linesResNet_path= './inceptionv3_-saved-model-59-val_accuracy-0.94.hdf5'EfficientNet_path= './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)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)img = np.expand_dims(img, axis=0)#img = 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)#keras_model = load_model(model_paths[model_name])#predictions = keras_model.predict(img)class_index = np.argmax(predictions[0])class_name = class_folders[class_index]#probability = max(predictions[0])# print(f'Predicted class index: {class_index}')# print(f'Predicted class name: {class_name}')# print(f'Probability: {probability}')return {"class_name": class_name, "probability": probability}1 unmodified linereturn {"error": str(e)}# Create Gradio interface# Create a Gradio interface with a dropdown for model selectioniface = gr.Interface(fn=classify_selected_model,inputs=["image", gr.Dropdown(["ResNet", "EfficientNet", "VGGNet", "InceptionV3"], label="Select Model")],10 unmodified lines1112131415161718192021222324252627282930313233343536373839401 unmodified line42434445464710 unmodified linesResNet_path= './inceptionv3_-saved-model-59-val_accuracy-0.94.hdf5'EfficientNet_path= './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)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)img = np.expand_dims(img, axis=0)if model_name == "ResNet":predictions = REsNet_model.predict(img)elif model_name == "EfficientNet":predictions = Efficient_model.predict(img)elif model_name == "VGGNet":predictions = VGGNet_model.predict(img)elif model_name == "InceptionV3":predictions = Inception_model.predict(img)class_index = np.argmax(predictions[0])class_name = class_folders[class_index]probability = max(predictions[0])return {"class_name": class_name, "probability": probability}1 unmodified linereturn {"error": str(e)}# Create Gradio interfaceiface = gr.Interface(fn=classify_selected_model,inputs=["image", gr.Dropdown(["ResNet", "EfficientNet", "VGGNet", "InceptionV3"], label="Select Model")],
app.py+13-25