Update app.py
Browse files
app.py
CHANGED
@@ -6,6 +6,7 @@ from collections import Counter
|
|
6 |
from ultralytics import YOLO
|
7 |
import plotly.express as px
|
8 |
import plotly.graph_objects as go
|
|
|
9 |
|
10 |
# Load the model
|
11 |
model = YOLO("best.pt")
|
@@ -91,6 +92,13 @@ def process_image(image, conf_threshold=0.25):
|
|
91 |
None
|
92 |
)
|
93 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
# Create Gradio interface with improved layout
|
95 |
with gr.Blocks(theme=gr.themes.Soft()) as app:
|
96 |
gr.Markdown("""
|
@@ -101,6 +109,9 @@ with gr.Blocks(theme=gr.themes.Soft()) as app:
|
|
101 |
with gr.Row():
|
102 |
with gr.Column(scale=1):
|
103 |
input_image = gr.Image(type="numpy", label="Upload Image")
|
|
|
|
|
|
|
104 |
conf_slider = gr.Slider(
|
105 |
minimum=0.1,
|
106 |
maximum=1.0,
|
@@ -109,7 +120,6 @@ with gr.Blocks(theme=gr.themes.Soft()) as app:
|
|
109 |
label="Confidence Threshold",
|
110 |
info="Adjust detection sensitivity"
|
111 |
)
|
112 |
-
analyze_btn = gr.Button("Analyze Image", variant="primary")
|
113 |
|
114 |
with gr.Column(scale=1):
|
115 |
output_image = gr.Image(type="numpy", label="Detected Cells")
|
@@ -128,7 +138,12 @@ with gr.Blocks(theme=gr.themes.Soft()) as app:
|
|
128 |
with gr.Column(scale=1):
|
129 |
density_plot = gr.Plot(label="Cell Density Heatmap")
|
130 |
|
131 |
-
# Handle button
|
|
|
|
|
|
|
|
|
|
|
132 |
analyze_btn.click(
|
133 |
process_image,
|
134 |
inputs=[input_image, conf_slider],
|
@@ -137,7 +152,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as app:
|
|
137 |
|
138 |
gr.Markdown("""
|
139 |
### Instructions:
|
140 |
-
1. Upload a microscopy image containing cells
|
141 |
2. Adjust the confidence threshold if needed (higher values = stricter detection)
|
142 |
3. Click 'Analyze Image' to process
|
143 |
4. View results in the various panels:
|
|
|
6 |
from ultralytics import YOLO
|
7 |
import plotly.express as px
|
8 |
import plotly.graph_objects as go
|
9 |
+
import os
|
10 |
|
11 |
# Load the model
|
12 |
model = YOLO("best.pt")
|
|
|
92 |
None
|
93 |
)
|
94 |
|
95 |
+
def load_example_image():
|
96 |
+
"""Load the example test image"""
|
97 |
+
example_image = cv2.imread("test.png")
|
98 |
+
if example_image is None:
|
99 |
+
return None
|
100 |
+
return example_image
|
101 |
+
|
102 |
# Create Gradio interface with improved layout
|
103 |
with gr.Blocks(theme=gr.themes.Soft()) as app:
|
104 |
gr.Markdown("""
|
|
|
109 |
with gr.Row():
|
110 |
with gr.Column(scale=1):
|
111 |
input_image = gr.Image(type="numpy", label="Upload Image")
|
112 |
+
with gr.Row():
|
113 |
+
example_btn = gr.Button("Try Example Image")
|
114 |
+
analyze_btn = gr.Button("Analyze Image", variant="primary")
|
115 |
conf_slider = gr.Slider(
|
116 |
minimum=0.1,
|
117 |
maximum=1.0,
|
|
|
120 |
label="Confidence Threshold",
|
121 |
info="Adjust detection sensitivity"
|
122 |
)
|
|
|
123 |
|
124 |
with gr.Column(scale=1):
|
125 |
output_image = gr.Image(type="numpy", label="Detected Cells")
|
|
|
138 |
with gr.Column(scale=1):
|
139 |
density_plot = gr.Plot(label="Cell Density Heatmap")
|
140 |
|
141 |
+
# Handle button clicks
|
142 |
+
example_btn.click(
|
143 |
+
load_example_image,
|
144 |
+
outputs=input_image
|
145 |
+
)
|
146 |
+
|
147 |
analyze_btn.click(
|
148 |
process_image,
|
149 |
inputs=[input_image, conf_slider],
|
|
|
152 |
|
153 |
gr.Markdown("""
|
154 |
### Instructions:
|
155 |
+
1. Upload a microscopy image containing cells or click 'Try Example Image'
|
156 |
2. Adjust the confidence threshold if needed (higher values = stricter detection)
|
157 |
3. Click 'Analyze Image' to process
|
158 |
4. View results in the various panels:
|