Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -20,12 +20,6 @@ def yolov8_func(image,
|
|
20 |
boxes = result[0].boxes
|
21 |
num_boxes = len(boxes)
|
22 |
|
23 |
-
# Print object detection details (optional)
|
24 |
-
print("Object type: ", boxes.cls)
|
25 |
-
print("Confidence: ", boxes.conf)
|
26 |
-
print("Coordinates: ", boxes.xyxy)
|
27 |
-
print(f"Number of bounding boxes: {num_boxes}")
|
28 |
-
|
29 |
# Categorize based on number of boxes (detections) and provide recommendations
|
30 |
if num_boxes > 10:
|
31 |
severity = "Worse"
|
@@ -37,9 +31,6 @@ def yolov8_func(image,
|
|
37 |
severity = "Good"
|
38 |
recommendation = "Your skin looks good! Keep up with your current skincare routine."
|
39 |
|
40 |
-
print(f"Acne condition: {severity}")
|
41 |
-
print(f"Recommendation: {recommendation}")
|
42 |
-
|
43 |
# Render the result (with bounding boxes/labels)
|
44 |
render = render_result(model=model, image=image, result=result[0])
|
45 |
|
@@ -47,33 +38,27 @@ def yolov8_func(image,
|
|
47 |
render.save(predicted_image_save_path)
|
48 |
return predicted_image_save_path, f"Acne condition: {severity}", recommendation
|
49 |
|
50 |
-
#
|
51 |
-
|
52 |
-
gr.
|
53 |
-
gr.Slider(minimum=320, maximum=1280, step=32, value=640, label="Image Size"),
|
54 |
-
gr.Slider(minimum=0, maximum=1, step=0.05, value=0.15, label="Confidence Threshold"),
|
55 |
-
gr.Slider(minimum=0, maximum=1, step=0.05, value=0.2, label="IOU Threshold")
|
56 |
-
]
|
57 |
-
|
58 |
-
# Use a Row layout to align the textboxes for condition and recommendation
|
59 |
-
output_image = gr.Image(type="filepath", label="Output Image")
|
60 |
-
acne_condition = gr.Textbox(label="Acne Condition")
|
61 |
-
recommendation = gr.Textbox(label="Recommendation")
|
62 |
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
|
|
|
|
68 |
|
69 |
-
|
70 |
-
|
|
|
|
|
71 |
|
72 |
-
#
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
title=title)
|
77 |
|
78 |
# Launch the app
|
79 |
yolo_app.launch(debug=True)
|
|
|
20 |
boxes = result[0].boxes
|
21 |
num_boxes = len(boxes)
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
# Categorize based on number of boxes (detections) and provide recommendations
|
24 |
if num_boxes > 10:
|
25 |
severity = "Worse"
|
|
|
31 |
severity = "Good"
|
32 |
recommendation = "Your skin looks good! Keep up with your current skincare routine."
|
33 |
|
|
|
|
|
|
|
34 |
# Render the result (with bounding boxes/labels)
|
35 |
render = render_result(model=model, image=image, result=result[0])
|
36 |
|
|
|
38 |
render.save(predicted_image_save_path)
|
39 |
return predicted_image_save_path, f"Acne condition: {severity}", recommendation
|
40 |
|
41 |
+
# Create the Gradio app using Blocks
|
42 |
+
with gr.Blocks() as yolo_app:
|
43 |
+
gr.Markdown("# YOLOv8: An Object Detection for Acne")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
|
45 |
+
with gr.Row():
|
46 |
+
with gr.Column():
|
47 |
+
input_image = gr.Image(type="filepath", label="Input Image")
|
48 |
+
image_size = gr.Slider(minimum=320, maximum=1280, step=32, value=640, label="Image Size")
|
49 |
+
conf_thresh = gr.Slider(minimum=0, maximum=1, step=0.05, value=0.15, label="Confidence Threshold")
|
50 |
+
iou_thresh = gr.Slider(minimum=0, maximum=1, step=0.05, value=0.2, label="IOU Threshold")
|
51 |
+
submit_btn = gr.Button("Submit")
|
52 |
|
53 |
+
with gr.Column():
|
54 |
+
output_image = gr.Image(type="filepath", label="Output Image")
|
55 |
+
acne_condition = gr.Textbox(label="Acne Condition")
|
56 |
+
recommendation = gr.Textbox(label="Recommendation")
|
57 |
|
58 |
+
# Link the submit button to the function
|
59 |
+
submit_btn.click(fn=yolov8_func,
|
60 |
+
inputs=[input_image, image_size, conf_thresh, iou_thresh],
|
61 |
+
outputs=[output_image, acne_condition, recommendation])
|
|
|
62 |
|
63 |
# Launch the app
|
64 |
yolo_app.launch(debug=True)
|