Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -314,13 +314,13 @@ async def predict(image):
|
|
314 |
if len(dogs) <= 1:
|
315 |
# Single dog or no dog detected, use the original method
|
316 |
top1_prob, topk_breeds, topk_probs_percent = await predict_single_dog(image)
|
317 |
-
return process_single_dog_result(top1_prob, topk_breeds, topk_probs_percent, image)
|
318 |
else:
|
319 |
# Multiple dogs detected
|
320 |
-
return process_multiple_dogs_result(dogs, image)
|
321 |
|
322 |
except Exception as e:
|
323 |
-
return f"An error occurred: {e}", None, gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
|
324 |
|
325 |
async def process_single_dog_result(top1_prob, topk_breeds, topk_probs_percent, image):
|
326 |
if top1_prob >= 0.5:
|
@@ -391,7 +391,6 @@ async def show_details(choice):
|
|
391 |
except Exception as e:
|
392 |
return f"An error occurred while showing details: {e}"
|
393 |
|
394 |
-
# Gradio 介面設置
|
395 |
with gr.Blocks(css="""
|
396 |
.container { max-width: 900px; margin: auto; padding: 20px; }
|
397 |
.gr-box { border-radius: 15px; }
|
@@ -411,9 +410,17 @@ with gr.Blocks(css="""
|
|
411 |
breed_buttons = gr.Radio([], label="Select breed for more details", visible=False)
|
412 |
breed_details = gr.Markdown(label="Breed Details")
|
413 |
|
|
|
|
|
|
|
414 |
input_image.change(
|
415 |
predict,
|
416 |
inputs=input_image,
|
|
|
|
|
|
|
|
|
|
|
417 |
outputs=[output, output_image, breed_buttons, breed_details]
|
418 |
)
|
419 |
|
|
|
314 |
if len(dogs) <= 1:
|
315 |
# Single dog or no dog detected, use the original method
|
316 |
top1_prob, topk_breeds, topk_probs_percent = await predict_single_dog(image)
|
317 |
+
return await process_single_dog_result(top1_prob, topk_breeds, topk_probs_percent, image)
|
318 |
else:
|
319 |
# Multiple dogs detected
|
320 |
+
return await process_multiple_dogs_result(dogs, image)
|
321 |
|
322 |
except Exception as e:
|
323 |
+
return f"An error occurred: {str(e)}", None, gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
|
324 |
|
325 |
async def process_single_dog_result(top1_prob, topk_breeds, topk_probs_percent, image):
|
326 |
if top1_prob >= 0.5:
|
|
|
391 |
except Exception as e:
|
392 |
return f"An error occurred while showing details: {e}"
|
393 |
|
|
|
394 |
with gr.Blocks(css="""
|
395 |
.container { max-width: 900px; margin: auto; padding: 20px; }
|
396 |
.gr-box { border-radius: 15px; }
|
|
|
410 |
breed_buttons = gr.Radio([], label="Select breed for more details", visible=False)
|
411 |
breed_details = gr.Markdown(label="Breed Details")
|
412 |
|
413 |
+
def handle_error(error):
|
414 |
+
return str(error), None, gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
|
415 |
+
|
416 |
input_image.change(
|
417 |
predict,
|
418 |
inputs=input_image,
|
419 |
+
outputs=[output, output_image, breed_buttons, breed_details],
|
420 |
+
api_name="predict"
|
421 |
+
).catch(
|
422 |
+
fn=handle_error,
|
423 |
+
inputs=None,
|
424 |
outputs=[output, output_image, breed_buttons, breed_details]
|
425 |
)
|
426 |
|