DawnC commited on
Commit
baeae81
·
1 Parent(s): 4426e8d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -11
app.py CHANGED
@@ -320,38 +320,35 @@ async def predict(image):
320
  breed = topk_breeds[0]
321
  description = get_dog_description(breed)
322
  dogs_info += format_description_html(description, breed)
323
-
324
  elif combined_confidence >= 0.15:
325
- # 多品種推測邏輯
326
  dogs_info += f"<p>Top 3 possible breeds:</p><ul>"
327
  for j, (breed, prob) in enumerate(zip(topk_breeds[:3], topk_probs_percent[:3])):
328
  prob = float(prob.replace('%', '')) # 去掉百分比符號並轉為浮點數
329
  dogs_info += f"<li><strong>{breed}</strong> ({prob:.2f}% confidence)</li>"
330
  dogs_info += "</ul>"
331
 
332
- # 單獨生成按鈕,按鈕生成邏輯完全獨立
333
- temp_buttons = '<div class="breed-buttons">' # 初始化每次生成的按鈕
334
  for breed in topk_breeds[:3]:
335
  button_id = f"Dog {i+1}: More about {breed}"
336
  temp_buttons += f'<button class="breed-button" onclick="handle_button_click(\'{button_id}\')">{breed}</button>'
337
  buttons.append(button_id)
338
  temp_buttons += '</div>'
339
 
340
- buttons_html += temp_buttons # 將本次生成的按鈕附加到 buttons_html
341
 
342
  else:
343
  dogs_info += "<p>The image is unclear or the breed is not in the dataset. Please upload a clearer image.</p>"
344
 
345
  dogs_info += '</div>' # 結束該狗的描述區塊
346
 
347
- # 統一將按鈕部分附加到最後輸出,確保不與品種名稱混淆
348
- dogs_info += buttons_html
349
-
350
 
351
 
352
-
353
-
354
-
355
  html_output = f"""
356
  <style>
357
  .dog-info {{ border: 1px solid #ddd; margin-bottom: 20px; padding: 15px; border-radius: 5px; box-shadow: 0 2px 5px rgba(0,0,0,0.1); }}
 
320
  breed = topk_breeds[0]
321
  description = get_dog_description(breed)
322
  dogs_info += format_description_html(description, breed)
323
+
324
  elif combined_confidence >= 0.15:
325
+ # 顯示 top3 品種
326
  dogs_info += f"<p>Top 3 possible breeds:</p><ul>"
327
  for j, (breed, prob) in enumerate(zip(topk_breeds[:3], topk_probs_percent[:3])):
328
  prob = float(prob.replace('%', '')) # 去掉百分比符號並轉為浮點數
329
  dogs_info += f"<li><strong>{breed}</strong> ({prob:.2f}% confidence)</li>"
330
  dogs_info += "</ul>"
331
 
332
+ # 單獨生成按鈕邏輯
333
+ temp_buttons = '<div class="breed-buttons">' # 按鈕生成區塊
334
  for breed in topk_breeds[:3]:
335
  button_id = f"Dog {i+1}: More about {breed}"
336
  temp_buttons += f'<button class="breed-button" onclick="handle_button_click(\'{button_id}\')">{breed}</button>'
337
  buttons.append(button_id)
338
  temp_buttons += '</div>'
339
 
340
+ buttons_html += temp_buttons # 按鈕 HTML 放置到按鈕區塊中
341
 
342
  else:
343
  dogs_info += "<p>The image is unclear or the breed is not in the dataset. Please upload a clearer image.</p>"
344
 
345
  dogs_info += '</div>' # 結束該狗的描述區塊
346
 
347
+ # 避免將按鈕與 dogs_info 同步顯示
348
+ if buttons_html:
349
+ dogs_info += buttons_html # 確保按鈕獨立並附加到最後輸出
350
 
351
 
 
 
 
352
  html_output = f"""
353
  <style>
354
  .dog-info {{ border: 1px solid #ddd; margin-bottom: 20px; padding: 15px; border-radius: 5px; box-shadow: 0 2px 5px rgba(0,0,0,0.1); }}