DawnC commited on
Commit
041d999
Β·
1 Parent(s): 9ec941c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -10
app.py CHANGED
@@ -518,42 +518,81 @@ async def predict(image):
518
  draw = ImageDraw.Draw(annotated_image)
519
  font = ImageFont.load_default()
520
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
521
  dogs_info = ""
522
- buttons_html = ""
523
 
524
  for i, (cropped_image, detection_confidence, box) in enumerate(dogs):
525
  top1_prob, topk_breeds, topk_probs_percent = await predict_single_dog(cropped_image)
526
  color = color_list[i % len(color_list)]
527
  draw.rectangle(box, outline=color, width=3)
528
  draw.text((box[0] + 5, box[1] + 5), f"Dog {i+1}", fill=color, font=font)
529
-
530
  combined_confidence = detection_confidence * top1_prob
531
  dogs_info += f'<div class="dog-info" style="border-left: 5px solid {color}; margin-bottom: 20px; padding: 15px;">'
532
  dogs_info += f'<h2>Dog {i+1}</h2>'
533
-
534
  if top1_prob >= 0.45:
535
  breed = topk_breeds[0]
536
  description = get_dog_description(breed)
537
  dogs_info += format_description_html(description, breed)
538
-
539
  elif combined_confidence >= 0.15:
540
  dogs_info += f"<p>Top 3 possible breeds:</p><ul>"
541
  for j, (breed, prob) in enumerate(zip(topk_breeds[:3], topk_probs_percent[:3])):
542
  dogs_info += f"<li><strong>{breed}</strong> ({prob} confidence)</li>"
543
  dogs_info += "</ul>"
544
- #buttons_html += '<div class="breed-buttons">'
545
- buttons_html = '<div class="breed-buttons">' #new
 
546
  for breed in topk_breeds[:3]:
547
  button_id = f"Dog {i+1}: More about {breed}"
548
  buttons_html += f'<button class="breed-button" onclick="handle_button_click(\'{button_id}\')">{breed}</button>'
549
  buttons.append(button_id)
550
  buttons_html += '</div>'
 
 
551
  else:
552
  dogs_info += "<p>The image is unclear or the breed is not in the dataset. Please upload a clearer image.</p>"
553
 
554
- dogs_info += '</div>'
555
-
556
- dogs_info += buttons_html
557
 
558
 
559
  html_output = f"""
@@ -564,7 +603,7 @@ async def predict(image):
564
  .breed-button {{ margin-right: 10px; margin-bottom: 10px; padding: 5px 10px; background-color: #4CAF50; color: white; border: none; border-radius: 3px; cursor: pointer; }}
565
  </style>
566
  {dogs_info}
567
- {buttons_html}
568
  """
569
 
570
  if buttons:
 
518
  draw = ImageDraw.Draw(annotated_image)
519
  font = ImageFont.load_default()
520
 
