Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -12,6 +12,7 @@ from data_manager import get_dog_description
|
|
12 |
from urllib.parse import quote
|
13 |
from ultralytics import YOLO
|
14 |
import asyncio
|
|
|
15 |
|
16 |
|
17 |
# 下載YOLOv8預訓練模型
|
@@ -503,6 +504,14 @@ async def process_single_dog(image):
|
|
503 |
# if __name__ == "__main__":
|
504 |
# iface.launch()
|
505 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
506 |
with gr.Blocks() as iface:
|
507 |
gr.HTML("<h1 style='text-align: center;'>🐶 Dog Breed Classifier 🔍</h1>")
|
508 |
gr.HTML("<p style='text-align: center;'>Upload a picture of a dog, and the model will predict its breed, provide detailed information, and include an extra information link!</p>")
|
@@ -514,7 +523,7 @@ with gr.Blocks() as iface:
|
|
514 |
output = gr.Markdown(label="Prediction Results")
|
515 |
|
516 |
with gr.Row():
|
517 |
-
buttons = [gr.Button(f"View More {i+1}", visible=False) for i in range(9)]
|
518 |
|
519 |
back_button = gr.Button("Back", visible=False)
|
520 |
|
@@ -534,7 +543,7 @@ with gr.Blocks() as iface:
|
|
534 |
gr.update(visible=state["show_back"]))
|
535 |
|
536 |
input_image.change(
|
537 |
-
|
538 |
inputs=input_image,
|
539 |
outputs=[output, output_image] + buttons + [back_button, initial_state]
|
540 |
)
|
|
|
12 |
from urllib.parse import quote
|
13 |
from ultralytics import YOLO
|
14 |
import asyncio
|
15 |
+
import traceback
|
16 |
|
17 |
|
18 |
# 下載YOLOv8預訓練模型
|
|
|
504 |
# if __name__ == "__main__":
|
505 |
# iface.launch()
|
506 |
|
507 |
+
def safe_predict(image):
|
508 |
+
try:
|
509 |
+
return predict(image)
|
510 |
+
except Exception as e:
|
511 |
+
error_msg = f"An error occurred: {str(e)}\n\n{traceback.format_exc()}"
|
512 |
+
print(error_msg) # 打印詳細錯誤信息到控制台
|
513 |
+
return error_msg, None, *[gr.update(visible=False) for _ in range(9)], gr.update(visible=False), None
|
514 |
+
|
515 |
with gr.Blocks() as iface:
|
516 |
gr.HTML("<h1 style='text-align: center;'>🐶 Dog Breed Classifier 🔍</h1>")
|
517 |
gr.HTML("<p style='text-align: center;'>Upload a picture of a dog, and the model will predict its breed, provide detailed information, and include an extra information link!</p>")
|
|
|
523 |
output = gr.Markdown(label="Prediction Results")
|
524 |
|
525 |
with gr.Row():
|
526 |
+
buttons = [gr.Button(f"View More {i+1}", visible=False) for i in range(9)]
|
527 |
|
528 |
back_button = gr.Button("Back", visible=False)
|
529 |
|
|
|
543 |
gr.update(visible=state["show_back"]))
|
544 |
|
545 |
input_image.change(
|
546 |
+
safe_predict,
|
547 |
inputs=input_image,
|
548 |
outputs=[output, output_image] + buttons + [back_button, initial_state]
|
549 |
)
|