DawnC commited on
Commit
2eed8a5
·
verified ·
1 Parent(s): 4353b45

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -13
app.py CHANGED
@@ -266,7 +266,7 @@ async def predict(image):
266
  dogs_info = ""
267
 
268
  for i, (cropped_image, detection_confidence, box) in enumerate(dogs):
269
- buttons_html = "" # 初始化buttons_html,防止累積
270
  top1_prob, topk_breeds, topk_probs_percent = await predict_single_dog(cropped_image)
271
  color = color_list[i % len(color_list)]
272
  draw.rectangle(box, outline=color, width=3)
@@ -288,7 +288,6 @@ async def predict(image):
288
  dogs_info += f"<li><strong>{breed}</strong> ({prob:.2f}% confidence)</li>"
289
  dogs_info += "</ul>"
290
 
291
- # 清空 buttons_html 以防累積
292
  for breed in topk_breeds[:3]:
293
  button_id = f"Dog {i+1}: More about {breed}"
294
  buttons_html += f'<button class="breed-button" onclick="handle_button_click(\'{button_id}\')">{breed}</button>'
@@ -297,15 +296,10 @@ async def predict(image):
297
  else:
298
  dogs_info += "<p>The image is unclear or the breed is not in the dataset. Please upload a clearer image.</p>"
299
 
300
- dogs_info += '</div>' # 關閉這個狗的div
301
-
302
- # 確保在每次處理一隻狗後重置,防止累積
303
  buttons_html = ""
304
-
305
-
306
-
307
-
308
-
309
  html_output = f"""
310
  <style>
311
  .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); }}
@@ -335,7 +329,7 @@ async def predict(image):
335
  "show_back": True,
336
  "image": annotated_image,
337
  "is_multi_dog": len(dogs) > 1,
338
- "html_output": html_output # 儲存完整的 HTML 輸出
339
  }
340
  return html_output, annotated_image, gr.update(visible=True, choices=buttons), initial_state
341
  else:
@@ -345,7 +339,7 @@ async def predict(image):
345
  "show_back": False,
346
  "image": annotated_image,
347
  "is_multi_dog": len(dogs) > 1,
348
- "html_output": html_output # 儲存完整的 HTML 輸出
349
  }
350
  return html_output, annotated_image, gr.update(visible=False, choices=[]), initial_state
351
 
@@ -416,7 +410,7 @@ with gr.Blocks() as iface:
416
  input_image = gr.Image(label="Upload a dog image", type="pil")
417
  output_image = gr.Image(label="Annotated Image")
418
 
419
- output = gr.HTML(label="Prediction Results") # 使用 HTML 而不是 Markdown
420
 
421
  breed_buttons = gr.Radio(choices=[], label="More Information", visible=False)
422
 
 
266
  dogs_info = ""
267
 
268
  for i, (cropped_image, detection_confidence, box) in enumerate(dogs):
269
+ buttons_html = ""
270
  top1_prob, topk_breeds, topk_probs_percent = await predict_single_dog(cropped_image)
271
  color = color_list[i % len(color_list)]
272
  draw.rectangle(box, outline=color, width=3)
 
288
  dogs_info += f"<li><strong>{breed}</strong> ({prob:.2f}% confidence)</li>"
289
  dogs_info += "</ul>"
290
 
 
291
  for breed in topk_breeds[:3]:
292
  button_id = f"Dog {i+1}: More about {breed}"
293
  buttons_html += f'<button class="breed-button" onclick="handle_button_click(\'{button_id}\')">{breed}</button>'
 
296
  else:
297
  dogs_info += "<p>The image is unclear or the breed is not in the dataset. Please upload a clearer image.</p>"
298
 
299
+ dogs_info += '</div>'
300
+
 
301
  buttons_html = ""
302
+
 
 
 
 
303
  html_output = f"""
304
  <style>
305
  .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); }}
 
329
  "show_back": True,
330
  "image": annotated_image,
331
  "is_multi_dog": len(dogs) > 1,
332
+ "html_output": html_output
333
  }
334
  return html_output, annotated_image, gr.update(visible=True, choices=buttons), initial_state
335
  else:
 
339
  "show_back": False,
340
  "image": annotated_image,
341
  "is_multi_dog": len(dogs) > 1,
342
+ "html_output": html_output
343
  }
344
  return html_output, annotated_image, gr.update(visible=False, choices=[]), initial_state
345
 
 
410
  input_image = gr.Image(label="Upload a dog image", type="pil")
411
  output_image = gr.Image(label="Annotated Image")
412
 
413
+ output = gr.HTML(label="Prediction Results")
414
 
415
  breed_buttons = gr.Radio(choices=[], label="More Information", visible=False)
416