from pathlib import Path from fastai.vision.all import * import gradio as gr examples = [ ["project/WBC-Benign-017.jpg"], # Replace with the actual paths to your images ["project/WBC-Benign-030.jpg"], ["project/WBC-Malignant-Early-027.jpg"], ["project/WBC-Malignant-Pre-019.jpg"], ["project/WBC-Malignant-Pro-027.jpg"] ] # Correctly format the path for Windows model_path = Path(r'efficientnet_b3_model.pkl') # Load the model learn = load_learner(model_path, cpu=True) # Define the prediction function def classify_image(image): pred, idx, probs = learn.predict(image) return {learn.dls.vocab[i]: float(probs[i]) for i in range(len(probs))} # Set up the Gradio interface interface = gr.Interface( fn=classify_image, inputs=gr.Image(type="pil"), outputs=gr.Label(num_top_classes=3), title="EfficientNet B3 Image Classifier", examples= examples, description="Upload an image to classify using the trained EfficientNet B3 model.", ) # Launch the app if __name__ == "__main__": interface.launch(share=True)