import gradio as gr from fastai.vision.all import * import os # list all file names in the samples directory examples = [] for file in os.listdir('samples'): examples.append(['samples/' + file]) categories = ['Jazzmaster', 'Stratocaster', 'Telecaster'] image = gr.inputs.Image(shape=(192, 192)) label = gr.outputs.Label() # Load the trained model from the model.pkl file model = load_learner('model.pkl') def predict(image): # image = cv2.resize(image, (224, 224)) # image = np.expand_dims(image, axis=0) prediction, idx, probabilities = model.predict(image) return dict(zip(categories, map(float, probabilities))) iface = gr.Interface(fn=predict, inputs=image, outputs=label, examples=examples, capture_session=True) iface.launch()