DawnC commited on
Commit
c855eed
·
1 Parent(s): a5727d0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -5
app.py CHANGED
@@ -316,19 +316,23 @@ async def predict(image):
316
  draw.rectangle(box, outline=color, width=3)
317
  draw.text((box[0] + 5, box[1] + 5), f"Dog {i+1}", fill=color, font=font)
318
 
 
 
 
 
319
  combined_confidence = detection_confidence * top1_prob
320
- print(f"Combined confidence for Dog {i+1}: {combined_confidence}") # 檢查confidence
321
 
322
  dogs_info += f'<div class="dog-info" style="border-left: 5px solid {color}; margin-bottom: 20px; padding: 15px;">'
323
  dogs_info += f'<h2>Dog {i+1}</h2>'
324
 
325
- if top1_prob >= 0.45:
326
  breed = topk_breeds[0]
327
  description = get_dog_description(breed)
328
  dogs_info += format_description_html(description, breed)
329
 
330
- elif combined_confidence >= 0.15:
331
- print(f"Entering button generation for Dog {i+1}") # 確認進入了這部分
332
  dogs_info += f"<p>Top 3 possible breeds:</p><ul>"
333
  for j, (breed, prob) in enumerate(zip(topk_breeds[:3], topk_probs_percent[:3])):
334
  prob = float(prob.replace('%', ''))
@@ -342,7 +346,7 @@ async def predict(image):
342
  dogs_info += "</ul>"
343
  dogs_info += f'<div>{buttons_html}</div>' # 確保按鈕顯示在該品種描述下
344
 
345
- else:
346
  dogs_info += "<p>The image is unclear or the breed is not in the dataset. Please upload a clearer image.</p>"
347
 
348
  dogs_info += '</div>' # 結束當前狗的資訊區塊
@@ -356,6 +360,7 @@ async def predict(image):
356
  """
357
 
358
 
 
359
 
360
 
361
  if buttons:
 
316
  draw.rectangle(box, outline=color, width=3)
317
  draw.text((box[0] + 5, box[1] + 5), f"Dog {i+1}", fill=color, font=font)
318
 
319
+ # 顯示追蹤訊息來幫助檢查數據
320
+ print(f"Detection confidence for Dog {i+1}: {detection_confidence}")
321
+ print(f"Top1 probability for Dog {i+1}: {top1_prob}")
322
+
323
  combined_confidence = detection_confidence * top1_prob
324
+ print(f"Combined confidence for Dog {i+1}: {combined_confidence}") # 確認combined confidence
325
 
326
  dogs_info += f'<div class="dog-info" style="border-left: 5px solid {color}; margin-bottom: 20px; padding: 15px;">'
327
  dogs_info += f'<h2>Dog {i+1}</h2>'
328
 
329
+ if combined_confidence >= 0.45: # 條件1:當 conf >= 0.45 時,返回最可能的品種資訊
330
  breed = topk_breeds[0]
331
  description = get_dog_description(breed)
332
  dogs_info += format_description_html(description, breed)
333
 
334
+ elif 0.15 < combined_confidence < 0.45: # 條件2:當 0.15 < conf < 0.45 時,返回前三個可能性並生成按鈕
335
+ print(f"Entering button generation for Dog {i+1}") # 確認進入這部分的條件
336
  dogs_info += f"<p>Top 3 possible breeds:</p><ul>"
337
  for j, (breed, prob) in enumerate(zip(topk_breeds[:3], topk_probs_percent[:3])):
338
  prob = float(prob.replace('%', ''))
 
346
  dogs_info += "</ul>"
347
  dogs_info += f'<div>{buttons_html}</div>' # 確保按鈕顯示在該品種描述下
348
 
349
+ else: # 條件3:當 conf < 0.15 時,返回 "圖像不清晰或無法辨認"
350
  dogs_info += "<p>The image is unclear or the breed is not in the dataset. Please upload a clearer image.</p>"
351
 
352
  dogs_info += '</div>' # 結束當前狗的資訊區塊
 
360
  """
361
 
362
 
363
+
364
 
365
 
366
  if buttons: