Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -36,43 +36,30 @@ def preprocess(image):
|
|
| 36 |
def detect_gingivitis(image, conf=0.4, iou=0.5):
|
| 37 |
image = preprocess(image)
|
| 38 |
|
| 39 |
-
# >> Run models <<
|
| 40 |
sw_res = model_swelling.predict(image, conf=conf, iou=iou)
|
| 41 |
rd_res = model_redness.predict(image, conf=conf, iou=iou)
|
| 42 |
bl_res = model_bleeding.predict(image, conf=conf, iou=iou)
|
| 43 |
|
| 44 |
-
#
|
| 45 |
-
img_sw =
|
| 46 |
-
img_rd =
|
| 47 |
-
img_bl =
|
| 48 |
|
| 49 |
-
# >> Save to temporary files <<
|
| 50 |
-
sw_path = save_temp_file(img_sw)
|
| 51 |
-
rd_path = save_temp_file(img_rd)
|
| 52 |
-
bl_path = save_temp_file(img_bl)
|
| 53 |
-
|
| 54 |
-
# >> Diagnosis <<
|
| 55 |
has_sw = len(sw_res[0].boxes) > 0
|
| 56 |
has_rd = len(rd_res[0].boxes) > 0
|
| 57 |
has_bl = len(bl_res[0].boxes) > 0
|
| 58 |
|
| 59 |
-
# ------------------------------
|
| 60 |
-
# UPDATED: CUSTOM DIAGNOSIS
|
| 61 |
-
# ------------------------------
|
| 62 |
if has_sw and has_rd and has_bl:
|
| 63 |
diagnosis = (
|
| 64 |
"🦷 You have gingivitis.\n\n"
|
| 65 |
-
"For accurate assessment and guidance, we recommend visiting your dentist
|
| 66 |
-
"
|
| 67 |
-
"If you have a periapical X-ray available, you can use the **Detect Periodontitis** feature for further analysis.\n\n"
|
| 68 |
-
"Would you like to proceed?"
|
| 69 |
)
|
| 70 |
else:
|
| 71 |
-
diagnosis = "🟢
|
|
|
|
|
|
|
| 72 |
|
| 73 |
-
# *** CRITICAL ***
|
| 74 |
-
# Must return FILE PATHS + diagnosis string in ONE LIST
|
| 75 |
-
return [sw_path, rd_path, bl_path, diagnosis]
|
| 76 |
|
| 77 |
# Gradio Interface
|
| 78 |
interface = gr.Interface(
|
|
@@ -83,9 +70,9 @@ interface = gr.Interface(
|
|
| 83 |
gr.Slider(0, 1, value=0.5, step=0.05, label="NMS IoU Threshold"),
|
| 84 |
],
|
| 85 |
outputs=[
|
| 86 |
-
gr.
|
| 87 |
-
gr.
|
| 88 |
-
gr.
|
| 89 |
gr.Textbox(label="Diagnosis")
|
| 90 |
],
|
| 91 |
title="Gingivitis Detection"
|
|
|
|
| 36 |
def detect_gingivitis(image, conf=0.4, iou=0.5):
|
| 37 |
image = preprocess(image)
|
| 38 |
|
|
|
|
| 39 |
sw_res = model_swelling.predict(image, conf=conf, iou=iou)
|
| 40 |
rd_res = model_redness.predict(image, conf=conf, iou=iou)
|
| 41 |
bl_res = model_bleeding.predict(image, conf=conf, iou=iou)
|
| 42 |
|
| 43 |
+
# Convert YOLO output → numpy RGB
|
| 44 |
+
img_sw = sw_res[0].plot()[:, :, ::-1] # BGR → RGB
|
| 45 |
+
img_rd = rd_res[0].plot()[:, :, ::-1]
|
| 46 |
+
img_bl = bl_res[0].plot()[:, :, ::-1]
|
| 47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
has_sw = len(sw_res[0].boxes) > 0
|
| 49 |
has_rd = len(rd_res[0].boxes) > 0
|
| 50 |
has_bl = len(bl_res[0].boxes) > 0
|
| 51 |
|
|
|
|
|
|
|
|
|
|
| 52 |
if has_sw and has_rd and has_bl:
|
| 53 |
diagnosis = (
|
| 54 |
"🦷 You have gingivitis.\n\n"
|
| 55 |
+
"For accurate assessment and guidance, we recommend visiting your dentist.\n"
|
| 56 |
+
"If you have a periapical X-ray, you may try the *Detect Periodontitis* tool."
|
|
|
|
|
|
|
| 57 |
)
|
| 58 |
else:
|
| 59 |
+
diagnosis = "🟢 You don't have gingivitis."
|
| 60 |
+
|
| 61 |
+
return [img_sw, img_rd, img_bl, diagnosis]
|
| 62 |
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
# Gradio Interface
|
| 65 |
interface = gr.Interface(
|
|
|
|
| 70 |
gr.Slider(0, 1, value=0.5, step=0.05, label="NMS IoU Threshold"),
|
| 71 |
],
|
| 72 |
outputs=[
|
| 73 |
+
gr.Image(label="Swelling Detection"),
|
| 74 |
+
gr.Image(label="Redness Detection"),
|
| 75 |
+
gr.Image(label="Bleeding Detection"),
|
| 76 |
gr.Textbox(label="Diagnosis")
|
| 77 |
],
|
| 78 |
title="Gingivitis Detection"
|