Spaces:
Runtime error
Runtime error
Update app.py
Browse files123426 unmodified lines31323334353637383940414243444546476 unmodified lines5455565758596061import onnxruntime as ortimport numpy as npimport gradio as grimport cv226 unmodified linesif model is None:return {"Error": f"Model {model_choice} not found"}img_preprocessed = preprocess_input(img)onnx_file=onnx.load(model)input_name = model.get_inputs()[0].nameoutput_name= model.get_output()[0].nametry:predictions = model.run(None, {input_name: img_preprocessed})class_idx = np.argmax(predictions[0][0])class_name = class_names[class_idx]confidence_score = round(predictions[0, class_idx] * 100, 2)result = {"Predicted class": class_name,"Confidence Score": confidence_score }except Exception as e:result = {"Error": str(e)}6 unmodified linesfn=classify_image,inputs=[image_input, gr.Dropdown(["InceptionV3", "VGGNet", "ResNet", "EfficientNet"], label="Select Model")],outputs="label",title= 'Image Classification',live=True)iface.launch(share=True,debug=True)1234526 unmodified lines3233343536373839404142434445464748495051525354556 unmodified lines6263646566676869import onnxruntime as ortimport onnximport numpy as npimport gradio as grimport cv226 unmodified linesif model is None:return {"Error": f"Model {model_choice} not found"}# Check if the input is a Gradio Image objectif isinstance(img, gr.Image):# Get the image file path from the Gradio Image objectimg_path = img.filepathelse:# Assume the input is already a file pathimg_path = imgimg_preprocessed = preprocess_input(img_path)input_name = model.get_inputs()[0].nameoutput_name = model.get_outputs()[0].nametry:predictions = model.run(None, {input_name: img_preprocessed})class_idx = np.argmax(predictions[0][0])class_name = class_names[class_idx]confidence_score = round(predictions[0, class_idx] * 100, 2)result = {"Predicted class": class_name, "Confidence Score": confidence_score}except Exception as e:result = {"Error": str(e)}6 unmodified linesfn=classify_image,inputs=[image_input, gr.Dropdown(["InceptionV3", "VGGNet", "ResNet", "EfficientNet"], label="Select Model")],outputs="label",title='Image Classification',live=True)iface.launch(share=True, debug=True)
app.py+14-6