Spaces:
Runtime error
Runtime error
Update app.py
Browse files12 unmodified lines131415161718194 unmodified lines242526272829305 unmodified lines3637383940414243444546474849505152535455565758596061626312 unmodified linesInception_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):4 unmodified linesimg = 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":5 unmodified linesclass_name = class_folders[class_index]probability = max(predictions[0])return {"class_name": class_name, "probability": probability}except Exception as e:return {"error": str(e)}# Create Gradio interface# iface = gr.Interface(# fn=classify_selected_model,# inputs=["image", gr.Dropdown(["ResNet", "EfficientNet", "VGGNet", "InceptionV3"], label="Select Model")],# outputs="text",# live=True# )# # Launch the Gradio interface and deploy on Gradio's public sharing service# iface.launch(share=True)image_input = gr.Image(type='filepath', label="Input Image")model_dropdown = gr.Dropdown(["ResNet", "EfficientNet", "VGGNet", "InceptionV3"], label="Select Model")gr.Interface(fn=classify_selected_model,inputs=[image_input, model_dropdown],outputs="json",live=True).launch(debug=True,share=True)12 unmodified lines131415161718194 unmodified lines242526272829305 unmodified lines363738394041424344454647484950515253545512 unmodified linesInception_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):4 unmodified linesimg = 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":5 unmodified linesclass_name = class_folders[class_index]probability = max(predictions[0])return class_name, probability # Return two separate valuesexcept Exception as e:return str(e), None # Return an error message and None for probability# Create Gradio interfaceimage_input = gr.Image(type='filepath', label="Input Image")model_dropdown = gr.Dropdown(["ResNet", "EfficientNet", "VGGNet", "InceptionV3"], label="Select Model")iface = gr.Interface(fn=classify_selected_model,inputs=[image_input, model_dropdown],outputs=["text", "number"], # Define separate outputs for class_name and probabilitylive=True)iface.launch(debug=True, share=True)
app.py+11-19