Spaces:
Runtime error
Runtime error
Update app.py
Browse files1234526 unmodified lines323334343535363738394041424344374546474849505144525354556 unmodified lines62636457656667686169import onnxruntime as ortimport onnximport numpy as npimport gradio as grimport cv226 unmodified lines if model is None: return {"Error": f"Model {model_choice} not found"}
img_preprocessed = preprocess_input(img) onnx_file=onnx.load(model) # Check if the input is a Gradio Image object if isinstance(img, gr.Image): # Get the image file path from the Gradio Image object img_path = img.filepath else: # Assume the input is already a file path img_path = img
img_preprocessed = preprocess_input(img_path) input_name = model.get_inputs()[0].name output_name= model.get_output()[0].name output_name = model.get_outputs()[0].name try: 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 } result = {"Predicted class": class_name, "Confidence Score": confidence_score} except Exception as e: result = {"Error": str(e)}
6 unmodified lines fn=classify_image, inputs=[image_input, gr.Dropdown(["InceptionV3", "VGGNet", "ResNet", "EfficientNet"], label="Select Model")], outputs="label", title= 'Image Classification', title='Image Classification', live=True)
iface.launch(share=True,debug=True)iface.launch(share=True, debug=True)app.py+14-6