DawnC commited on
Commit
8ecc386
ยท
1 Parent(s): 5a3e9ec

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -6
app.py CHANGED
@@ -472,32 +472,33 @@ async def predict(image):
472
  color = color_list[i % len(color_list)]
473
  draw.rectangle(box, outline=color, width=3)
474
  draw.text((box[0] + 5, box[1] + 5), f"Dog {i+1}", fill=color, font=font)
475
-
476
  combined_confidence = detection_confidence * top1_prob
477
  dogs_info += f'<div class="dog-info" style="border-left: 5px solid {color}; margin-bottom: 20px; padding: 15px;">'
478
  dogs_info += f'<h2>Dog {i+1}</h2>'
479
-
480
  if top1_prob >= 0.45:
481
  breed = topk_breeds[0]
482
  description = get_dog_description(breed)
483
  dogs_info += format_description_html(description, breed)
484
-
485
  elif combined_confidence >= 0.15:
486
  dogs_info += f"<p>Top 3 possible breeds:</p><ul>"
487
  for j, (breed, prob) in enumerate(zip(topk_breeds[:3], topk_probs_percent[:3])):
488
  prob = float(prob.replace('%', ''))
489
  button_id = f"Dog {i+1}: More about {breed}"
490
  buttons.append(button_id) # ็‚บๆฏๅ€‹ๅ“็จฎๅŠ ๅ…ฅๆŒ‰้ˆ•
 
491
  # ๅŠ ๅ…ฅ Learn More ๆŒ‰้ˆ•
492
  dogs_info += f"<li><strong>{breed}</strong> ({prob:.2f}% confidence)"
493
  dogs_info += f'<button style="background-color: #4CAF50; color: white; border: none; padding: 5px 10px; border-radius: 3px; margin-left: 10px;" onclick="handle_button_click(\'{button_id}\')">Learn More</button></li>'
494
  dogs_info += "</ul>"
495
-
496
  else:
497
  dogs_info += "<p>The image is unclear or the breed is not in the dataset. Please upload a clearer image.</p>"
498
-
499
  dogs_info += '</div>'
500
-
501
  # ็”Ÿๆˆ Javascript ไพ†่™•็†ๆŒ‰้ˆ•้ปžๆ“Šไบ‹ไปถ
502
  html_output = f"""
503
  <style>
@@ -518,6 +519,7 @@ async def predict(image):
518
  """
519
 
520
 
 
521
  initial_state = {
522
  "dogs_info": dogs_info,
523
  "buttons": buttons,
 
472
  color = color_list[i % len(color_list)]
473
  draw.rectangle(box, outline=color, width=3)
474
  draw.text((box[0] + 5, box[1] + 5), f"Dog {i+1}", fill=color, font=font)
475
+
476
  combined_confidence = detection_confidence * top1_prob
477
  dogs_info += f'<div class="dog-info" style="border-left: 5px solid {color}; margin-bottom: 20px; padding: 15px;">'
478
  dogs_info += f'<h2>Dog {i+1}</h2>'
479
+
480
  if top1_prob >= 0.45:
481
  breed = topk_breeds[0]
482
  description = get_dog_description(breed)
483
  dogs_info += format_description_html(description, breed)
484
+
485
  elif combined_confidence >= 0.15:
486
  dogs_info += f"<p>Top 3 possible breeds:</p><ul>"
487
  for j, (breed, prob) in enumerate(zip(topk_breeds[:3], topk_probs_percent[:3])):
488
  prob = float(prob.replace('%', ''))
489
  button_id = f"Dog {i+1}: More about {breed}"
490
  buttons.append(button_id) # ็‚บๆฏๅ€‹ๅ“็จฎๅŠ ๅ…ฅๆŒ‰้ˆ•
491
+
492
  # ๅŠ ๅ…ฅ Learn More ๆŒ‰้ˆ•
493
  dogs_info += f"<li><strong>{breed}</strong> ({prob:.2f}% confidence)"
494
  dogs_info += f'<button style="background-color: #4CAF50; color: white; border: none; padding: 5px 10px; border-radius: 3px; margin-left: 10px;" onclick="handle_button_click(\'{button_id}\')">Learn More</button></li>'
495
  dogs_info += "</ul>"
496
+
497
  else:
498
  dogs_info += "<p>The image is unclear or the breed is not in the dataset. Please upload a clearer image.</p>"
499
+
500
  dogs_info += '</div>'
501
+
502
  # ็”Ÿๆˆ Javascript ไพ†่™•็†ๆŒ‰้ˆ•้ปžๆ“Šไบ‹ไปถ
503
  html_output = f"""
504
  <style>
 
519
  """
520
 
521
 
522
+
523
  initial_state = {
524
  "dogs_info": dogs_info,
525
  "buttons": buttons,