521
+ # dogs_info = ""
522
+ # buttons_html = ""
523
+
524
+ # for i, (cropped_image, detection_confidence, box) in enumerate(dogs):
525
+ # top1_prob, topk_breeds, topk_probs_percent = await predict_single_dog(cropped_image)
526
+ # color = color_list[i % len(color_list)]
527
+ # draw.rectangle(box, outline=color, width=3)
528
+ # draw.text((box[0] + 5, box[1] + 5), f"Dog {i+1}", fill=color, font=font)
529
+
530
+ # combined_confidence = detection_confidence * top1_prob
531
+ # dogs_info += f'<div class="dog-info" style="border-left: 5px solid {color}; margin-bottom: 20px; padding: 15px;">'
532
+ # dogs_info += f'<h2>Dog {i+1}</h2>'
533
+
534
+ # if top1_prob >= 0.45:
535
+ # breed = topk_breeds[0]
536
+ # description = get_dog_description(breed)
537
+ # dogs_info += format_description_html(description, breed)
538
+
539
+ # elif combined_confidence >= 0.15:
540
+ # dogs_info += f"<p>Top 3 possible breeds:</p><ul>"
541
+ # for j, (breed, prob) in enumerate(zip(topk_breeds[:3], topk_probs_percent[:3])):
542
+ # dogs_info += f"<li><strong>{breed}</strong> ({prob} confidence)</li>"
543
+ # dogs_info += "</ul>"
544
+ # buttons_html = '<div class="breed-buttons">' #new
545
+ # for breed in topk_breeds[:3]:
546
+ # button_id = f"Dog {i+1}: More about {breed}"
547
+ # buttons_html += f'<button class="breed-button" onclick="handle_button_click(\'{button_id}\')">{breed}</button>'
548
+ # buttons.append(button_id)
549
+ # buttons_html += '</div>'
550
+ # else:
551
+ # dogs_info += "<p>The image is unclear or the breed is not in the dataset. Please upload a clearer image.</p>"
552
+
553
+ # dogs_info += '</div>'
554
+
555
+ # dogs_info += buttons_html
556
+
557
+
558
  dogs_info = ""
 
559
 
560
  for i, (cropped_image, detection_confidence, box) in enumerate(dogs):
561
  top1_prob, topk_breeds, topk_probs_percent = await predict_single_dog(cropped_image)
562
  color = color_list[i % len(color_list)]
563
  draw.rectangle(box, outline=color, width=3)
564
  draw.text((box[0] + 5, box[1] + 5), f"Dog {i+1}", fill=color, font=font)
565
+
566
  combined_confidence = detection_confidence * top1_prob
567
  dogs_info += f'<div class="dog-info" style="border-left: 5px solid {color}; margin-bottom: 20px; padding: 15px;">'
568
  dogs_info += f'<h2>Dog {i+1}</h2>'
569
+
570
  if top1_prob >= 0.45:
571
  breed = topk_breeds[0]
572
  description = get_dog_description(breed)
573
  dogs_info += format_description_html(description, breed)
574
+
575
  elif combined_confidence >= 0.15:
576
  dogs_info += f"<p>Top 3 possible breeds:</p><ul>"
577
  for j, (breed, prob) in enumerate(zip(topk_breeds[:3], topk_probs_percent[:3])):
578
  dogs_info += f"<li><strong>{breed}</strong> ({prob} confidence)</li>"
579
  dogs_info += "</ul>"
580
+
581
+ # ζ―ιš»η‹—ηš„ζŒ‰ιˆ•η”ŸζˆδΈ¦ι™„εŠ εˆ°θ©²ιš»η‹—ηš„θ³‡θ¨ŠδΈ­
582
+ buttons_html = '<div class="breed-buttons">'
583
  for breed in topk_breeds[:3]:
584
  button_id = f"Dog {i+1}: More about {breed}"
585
  buttons_html += f'<button class="breed-button" onclick="handle_button_click(\'{button_id}\')">{breed}</button>'
586
  buttons.append(button_id)
587
  buttons_html += '</div>'
588
+ dogs_info += buttons_html # ε°‡ζŒ‰ιˆ•η›΄ζŽ₯加ε…₯εˆ°θ©²ιš»η‹—ηš„θ³‡θ¨ŠδΈ­
589
+
590
  else:
591
  dogs_info += "<p>The image is unclear or the breed is not in the dataset. Please upload a clearer image.</p>"
592
 
593
+ dogs_info += '</div>' # ι—œι–‰θ©²ιš»η‹—ηš„θ³‡θ¨Šε€ε‘Š
594
+
595
+
596
 
597
 
598
  html_output = f"""
 
603
  .breed-button {{ margin-right: 10px; margin-bottom: 10px; padding: 5px 10px; background-color: #4CAF50; color: white; border: none; border-radius: 3px; cursor: pointer; }}
604
  </style>
605
  {dogs_info}
606
+
607
  """
608
 
609
  if buttons: