Spaces:
Runtime error
Runtime error
Update app.py
Browse files2 unmodified lines34567891011121313 unmodified lines27282925262730313230313233343534353636373838394039404142435 unmodified lines49505152525354545556574 unmodified lines62636465656667686971707172747576732 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_input
os.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 shape if model_choice == "ResNet": img = tf.image.resize(img, (150, 150)) # ResNet50 input size img = image.img_to_array(img) img = img.copy() # Make a copy of the image array img = tf.image.resize(img, (224, 224)) # ResNet50 input size img = 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) img = tf.image.resize(img, (224, 224)) img = efficientnet_preprocess_input(img) elif model_choice == "VGGNet": img = tf.image.resize(img, (150, 150)) img = image.img_to_array(img) img = preprocess_input(img) img = tf.image.resize(img, (224, 224)) img = vgg_preprocess_input(img) elif model_choice == "InceptionV3": img = tf.image.resize(img, (150, 150)) img = image.img_to_array(img) img = preprocess_input(img) img = tf.image.resize(img, (299, 299)) # InceptionV3 input size img = inception_preprocess_input(img) else: return "Invalid model choice"
5 unmodified lines elif model_choice == "EfficientNet": predictions = efficientnet_model.predict(img) elif model_choice == "VGGNet": predictions = VGGNet_model.predict(img) predictions = vggnet_model.predict(img) elif model_choice == "InceptionV3": predictions = InceptionV3_model.predict(img) predictions = inception_model.predict(img)
class_idx = tf.argmax(predictions[0])
4 unmodified lines return 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")], inputs=[image_input, gr.Dropdown(["ResNet", "EfficientNet", "VGGNet", "InceptionV3"], label="Select Model")], outputs="text", live=True)
.launch(debug=True)).launch(debug=True)app.py+16-19