import gradio as gr from fastai.vision.all import * import pathlib plt = platform.system() if plt == 'Linux': pathlib.WindowsPath = pathlib.PosixPath learn = load_learner('nihal_model.pkl') def classify_image(img): pred,pred_idx,probs = learn.predict(img) #return both the prediction and the probability either nihal or not and format in perccentage return pred, "{:.0%}".format(float(probs[pred_idx])),float(probs[~pred_idx]) #return f'Prediction: {pred}; Probability: {probs[pred_idx]:.04f}' if __name__ == '__main__': # Define inputs and outputs for Gradio interface inputs = [gr.Image(type="pil", label="Select an image of Nihal")] outputs = [ gr.Label(""), gr.Label(label="Confidence"), ] # Launch the Gradio interface interface = gr.Interface(fn=classify_image, inputs=inputs, outputs=outputs) interface.launch()