jayn95 commited on
Commit
e740f5e
·
verified ·
1 Parent(s): 186fa75

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -7
app.py CHANGED
@@ -127,8 +127,12 @@ def detect_periodontitis(image_np):
127
  # Compute mm scaling
128
  mm_per_px, method = compute_mm_per_pixel(temp_path)
129
 
130
- # Summaries — CLEAN (no method labels)
131
- summaries = []
 
 
 
 
132
  for tooth in results["distance_analyses"]:
133
  tid = tooth["tooth_id"]
134
  analysis = tooth["analysis"]
@@ -136,19 +140,34 @@ def detect_periodontitis(image_np):
136
  if analysis:
137
  px = analysis["mean_distance"]
138
  mm = px * mm_per_px
139
- summaries.append(f"Tooth {tid}: {mm:.2f} mm")
 
 
 
 
 
 
 
140
  else:
141
- summaries.append(f"Tooth {tid}: no valid CEJ–ABC measurement")
 
 
 
 
 
142
 
143
- summary_text = "\n".join(summaries)
144
 
145
- # Remove temp
146
  try:
147
  os.remove(temp_path)
148
  except:
149
  pass
150
 
151
- return combined_rgb, summary_text
 
 
 
152
 
153
 
154
  # ==========================
 
127
  # Compute mm scaling
128
  mm_per_px, method = compute_mm_per_pixel(temp_path)
129
 
130
+ # ==============================================
131
+ # Build structured measurement list for Flutter
132
+ # ==============================================
133
+ measurements = []
134
+ summary_lines = []
135
+
136
  for tooth in results["distance_analyses"]:
137
  tid = tooth["tooth_id"]
138
  analysis = tooth["analysis"]
 
140
  if analysis:
141
  px = analysis["mean_distance"]
142
  mm = px * mm_per_px
143
+
144
+ measurements.append({
145
+ "tooth_id": tid,
146
+ "mm": round(mm, 2)
147
+ })
148
+
149
+ summary_lines.append(f"Tooth {tid}: {mm:.2f} mm")
150
+
151
  else:
152
+ measurements.append({
153
+ "tooth_id": tid,
154
+ "mm": None
155
+ })
156
+
157
+ summary_lines.append(f"Tooth {tid}: no valid CEJ–ABC measurement")
158
 
159
+ summary_text = "\n".join(summary_lines)
160
 
161
+ # Remove temp file safely
162
  try:
163
  os.remove(temp_path)
164
  except:
165
  pass
166
 
167
+ # ============================================================
168
+ # Return both: structured measurements + text + image
169
+ # ============================================================
170
+ return combined_rgb, measurements, summary_text
171
 
172
 
173
  # ==========================