Spaces:
Runtime error
Runtime error
Upload 3 files
Browse files- app.py +78 -0
- best.pt +3 -0
- requirements.txt +3 -0
app.py
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import torch
|
| 3 |
+
from ultralyticsplus import YOLO, render_result
|
| 4 |
+
from PIL import Image
|
| 5 |
+
import os
|
| 6 |
+
|
| 7 |
+
def yolov8_func(image,
|
| 8 |
+
image_size,
|
| 9 |
+
conf_thresold=0.4,
|
| 10 |
+
iou_thresold=0.50):
|
| 11 |
+
|
| 12 |
+
# Load the YOLOv8 model
|
| 13 |
+
model_path = "best.pt"
|
| 14 |
+
model = YOLO(model_path) # Use your custom model path here
|
| 15 |
+
|
| 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 = [
|
| 55 |
+
gr.Image(type="filepath", label="Input Image"),
|
| 56 |
+
gr.Slider(minimum=320, maximum=1280, step=32, value=640, label="Image Size"),
|
| 57 |
+
gr.Slider(minimum=0, maximum=1, step=0.05, value=0.15, label="Confidence Threshold"),
|
| 58 |
+
gr.Slider(minimum=0, maximum=1, step=0.05, value=0.15, 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"
|
| 70 |
+
|
| 71 |
+
# Create the Gradio interface
|
| 72 |
+
yolo_app = gr.Interface(fn=yolov8_func,
|
| 73 |
+
inputs=inputs,
|
| 74 |
+
outputs=outputs,
|
| 75 |
+
title=title)
|
| 76 |
+
|
| 77 |
+
# Launch the app
|
| 78 |
+
yolo_app.launch(debug=True)
|
best.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:88dd8766ff1f53969339c030cb78f8736148c25a1bbeec111d171e5126ce08e4
|
| 3 |
+
size 19956335
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio==5.0.0
|
| 2 |
+
torch
|
| 3 |
+
ultralyticsplus==0.1.0
|