Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -432,11 +432,11 @@ async def predict(image):
|
|
| 432 |
if isinstance(image, np.ndarray):
|
| 433 |
image = Image.fromarray(image)
|
| 434 |
|
| 435 |
-
#
|
| 436 |
-
dogs = await detect_multiple_dogs(image, conf_threshold=0.
|
| 437 |
|
| 438 |
-
# 如果只檢測到一隻或沒有檢測到狗,使用單狗處理邏輯
|
| 439 |
if len(dogs) <= 1:
|
|
|
|
| 440 |
return await process_single_dog(image)
|
| 441 |
|
| 442 |
# 多狗情境
|
|
@@ -473,7 +473,7 @@ async def predict(image):
|
|
| 473 |
buttons[0] if len(buttons) > 0 else gr.update(visible=False),
|
| 474 |
buttons[1] if len(buttons) > 1 else gr.update(visible=False),
|
| 475 |
buttons[2] if len(buttons) > 2 else gr.update(visible=False),
|
| 476 |
-
gr.update(visible=
|
| 477 |
else:
|
| 478 |
return final_explanation, annotated_image, gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
|
| 479 |
|
|
@@ -503,7 +503,7 @@ async def process_single_dog(image):
|
|
| 503 |
gr.update(visible=True, value=f"More about {topk_breeds[0]}"),
|
| 504 |
gr.update(visible=True, value=f"More about {topk_breeds[1]}"),
|
| 505 |
gr.update(visible=True, value=f"More about {topk_breeds[2]}"),
|
| 506 |
-
gr.update(visible=True))
|
| 507 |
|
| 508 |
def show_details(choice, previous_output):
|
| 509 |
if not choice:
|
|
@@ -534,12 +534,12 @@ with gr.Blocks() as iface:
|
|
| 534 |
|
| 535 |
back_button = gr.Button("Back", visible=False)
|
| 536 |
|
| 537 |
-
|
| 538 |
|
| 539 |
input_image.change(
|
| 540 |
predict,
|
| 541 |
inputs=input_image,
|
| 542 |
-
outputs=[output, output_image, btn1, btn2, btn3, back_button,
|
| 543 |
)
|
| 544 |
|
| 545 |
for btn in [btn1, btn2, btn3]:
|
|
@@ -550,9 +550,9 @@ with gr.Blocks() as iface:
|
|
| 550 |
)
|
| 551 |
|
| 552 |
back_button.click(
|
| 553 |
-
lambda
|
| 554 |
-
inputs=[
|
| 555 |
-
outputs=[output, back_button]
|
| 556 |
)
|
| 557 |
|
| 558 |
gr.Examples(
|
|
@@ -562,6 +562,5 @@ with gr.Blocks() as iface:
|
|
| 562 |
|
| 563 |
gr.HTML('For more details on this project and other work, feel free to visit my GitHub <a href="https://github.com/Eric-Chung-0511/Learning-Record/tree/main/Data%20Science%20Projects/Dog_Breed_Classifier">Dog Breed Classifier</a>')
|
| 564 |
|
| 565 |
-
|
| 566 |
if __name__ == "__main__":
|
| 567 |
iface.launch()
|
|
|
|
| 432 |
if isinstance(image, np.ndarray):
|
| 433 |
image = Image.fromarray(image)
|
| 434 |
|
| 435 |
+
# 嘗試檢測多隻狗,進一步降低閾值以提高檢測率
|
| 436 |
+
dogs = await detect_multiple_dogs(image, conf_threshold=0.05) # 降低閾值以檢測更多狗
|
| 437 |
|
|
|
|
| 438 |
if len(dogs) <= 1:
|
| 439 |
+
# 單狗情境
|
| 440 |
return await process_single_dog(image)
|
| 441 |
|
| 442 |
# 多狗情境
|
|
|
|
| 473 |
buttons[0] if len(buttons) > 0 else gr.update(visible=False),
|
| 474 |
buttons[1] if len(buttons) > 1 else gr.update(visible=False),
|
| 475 |
buttons[2] if len(buttons) > 2 else gr.update(visible=False),
|
| 476 |
+
gr.update(visible=True)) # 顯示 back 按鈕
|
| 477 |
else:
|
| 478 |
return final_explanation, annotated_image, gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
|
| 479 |
|
|
|
|
| 503 |
gr.update(visible=True, value=f"More about {topk_breeds[0]}"),
|
| 504 |
gr.update(visible=True, value=f"More about {topk_breeds[1]}"),
|
| 505 |
gr.update(visible=True, value=f"More about {topk_breeds[2]}"),
|
| 506 |
+
gr.update(visible=True)) # 顯示 back 按鈕
|
| 507 |
|
| 508 |
def show_details(choice, previous_output):
|
| 509 |
if not choice:
|
|
|
|
| 534 |
|
| 535 |
back_button = gr.Button("Back", visible=False)
|
| 536 |
|
| 537 |
+
initial_state = gr.State()
|
| 538 |
|
| 539 |
input_image.change(
|
| 540 |
predict,
|
| 541 |
inputs=input_image,
|
| 542 |
+
outputs=[output, output_image, btn1, btn2, btn3, back_button, initial_state]
|
| 543 |
)
|
| 544 |
|
| 545 |
for btn in [btn1, btn2, btn3]:
|
|
|
|
| 550 |
)
|
| 551 |
|
| 552 |
back_button.click(
|
| 553 |
+
lambda x: x,
|
| 554 |
+
inputs=[initial_state],
|
| 555 |
+
outputs=[output, btn1, btn2, btn3, back_button]
|
| 556 |
)
|
| 557 |
|
| 558 |
gr.Examples(
|
|
|
|
| 562 |
|
| 563 |
gr.HTML('For more details on this project and other work, feel free to visit my GitHub <a href="https://github.com/Eric-Chung-0511/Learning-Record/tree/main/Data%20Science%20Projects/Dog_Breed_Classifier">Dog Breed Classifier</a>')
|
| 564 |
|
|
|
|
| 565 |
if __name__ == "__main__":
|
| 566 |
iface.launch()
|