added example images
Browse files
app.py
CHANGED
@@ -1,12 +1,15 @@
|
|
1 |
import gradio as gr
|
2 |
from ultralytics import YOLO
|
|
|
3 |
|
|
|
4 |
format = { 0: 'Bengin case',
|
5 |
1: 'Bengin case Malignant case',
|
6 |
2: 'Malignant case',
|
7 |
3: 'Malignant case Normal case',
|
8 |
4: 'Normal case'}
|
9 |
|
|
|
10 |
def image_classifier(inp):
|
11 |
model = YOLO("best.pt")
|
12 |
|
@@ -14,10 +17,25 @@ def image_classifier(inp):
|
|
14 |
probs = result[0].probs
|
15 |
max_tensor = max(probs)
|
16 |
tensor_pos = ((probs == max_tensor).nonzero(as_tuple=True)[0])
|
17 |
-
|
18 |
return format.get(int(tensor_pos))
|
19 |
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
|
|
|
1 |
import gradio as gr
|
2 |
from ultralytics import YOLO
|
3 |
+
import os
|
4 |
|
5 |
+
# catgories
|
6 |
format = { 0: 'Bengin case',
|
7 |
1: 'Bengin case Malignant case',
|
8 |
2: 'Malignant case',
|
9 |
3: 'Malignant case Normal case',
|
10 |
4: 'Normal case'}
|
11 |
|
12 |
+
# returning classifiers output
|
13 |
def image_classifier(inp):
|
14 |
model = YOLO("best.pt")
|
15 |
|
|
|
17 |
probs = result[0].probs
|
18 |
max_tensor = max(probs)
|
19 |
tensor_pos = ((probs == max_tensor).nonzero(as_tuple=True)[0])
|
20 |
+
|
21 |
return format.get(int(tensor_pos))
|
22 |
|
23 |
+
# gradio code block for input and output
|
24 |
+
with gr.Blocks() as app:
|
25 |
+
gr.Markdown("## Lung Cancer classification using Yolov8")
|
26 |
+
with gr.Row():
|
27 |
+
inp_img = gr.Image()
|
28 |
+
out_txt = gr.Textbox()
|
29 |
+
btn = gr.Button(value="Submit")
|
30 |
+
btn.click(image_classifier, inputs=inp_img, outputs=out_txt)
|
31 |
|
32 |
+
gr.Markdown("## Image Examples")
|
33 |
+
gr.Examples(
|
34 |
+
examples=[os.path.join(os.path.dirname(__file__), "1.jpg"), os.path.join(os.path.dirname(__file__), "2.jpg")],
|
35 |
+
inputs=inp_img,
|
36 |
+
outputs=out_txt,
|
37 |
+
fn=image_classifier,
|
38 |
+
cache_examples=True,
|
39 |
+
)
|
40 |
|
41 |
+
app.launch(share=True)
|