Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,17 +12,18 @@ from utils.measure_utils import ContourAnalyzer
|
|
| 12 |
from PIL import Image
|
| 13 |
import utils.plot as pt
|
| 14 |
|
| 15 |
-
|
| 16 |
-
# Clear any previous data and configurations
|
| 17 |
-
clear_all()
|
| 18 |
-
model = YOLO('./weights/best.pt')
|
| 19 |
-
# Define the color scheme/theme for the website
|
| 20 |
theme = gr.themes.Soft(
|
| 21 |
primary_hue="orange",
|
| 22 |
).set(
|
| 23 |
body_background_fill='*primary_50',
|
| 24 |
block_background_fill='*neutral_50'
|
| 25 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
#Custom css for styling
|
| 27 |
css = """
|
| 28 |
.size {
|
|
@@ -178,7 +179,7 @@ with gr.Blocks(theme=theme, css=css) as demo:
|
|
| 178 |
return np.array(input_image)
|
| 179 |
|
| 180 |
|
| 181 |
-
def predict_segmentation_im(image, conf, reference, remark):
|
| 182 |
"""
|
| 183 |
Perform segmentation prediction on a list of images.
|
| 184 |
|
|
@@ -258,7 +259,7 @@ with gr.Blocks(theme=theme, css=css) as demo:
|
|
| 258 |
contour_analyzer.draw_circle_on_image(visualized_image, (int(thickest_points[0]), int(thickest_points[1])), 5, (57, 255, 20), -1)
|
| 259 |
print("Max Width in pixels: ", max_width)
|
| 260 |
|
| 261 |
-
width = contour_analyzer.calculate_width(y=
|
| 262 |
print("Max Width, converted: ", width)
|
| 263 |
|
| 264 |
prets = pt.classify_wall_damage(width)
|
|
@@ -300,7 +301,7 @@ with gr.Blocks(theme=theme, css=css) as demo:
|
|
| 300 |
# Connect the buttons to the prediction function and clear function
|
| 301 |
image_button.click(
|
| 302 |
predict_segmentation_im,
|
| 303 |
-
inputs=[image_input, conf, image_reference, image_remark],
|
| 304 |
outputs=[image_output, csv_image, df_image, md_result]
|
| 305 |
)
|
| 306 |
|
|
@@ -313,9 +314,10 @@ with gr.Blocks(theme=theme, css=css) as demo:
|
|
| 313 |
gr.DataFrame(visible=False),
|
| 314 |
gr.Slider(value=20),
|
| 315 |
None,
|
| 316 |
-
None
|
|
|
|
| 317 |
],
|
| 318 |
-
outputs=[image_input, image_output, md_result, csv_image, df_image, conf, image_reference, image_remark]
|
| 319 |
)
|
| 320 |
|
| 321 |
# Launch the Gradio app
|
|
|
|
| 12 |
from PIL import Image
|
| 13 |
import utils.plot as pt
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
theme = gr.themes.Soft(
|
| 16 |
primary_hue="orange",
|
| 17 |
).set(
|
| 18 |
body_background_fill='*primary_50',
|
| 19 |
block_background_fill='*neutral_50'
|
| 20 |
)
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
# Clear any previous data and configurations
|
| 24 |
+
clear_all()
|
| 25 |
+
model = YOLO('./weights/best.pt')
|
| 26 |
+
# Define the color scheme/theme for the website
|
| 27 |
#Custom css for styling
|
| 28 |
css = """
|
| 29 |
.size {
|
|
|
|
| 179 |
return np.array(input_image)
|
| 180 |
|
| 181 |
|
| 182 |
+
def predict_segmentation_im(image, conf, reference, remark, distance):
|
| 183 |
"""
|
| 184 |
Perform segmentation prediction on a list of images.
|
| 185 |
|
|
|
|
| 259 |
contour_analyzer.draw_circle_on_image(visualized_image, (int(thickest_points[0]), int(thickest_points[1])), 5, (57, 255, 20), -1)
|
| 260 |
print("Max Width in pixels: ", max_width)
|
| 261 |
|
| 262 |
+
width = contour_analyzer.calculate_width(y=thickest_points[1], x=thickest_points[0], pixel_width=max_width, calibration_factor=0.36*0.01, distance=distance)
|
| 263 |
print("Max Width, converted: ", width)
|
| 264 |
|
| 265 |
prets = pt.classify_wall_damage(width)
|
|
|
|
| 301 |
# Connect the buttons to the prediction function and clear function
|
| 302 |
image_button.click(
|
| 303 |
predict_segmentation_im,
|
| 304 |
+
inputs=[image_input, conf, image_reference, image_remark, distance],
|
| 305 |
outputs=[image_output, csv_image, df_image, md_result]
|
| 306 |
)
|
| 307 |
|
|
|
|
| 314 |
gr.DataFrame(visible=False),
|
| 315 |
gr.Slider(value=20),
|
| 316 |
None,
|
| 317 |
+
None,
|
| 318 |
+
gr.Slider(value=10)
|
| 319 |
],
|
| 320 |
+
outputs=[image_input, image_output, md_result, csv_image, df_image, conf, image_reference, image_remark, distance]
|
| 321 |
)
|
| 322 |
|
| 323 |
# Launch the Gradio app
|