Vwadhwa02 commited on
Commit
7954f1a
·
verified ·
1 Parent(s): 7395194

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -36
app.py CHANGED
@@ -1,36 +1,37 @@
1
- from pathlib import Path
2
- from fastai.vision.all import *
3
- import gradio as gr
4
-
5
- examples = [
6
- ["project/WBC-Benign-017.jpg"], # Replace with the actual paths to your images
7
- ["project/WBC-Benign-030.jpg"],
8
- ["project/WBC-Malignant-Early-027.jpg"],
9
- ["project/WBC-Malignant-Pre-019.jpg"],
10
- ["project/WBC-Malignant-Pro-027.jpg"]
11
- ]
12
- # Correctly format the path for Windows
13
- model_path = Path(r'efficientnet_b3_model.pkl')
14
-
15
- # Load the model
16
- learn = load_learner(model_path, cpu=True)
17
-
18
- # Define the prediction function
19
- def classify_image(image):
20
- pred, idx, probs = learn.predict(image)
21
- return {learn.dls.vocab[i]: float(probs[i]) for i in range(len(probs))}
22
-
23
- # Set up the Gradio interface
24
- interface = gr.Interface(
25
- fn=classify_image,
26
- inputs=gr.Image(type="pil"),
27
- outputs=gr.Label(num_top_classes=3),
28
- title="EfficientNet B3 Image Classifier",
29
- examples= examples,
30
- description="Upload an image to classify using the trained EfficientNet B3 model.",
31
- )
32
-
33
-
34
- # Launch the app
35
- if __name__ == "__main__":
36
- interface.launch(share=True)
 
 
1
+ from pathlib import Path
2
+ from fastai.vision.all import *
3
+ import gradio as gr
4
+
5
+ examples = [
6
+ ["project/WBC-Benign-017.jpg"], # Replace with the actual paths to your images
7
+ ["project/WBC-Benign-030.jpg"],
8
+ ["project/WBC-Malignant-Early-027.jpg"],
9
+ ["project/WBC-Malignant-Pre-019.jpg"],
10
+ ["project/WBC-Malignant-Pro-027.jpg"]
11
+ ]
12
+ # Correctly format the path for Windows
13
+ model_path = Path(r'efficientnet_b3_model.pkl')
14
+
15
+ # Load the model
16
+ learn = load_learner(model_path, cpu=True)
17
+
18
+ # Define the prediction function
19
+ def classify_image(image):
20
+ pred, idx, probs = learn.predict(image)
21
+ return {learn.dls.vocab[i]: float(probs[i]) for i in range(len(probs))}
22
+
23
+ # Set up the Gradio interface
24
+ interface = gr.Interface(
25
+ fn=classify_image,
26
+ inputs=gr.Image(type="pil"),
27
+ outputs=[gr.Label(num_top_classes=3), gr.Textbox(label="Image Name")],
28
+ title="EfficientNet B3 Image Classifier",
29
+ examples= examples,
30
+ description="Upload an image to classify using the trained EfficientNet B3 model.",
31
+
32
+ )
33
+
34
+
35
+ # Launch the app
36
+ if __name__ == "__main__":
37
+ interface.launch(share=True)