Spaces:
Running
Running
Update breed_detection.py
Browse files- breed_detection.py +48 -143
breed_detection.py
CHANGED
@@ -2,151 +2,56 @@ import re
|
|
2 |
import gradio as gr
|
3 |
from PIL import Image
|
4 |
|
5 |
-
# def create_detection_tab(predict_fn, example_images):
|
6 |
-
# with gr.TabItem("Breed Detection"):
|
7 |
-
# gr.HTML("""
|
8 |
-
# <div style='
|
9 |
-
# text-align: center;
|
10 |
-
# padding: 20px 0;
|
11 |
-
# margin: 15px 0;
|
12 |
-
# background: linear-gradient(to right, rgba(66, 153, 225, 0.1), rgba(72, 187, 120, 0.1));
|
13 |
-
# border-radius: 10px;
|
14 |
-
# '>
|
15 |
-
# <p style='
|
16 |
-
# font-size: 1.2em;
|
17 |
-
# margin: 0;
|
18 |
-
# padding: 0 20px;
|
19 |
-
# line-height: 1.5;
|
20 |
-
# background: linear-gradient(90deg, #4299e1, #48bb78);
|
21 |
-
# -webkit-background-clip: text;
|
22 |
-
# -webkit-text-fill-color: transparent;
|
23 |
-
# font-weight: 600;
|
24 |
-
# '>
|
25 |
-
# Upload a picture of a dog, and the model will predict its breed and provide detailed information!
|
26 |
-
# </p>
|
27 |
-
# <p style='
|
28 |
-
# font-size: 0.9em;
|
29 |
-
# color: #666;
|
30 |
-
# margin-top: 8px;
|
31 |
-
# padding: 0 20px;
|
32 |
-
# '>
|
33 |
-
# Note: The model's predictions may not always be 100% accurate, and it is recommended to use the results as a reference.
|
34 |
-
# </p>
|
35 |
-
# </div>
|
36 |
-
# """)
|
37 |
-
|
38 |
-
# with gr.Row():
|
39 |
-
# input_image = gr.Image(label="Upload a dog image", type="pil")
|
40 |
-
# output_image = gr.Image(label="Annotated Image")
|
41 |
-
|
42 |
-
# output = gr.HTML(label="Prediction Results")
|
43 |
-
# initial_state = gr.State()
|
44 |
-
|
45 |
-
# input_image.change(
|
46 |
-
# predict_fn,
|
47 |
-
# inputs=input_image,
|
48 |
-
# outputs=[output, output_image, initial_state]
|
49 |
-
# )
|
50 |
-
|
51 |
-
# gr.Examples(
|
52 |
-
# examples=example_images,
|
53 |
-
# inputs=input_image
|
54 |
-
# )
|
55 |
-
|
56 |
-
# return {
|
57 |
-
# 'input_image': input_image,
|
58 |
-
# 'output_image': output_image,
|
59 |
-
# 'output': output,
|
60 |
-
# 'initial_state': initial_state
|
61 |
-
# }
|
62 |
-
|
63 |
-
|
64 |
def create_detection_tab(predict_fn, example_images):
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
position: relative !important;
|
84 |
-
}
|
85 |
-
|
86 |
-
/* 被選中的標籤樣式 */
|
87 |
-
.tab-nav button.selected {
|
88 |
-
color: #4299e1 !important;
|
89 |
-
border-bottom: 2px solid #4299e1 !important;
|
90 |
-
background: linear-gradient(to bottom, rgba(66, 153, 225, 0.1), transparent) !important;
|
91 |
-
}
|
92 |
-
|
93 |
-
/* hover 效果 */
|
94 |
-
.tab-nav button:hover {
|
95 |
-
color: #4299e1 !important;
|
96 |
-
background: rgba(66, 153, 225, 0.05) !important;
|
97 |
-
}
|
98 |
-
"""
|
99 |
-
|
100 |
-
with gr.Blocks(css=custom_css) as detection_tab:
|
101 |
-
with gr.TabItem("Breed Detection"):
|
102 |
-
gr.HTML("""
|
103 |
-
<div style='
|
104 |
-
text-align: center;
|
105 |
-
padding: 20px 0;
|
106 |
-
margin: 15px 0;
|
107 |
-
background: linear-gradient(to right, rgba(66, 153, 225, 0.1), rgba(72, 187, 120, 0.1));
|
108 |
-
border-radius: 10px;
|
109 |
'>
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
input_image.change(
|
141 |
-
predict_fn,
|
142 |
-
inputs=input_image,
|
143 |
-
outputs=[output, output_image, initial_state]
|
144 |
-
)
|
145 |
-
|
146 |
-
gr.Examples(
|
147 |
-
examples=example_images,
|
148 |
-
inputs=input_image
|
149 |
-
)
|
150 |
|
151 |
return {
|
152 |
'input_image': input_image,
|
|
|
2 |
import gradio as gr
|
3 |
from PIL import Image
|
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
def create_detection_tab(predict_fn, example_images):
|
6 |
+
with gr.TabItem("Breed Detection"):
|
7 |
+
gr.HTML("""
|
8 |
+
<div style='
|
9 |
+
text-align: center;
|
10 |
+
padding: 20px 0;
|
11 |
+
margin: 15px 0;
|
12 |
+
background: linear-gradient(to right, rgba(66, 153, 225, 0.1), rgba(72, 187, 120, 0.1));
|
13 |
+
border-radius: 10px;
|
14 |
+
'>
|
15 |
+
<p style='
|
16 |
+
font-size: 1.2em;
|
17 |
+
margin: 0;
|
18 |
+
padding: 0 20px;
|
19 |
+
line-height: 1.5;
|
20 |
+
background: linear-gradient(90deg, #4299e1, #48bb78);
|
21 |
+
-webkit-background-clip: text;
|
22 |
+
-webkit-text-fill-color: transparent;
|
23 |
+
font-weight: 600;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
'>
|
25 |
+
Upload a picture of a dog, and the model will predict its breed and provide detailed information!
|
26 |
+
</p>
|
27 |
+
<p style='
|
28 |
+
font-size: 0.9em;
|
29 |
+
color: #666;
|
30 |
+
margin-top: 8px;
|
31 |
+
padding: 0 20px;
|
32 |
+
'>
|
33 |
+
Note: The model's predictions may not always be 100% accurate, and it is recommended to use the results as a reference.
|
34 |
+
</p>
|
35 |
+
</div>
|
36 |
+
""")
|
37 |
+
|
38 |
+
with gr.Row():
|
39 |
+
input_image = gr.Image(label="Upload a dog image", type="pil")
|
40 |
+
output_image = gr.Image(label="Annotated Image")
|
41 |
+
|
42 |
+
output = gr.HTML(label="Prediction Results")
|
43 |
+
initial_state = gr.State()
|
44 |
+
|
45 |
+
input_image.change(
|
46 |
+
predict_fn,
|
47 |
+
inputs=input_image,
|
48 |
+
outputs=[output, output_image, initial_state]
|
49 |
+
)
|
50 |
+
|
51 |
+
gr.Examples(
|
52 |
+
examples=example_images,
|
53 |
+
inputs=input_image
|
54 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
|
56 |
return {
|
57 |
'input_image': input_image,
|