import re import gradio as gr from PIL import Image # def create_detection_tab(predict_fn, example_images): # with gr.TabItem("Breed Detection"): # gr.HTML(""" #
#

# Upload a picture of a dog, and the model will predict its breed and provide detailed information! #

#

# Note: The model's predictions may not always be 100% accurate, and it is recommended to use the results as a reference. #

#
# """) # with gr.Row(): # input_image = gr.Image(label="Upload a dog image", type="pil") # output_image = gr.Image(label="Annotated Image") # output = gr.HTML(label="Prediction Results") # initial_state = gr.State() # input_image.change( # predict_fn, # inputs=input_image, # outputs=[output, output_image, initial_state] # ) # gr.Examples( # examples=example_images, # inputs=input_image # ) # return { # 'input_image': input_image, # 'output_image': output_image, # 'output': output, # 'initial_state': initial_state # } def create_detection_tab(predict_fn, example_images): # 首先定義CSS樣式 custom_css = """ /* 標籤樣式 */ .tab-nav { padding: 0 !important; margin-bottom: 20px !important; border-bottom: 1px solid #e2e8f0 !important; } /* 所有標籤的基本樣式 */ .tab-nav button { padding: 12px 16px !important; margin: 0 8px !important; font-size: 1.1em !important; font-weight: 500 !important; transition: all 0.3s ease !important; border-bottom: 2px solid transparent !important; background: none !important; position: relative !important; } /* 被選中的標籤樣式 */ .tab-nav button.selected { color: #4299e1 !important; border-bottom: 2px solid #4299e1 !important; background: linear-gradient(to bottom, rgba(66, 153, 225, 0.1), transparent) !important; } /* hover 效果 */ .tab-nav button:hover { color: #4299e1 !important; background: rgba(66, 153, 225, 0.05) !important; } """ with gr.Blocks(css=custom_css) as detection_tab: with gr.TabItem("Breed Detection"): gr.HTML("""

Upload a picture of a dog, and the model will predict its breed and provide detailed information!

Note: The model's predictions may not always be 100% accurate, and it is recommended to use the results as a reference.

""") with gr.Row(): input_image = gr.Image(label="Upload a dog image", type="pil") output_image = gr.Image(label="Annotated Image") output = gr.HTML(label="Prediction Results") initial_state = gr.State() input_image.change( predict_fn, inputs=input_image, outputs=[output, output_image, initial_state] ) gr.Examples( examples=example_images, inputs=input_image ) return { 'input_image': input_image, 'output_image': output_image, 'output': output, 'initial_state': initial_state }