Spaces:
Runtime error
Runtime error
Update app.py
Browse files4 unmodified lines567891011121314151619 unmodified lines36373839404142434445464748495051525354555657585960611 unmodified line6364656667684 unmodified linesimport onnxruntime as ortonnx_efficientnet_path = './Models_onnx/efficientnet.onnx'#onnx_inception_path = './Models_onnx/inceptionv3.onnx'onnx_vggnet_path = './Models_onnx/vgg_16.onnx'onnx_resnet_path = './Models_onnx/resnet50.onnx'# Uncomment or remove the following line based on your needs#onnx_inception_model = ort.InferenceSession(onnx_inception_path)onnx_vggnet_model = ort.InferenceSession(onnx_vggnet_path)onnx_resnet_model = ort.InferenceSession(onnx_resnet_path)onnx_efficientnet_model = ort.InferenceSession(onnx_efficientnet_path)19 unmodified lines"ResNet": onnx_resnet_model,"EfficientNet": onnx_efficientnet_model,"VGGNet": onnx_vggnet_model,#"InceptionV3": onnx_inception_model # Uncomment or remove based on your needs}[model_choice]predictions = model.run(None, {"input": img_preprocessed})class_idx = np.argmax(predictions)class_name = class_names[class_idx]# Get the top 3 predictionstop_predictions = sorted(enumerate(predictions[0]), key=lambda x: x[1], reverse=True)[:3]top_classes = [class_names[idx] for idx, _ in top_predictions]top_probs = [round(prob * 100, 2) for _, prob in top_predictions]return {"Original Image": img,"Resized Image": img_resized,"Predicted class using {}: {}".format:(model_choice, class_name),"Top 3 Predictions": list(zip(top_classes, top_probs)),"Confidence Scores": predictions[0]}image_input = gr.Image()1 unmodified lineiface = gr.Interface(fn=classify_image,inputs=[image_input, gr.Dropdown(["ResNet", "EfficientNet", "VGGNet", "InceptionV3"], label="Select Model")],outputs=["image", "image", "text", "text", "text"],live=True).launch(debug=True)4 unmodified lines567891011121314151619 unmodified lines3637383940414243444546474849505152535455565758596061626364651 unmodified line6768697071724 unmodified linesimport onnxruntime as ortonnx_efficientnet_path = './Models_onnx/efficientnet.onnx'# onnx_inception_path = './Models_onnx/inceptionv3.onnx'onnx_vggnet_path = './Models_onnx/vgg_16.onnx'onnx_resnet_path = './Models_onnx/resnet50.onnx'# Uncomment or remove the following line based on your needs# onnx_inception_model = ort.InferenceSession(onnx_inception_path)onnx_vggnet_model = ort.InferenceSession(onnx_vggnet_path)onnx_resnet_model = ort.InferenceSession(onnx_resnet_path)onnx_efficientnet_model = ort.InferenceSession(onnx_efficientnet_path)19 unmodified lines"ResNet": onnx_resnet_model,"EfficientNet": onnx_efficientnet_model,"VGGNet": onnx_vggnet_model,# "InceptionV3": onnx_inception_model # Uncomment or remove based on your needs}[model_choice]try:predictions = model.run(None, {"input": img_preprocessed})class_idx = np.argmax(predictions)class_name = class_names[class_idx]# Get the top 3 predictionstop_predictions = sorted(enumerate(predictions[0]), key=lambda x: x[1], reverse=True)[:3]top_classes = [class_names[idx] for idx, _ in top_predictions]top_probs = [round(prob * 100, 2) for _, prob in top_predictions]result = {"Original Image": img.tolist(), # Convert to list for compatibility with Gradio"Resized Image": img_resized.tolist(),f"Predicted class using {model_choice}": class_name,"Top 3 Predictions": list(zip(top_classes, top_probs)),"Confidence Scores": predictions[0].tolist()}except Exception as e:result = {"Error": str(e)}return resultimage_input = gr.Image()1 unmodified lineiface = gr.Interface(fn=classify_image,inputs=[image_input, gr.Dropdown(["ResNet", "EfficientNet", "VGGNet", "InceptionV3"], label="Select Model")],outputs=["json"],live=True).launch(debug=True)
app.py+23-19