Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -16,19 +16,39 @@ def yolov8_func(image,
|
|
16 |
# Make predictions
|
17 |
result = model.predict(image, conf=conf_thresold, iou=iou_thresold, imgsz=image_size)
|
18 |
|
19 |
-
# Access
|
20 |
-
|
21 |
-
|
22 |
-
print("Confidence: ", box.conf)
|
23 |
-
print("Coordinates: ", box.xyxy)
|
24 |
|
25 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
render = render_result(model=model, image=image, result=result[0])
|
27 |
|
28 |
-
# Save the rendered image
|
29 |
-
|
30 |
-
render.save(
|
31 |
-
|
|
|
|
|
32 |
|
33 |
# Define inputs for the Gradio app
|
34 |
inputs = [
|
@@ -38,8 +58,12 @@ inputs = [
|
|
38 |
gr.Slider(minimum=0, maximum=1, step=0.05, value=0.45, label="IOU Threshold")
|
39 |
]
|
40 |
|
41 |
-
# Define the output for the Gradio app
|
42 |
-
outputs =
|
|
|
|
|
|
|
|
|
43 |
|
44 |
# Set the title of the Gradio app
|
45 |
title = "YOLOv8: An Object Detection for Acne"
|
|
|
16 |
# Make predictions
|
17 |
result = model.predict(image, conf=conf_thresold, iou=iou_thresold, imgsz=image_size)
|
18 |
|
19 |
+
# Access object detection results
|
20 |
+
boxes = result[0].boxes # Bounding boxes
|
21 |
+
num_boxes = len(boxes) # Count the number of bounding boxes (detections)
|
|
|
|
|
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"
|
32 |
+
recommendation = "It is recommended to see a dermatologist and start stronger acne treatment."
|
33 |
+
elif 5 <= num_boxes <= 10:
|
34 |
+
severity = "Medium"
|
35 |
+
recommendation = "You should follow a consistent skincare routine with proper cleansing and moisturizing."
|
36 |
+
else:
|
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 |
|
46 |
+
# Save the rendered image (with predictions)
|
47 |
+
predicted_image_save_path = "predicted_image.jpg"
|
48 |
+
render.save(predicted_image_save_path)
|
49 |
+
|
50 |
+
# Return the saved image, severity, and recommendation for Gradio output
|
51 |
+
return predicted_image_save_path, f"Acne condition: {severity}", recommendation
|
52 |
|
53 |
# Define inputs for the Gradio app
|
54 |
inputs = [
|
|
|
58 |
gr.Slider(minimum=0, maximum=1, step=0.05, value=0.45, label="IOU Threshold")
|
59 |
]
|
60 |
|
61 |
+
# Define the output for the Gradio app (image + text for severity and recommendation)
|
62 |
+
outputs = [
|
63 |
+
gr.Image(type="filepath", label="Output Image"),
|
64 |
+
gr.Textbox(label="Acne Condition"),
|
65 |
+
gr.Textbox(label="Recommendation")
|
66 |
+
]
|
67 |
|
68 |
# Set the title of the Gradio app
|
69 |
title = "YOLOv8: An Object Detection for Acne"
|