File size: 1,066 Bytes
e2a1281
 
 
 
e98cceb
e2324bd
 
 
 
 
e98cceb
e2a1281
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1d0c7f1
e2a1281
e98cceb
 
e2a1281
 
2ec730e
e2a1281
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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)