Spaces:
Runtime error
Runtime error
Update app.py
Browse files2 unmodified lines34567813 unmodified lines222324252627282930313233343536373839404142435 unmodified lines4950515253545556574 unmodified lines6263646566676869707172737475762 unmodified linesimport cv2import gradio as grimport tensorflow as tfos.environ['TF_ENABLE_ONEDNN_OPTS'] = '0'inception_model_path = './inceptionv3_-saved-model-97-loss-0.00.hdf5'13 unmodified linesdef classify_image(img, model_choice):# Resize the input image based on the selected model's expected input shapeif model_choice == "ResNet":img = tf.image.resize(img, (150, 150)) # ResNet50 input sizeimg = image.img_to_array(img)img = img.copy() # Make a copy of the image arrayimg = resnet_preprocess_input(img)elif model_choice == "EfficientNet":img = tf.image.resize(img, (150, 150))img = image.img_to_array(img)img = preprocess_input(img)elif model_choice == "VGGNet":img = tf.image.resize(img, (150, 150))img = image.img_to_array(img)img = preprocess_input(img)elif model_choice == "InceptionV3":img = tf.image.resize(img, (150, 150))img = image.img_to_array(img)img = preprocess_input(img)else:return "Invalid model choice"5 unmodified lineselif 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)class_idx = tf.argmax(predictions[0])4 unmodified linesreturn f"Predicted class using {model_choice}: {class_name}"image_input = gr.Image()# Create a Gradio interface with a dropdown for model selectioniface = gr.Interface(fn=classify_image,inputs=[image_input, gr.Dropdown(["ResNet", "EfficientNet","VGGNet","InceptionV3"], label="Select Model")],outputs="text",live=True).launch(debug=True)2 unmodified lines34567891011121313 unmodified lines27282930313233343536373839404142435 unmodified lines4950515253545556574 unmodified lines6263646566676869707172732 unmodified linesimport cv2import gradio as grimport tensorflow as tffrom tensorflow.keras.applications.inception_v3 import InceptionV3, preprocess_input as inception_preprocess_inputfrom tensorflow.keras.applications.vgg16 import VGG16, preprocess_input as vgg_preprocess_inputfrom tensorflow.keras.applications.resnet50 import ResNet50, preprocess_input as resnet_preprocess_inputfrom tensorflow.keras.applications.efficientnet import EfficientNetB0, preprocess_input as efficientnet_preprocess_inputos.environ['TF_ENABLE_ONEDNN_OPTS'] = '0'inception_model_path = './inceptionv3_-saved-model-97-loss-0.00.hdf5'13 unmodified linesdef classify_image(img, model_choice):# Resize the input image based on the selected model's expected input shapeif model_choice == "ResNet":img = tf.image.resize(img, (224, 224)) # ResNet50 input sizeimg = resnet_preprocess_input(img)elif model_choice == "EfficientNet":img = tf.image.resize(img, (224, 224))img = efficientnet_preprocess_input(img)elif model_choice == "VGGNet":img = tf.image.resize(img, (224, 224))img = vgg_preprocess_input(img)elif model_choice == "InceptionV3":img = tf.image.resize(img, (299, 299)) # InceptionV3 input sizeimg = inception_preprocess_input(img)else:return "Invalid model choice"5 unmodified lineselif model_choice == "EfficientNet":predictions = efficientnet_model.predict(img)elif model_choice == "VGGNet":predictions = vggnet_model.predict(img)elif model_choice == "InceptionV3":predictions = inception_model.predict(img)class_idx = tf.argmax(predictions[0])4 unmodified linesreturn f"Predicted class using {model_choice}: {class_name}"image_input = gr.Image()# Create a Gradio interface with a dropdown for model selectioniface = gr.Interface(fn=classify_image,inputs=[image_input, gr.Dropdown(["ResNet", "EfficientNet", "VGGNet", "InceptionV3"], label="Select Model")],outputs="text",live=True).launch(debug=True)
app.py+16-19