import gradio as gr from fastcore.all import * from fastai.vision.all import * from pathlib import Path plt = platform.system() if plt == 'Linux': pathlib.WindowsPath = pathlib.PosixPath def classify_image(img): learn = load_learner(str(Path('./nihal_model.pkl'))) 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()