DawnC commited on
Commit
87e345a
·
1 Parent(s): afa51ae

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -42
app.py CHANGED
@@ -261,43 +261,8 @@ async def predict(image):
261
 
262
  dogs_info = ""
263
 
264
- # for i, (cropped_image, detection_confidence, box) in enumerate(dogs):
265
- # buttons_html = ""
266
- # top1_prob, topk_breeds, topk_probs_percent = await predict_single_dog(cropped_image)
267
- # color = color_list[i % len(color_list)]
268
- # draw.rectangle(box, outline=color, width=3)
269
- # draw.text((box[0] + 5, box[1] + 5), f"Dog {i+1}", fill=color, font=font)
270
-
271
- # combined_confidence = detection_confidence * top1_prob
272
- # dogs_info += f'<div class="dog-info" style="border-left: 5px solid {color}; margin-bottom: 20px; padding: 15px;">'
273
- # dogs_info += f'<h2>Dog {i+1}</h2>'
274
-
275
- # if top1_prob >= 0.45:
276
- # breed = topk_breeds[0]
277
- # description = get_dog_description(breed)
278
- # dogs_info += format_description_html(description, breed)
279
-
280
- # elif combined_confidence >= 0.15:
281
- # dogs_info += f"<p>Top 3 possible breeds:</p><ul>"
282
- # for j, (breed, prob) in enumerate(zip(topk_breeds[:3], topk_probs_percent[:3])):
283
- # prob = float(prob.replace('%', ''))
284
- # dogs_info += f"<li><strong>{breed}</strong> ({prob:.2f}% confidence)</li>"
285
- # dogs_info += "</ul>"
286
-
287
- # for breed in topk_breeds[:3]:
288
- # button_id = f"Dog {i+1}: More about {breed}"
289
- # buttons_html += f'<button class="breed-button" onclick="handle_button_click(\'{button_id}\')">{breed}</button>'
290
- # buttons.append(button_id)
291
-
292
- # else:
293
- # dogs_info += "<p>The image is unclear or the breed is not in the dataset. Please upload a clearer image.</p>"
294
-
295
- # dogs_info += '</div>'
296
-
297
-
298
-
299
  for i, (cropped_image, detection_confidence, box) in enumerate(dogs):
300
- buttons_html = "" # 清空按鈕 HTML 變數
301
  top1_prob, topk_breeds, topk_probs_percent = await predict_single_dog(cropped_image)
302
  color = color_list[i % len(color_list)]
303
  draw.rectangle(box, outline=color, width=3)
@@ -311,6 +276,7 @@ async def predict(image):
311
  breed = topk_breeds[0]
312
  description = get_dog_description(breed)
313
  dogs_info += format_description_html(description, breed)
 
314
  elif combined_confidence >= 0.15:
315
  dogs_info += f"<p>Top 3 possible breeds:</p><ul>"
316
  for j, (breed, prob) in enumerate(zip(topk_breeds[:3], topk_probs_percent[:3])):
@@ -318,20 +284,17 @@ async def predict(image):
318
  dogs_info += f"<li><strong>{breed}</strong> ({prob:.2f}% confidence)</li>"
319
  dogs_info += "</ul>"
320
 
321
- # 生成與品種對應的按鈕,並插入到描述後
322
  for breed in topk_breeds[:3]:
323
  button_id = f"Dog {i+1}: More about {breed}"
324
  buttons_html += f'<button class="breed-button" onclick="handle_button_click(\'{button_id}\')">{breed}</button>'
325
  buttons.append(button_id)
326
-
327
- # 將按鈕放在該狗的描述之後
328
- dogs_info += f'<div class="breed-buttons">{buttons_html}</div>'
329
 
330
  else:
331
  dogs_info += "<p>The image is unclear or the breed is not in the dataset. Please upload a clearer image.</p>"
332
 
333
- dogs_info += '</div>'
334
-
335
 
336
  buttons_html = ""
337
 
 
261
 
262
  dogs_info = ""
263
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
264
  for i, (cropped_image, detection_confidence, box) in enumerate(dogs):
265
+ buttons_html = ""
266
  top1_prob, topk_breeds, topk_probs_percent = await predict_single_dog(cropped_image)
267
  color = color_list[i % len(color_list)]
268
  draw.rectangle(box, outline=color, width=3)
 
276
  breed = topk_breeds[0]
277
  description = get_dog_description(breed)
278
  dogs_info += format_description_html(description, breed)
279
+
280
  elif combined_confidence >= 0.15:
281
  dogs_info += f"<p>Top 3 possible breeds:</p><ul>"
282
  for j, (breed, prob) in enumerate(zip(topk_breeds[:3], topk_probs_percent[:3])):
 
284
  dogs_info += f"<li><strong>{breed}</strong> ({prob:.2f}% confidence)</li>"
285
  dogs_info += "</ul>"
286
 
 
287
  for breed in topk_breeds[:3]:
288
  button_id = f"Dog {i+1}: More about {breed}"
289
  buttons_html += f'<button class="breed-button" onclick="handle_button_click(\'{button_id}\')">{breed}</button>'
290
  buttons.append(button_id)
291
+
292
+ dogs_info += f'<div class="breed-buttons">{buttons_html}</div>' # new if not work, delete it
 
293
 
294
  else:
295
  dogs_info += "<p>The image is unclear or the breed is not in the dataset. Please upload a clearer image.</p>"
296
 
297
+ dogs_info += '</div>'
 
298
 
299
  buttons_html = ""
300