Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -243,188 +243,6 @@ async def process_single_dog(image):
|
|
243 |
return breeds_info, image, initial_state
|
244 |
|
245 |
|
246 |
-
# async def predict(image):
|
247 |
-
# if image is None:
|
248 |
-
# return "Please upload an image to start.", None, None
|
249 |
-
|
250 |
-
# try:
|
251 |
-
# if isinstance(image, np.ndarray):
|
252 |
-
# image = Image.fromarray(image)
|
253 |
-
|
254 |
-
# dogs = await detect_multiple_dogs(image)
|
255 |
-
# color_list = ['#FF3B30', '#34C759', '#007AFF', '#FF9500', '#5856D6', '#FF2D55', '#5AC8FA', '#FFCC00']
|
256 |
-
# annotated_image = image.copy()
|
257 |
-
# draw = ImageDraw.Draw(annotated_image)
|
258 |
-
|
259 |
-
# try:
|
260 |
-
# font = ImageFont.truetype("arial.ttf", 24)
|
261 |
-
# except:
|
262 |
-
# font = ImageFont.load_default()
|
263 |
-
|
264 |
-
# dogs_info = ""
|
265 |
-
|
266 |
-
|
267 |
-
# for i, (cropped_image, detection_confidence, box) in enumerate(dogs):
|
268 |
-
# color = color_list[i % len(color_list)]
|
269 |
-
|
270 |
-
# # ๅชๅๅ็ไธ็ๆจ่จ
|
271 |
-
# draw.rectangle(box, outline=color, width=4)
|
272 |
-
# label = f"Dog {i+1}"
|
273 |
-
# label_bbox = draw.textbbox((0, 0), label, font=font)
|
274 |
-
# label_width = label_bbox[2] - label_bbox[0]
|
275 |
-
# label_height = label_bbox[3] - label_bbox[1]
|
276 |
-
|
277 |
-
# label_x = box[0] + 5
|
278 |
-
# label_y = box[1] + 5
|
279 |
-
# draw.rectangle(
|
280 |
-
# [label_x - 2, label_y - 2, label_x + label_width + 4, label_y + label_height + 4],
|
281 |
-
# fill='white',
|
282 |
-
# outline=color,
|
283 |
-
# width=2
|
284 |
-
# )
|
285 |
-
# draw.text((label_x, label_y), label, fill=color, font=font)
|
286 |
-
|
287 |
-
# top1_prob, topk_breeds, relative_probs = await predict_single_dog(cropped_image)
|
288 |
-
# combined_confidence = detection_confidence * top1_prob
|
289 |
-
|
290 |
-
# # ้ๅง่ณ่จๅก็
|
291 |
-
# dogs_info += f'<div class="dog-info-card" style="border-left: 6px solid {color};">'
|
292 |
-
|
293 |
-
# if combined_confidence < 0.15:
|
294 |
-
# dogs_info += f'''
|
295 |
-
# <div class="dog-info-header" style="background-color: {color}20;">
|
296 |
-
# <span class="dog-label" style="color: {color};">Dog {i+1}</span>
|
297 |
-
# </div>
|
298 |
-
# <div class="breed-info">
|
299 |
-
# <p class="warning-message">The image is unclear or the breed is not in the dataset. Please upload a clearer image.</p>
|
300 |
-
# </div>
|
301 |
-
# '''
|
302 |
-
# elif top1_prob >= 0.45:
|
303 |
-
# breed = topk_breeds[0]
|
304 |
-
# description = get_dog_description(breed)
|
305 |
-
# dogs_info += f'''
|
306 |
-
# <div class="dog-info-header" style="background-color: {color}20;">
|
307 |
-
# <span class="dog-label" style="color: {color};">{breed}</span>
|
308 |
-
# </div>
|
309 |
-
# <div class="breed-info">
|
310 |
-
# {format_description_html(description, breed)}
|
311 |
-
# </div>
|
312 |
-
# '''
|
313 |
-
# else:
|
314 |
-
# dogs_info += f'''
|
315 |
-
# <div class="dog-info-header" style="background-color: {color}20;">
|
316 |
-
# <span class="dog-label" style="color: {color};">Dog {i+1}</span>
|
317 |
-
# </div>
|
318 |
-
# <div class="breed-info">
|
319 |
-
# <div class="model-uncertainty-note">
|
320 |
-
# Note: The model is showing some uncertainty in its predictions.
|
321 |
-
# Here are the most likely breeds based on the available visual features.
|
322 |
-
# </div>
|
323 |
-
# <h3 class="breeds-title">Top 3 possible breeds:</h3>
|
324 |
-
# '''
|
325 |
-
|
326 |
-
# for j, (breed, prob) in enumerate(zip(topk_breeds, relative_probs)):
|
327 |
-
# description = get_dog_description(breed)
|
328 |
-
# dogs_info += f'''
|
329 |
-
# <div class="breed-section">
|
330 |
-
# <div class="confidence-score" style="color: {color};">{breed} (Confidence: {prob})</div>
|
331 |
-
# <div class="breed-info-content">
|
332 |
-
# {format_description_html(description, breed)}
|
333 |
-
# </div>
|
334 |
-
# </div>
|
335 |
-
# '''
|
336 |
-
# dogs_info += '</div>'
|
337 |
-
|
338 |
-
# dogs_info += '</div>'
|
339 |
-
|
340 |
-
# html_output = f"""
|
341 |
-
# <style>
|
342 |
-
# .dog-info-card {{
|
343 |
-
# border: 1px solid #ddd;
|
344 |
-
# margin-bottom: 24px;
|
345 |
-
# padding: 0;
|
346 |
-
# border-radius: 8px;
|
347 |
-
# box-shadow: 0 2px 8px rgba(0,0,0,0.1);
|
348 |
-
# overflow: hidden;
|
349 |
-
# transition: all 0.3s ease;
|
350 |
-
# }}
|
351 |
-
|
352 |
-
# .dog-info-card:hover {{
|
353 |
-
# box-shadow: 0 4px 12px rgba(0,0,0,0.15);
|
354 |
-
# }}
|
355 |
-
|
356 |
-
# .dog-info-header {{
|
357 |
-
# padding: 16px 20px;
|
358 |
-
# margin: 0;
|
359 |
-
# font-size: 20px;
|
360 |
-
# font-weight: bold;
|
361 |
-
# }}
|
362 |
-
|
363 |
-
# .dog-label {{
|
364 |
-
# font-size: 18px;
|
365 |
-
# font-weight: bold;
|
366 |
-
# }}
|
367 |
-
|
368 |
-
# .breed-info {{
|
369 |
-
# padding: 20px;
|
370 |
-
# }}
|
371 |
-
|
372 |
-
# .breeds-title {{
|
373 |
-
# margin: 0 0 16px 0;
|
374 |
-
# font-size: 18px;
|
375 |
-
# color: #333;
|
376 |
-
# }}
|
377 |
-
|
378 |
-
# .breed-section {{
|
379 |
-
# margin: 16px 0;
|
380 |
-
# padding: 16px;
|
381 |
-
# background-color: #f8f8f8;
|
382 |
-
# border-radius: 6px;
|
383 |
-
# }}
|
384 |
-
|
385 |
-
# .confidence-score {{
|
386 |
-
# font-size: 18px;
|
387 |
-
# font-weight: bold;
|
388 |
-
# margin-bottom: 12px;
|
389 |
-
# }}
|
390 |
-
|
391 |
-
# .breed-info-content {{
|
392 |
-
# margin-top: 8px;
|
393 |
-
# }}
|
394 |
-
|
395 |
-
# .warning-message {{
|
396 |
-
# color: #ff3b30;
|
397 |
-
# font-weight: bold;
|
398 |
-
# margin: 0;
|
399 |
-
# }}
|
400 |
-
|
401 |
-
# ul {{
|
402 |
-
# padding-left: 0;
|
403 |
-
# margin: 0;
|
404 |
-
# }}
|
405 |
-
|
406 |
-
# li {{
|
407 |
-
# margin-bottom: 8px;
|
408 |
-
# }}
|
409 |
-
# </style>
|
410 |
-
# {dogs_info}
|
411 |
-
# """
|
412 |
-
|
413 |
-
# initial_state = {
|
414 |
-
# "dogs_info": dogs_info,
|
415 |
-
# "image": annotated_image,
|
416 |
-
# "is_multi_dog": len(dogs) > 1,
|
417 |
-
# "html_output": html_output
|
418 |
-
# }
|
419 |
-
|
420 |
-
# return html_output, annotated_image, initial_state
|
421 |
-
|
422 |
-
# except Exception as e:
|
423 |
-
# error_msg = f"An error occurred: {str(e)}\n\nTraceback:\n{traceback.format_exc()}"
|
424 |
-
# print(error_msg)
|
425 |
-
# return error_msg, None, None
|
426 |
-
|
427 |
-
|
428 |
|
429 |
async def predict(image):
|
430 |
if image is None:
|
@@ -437,7 +255,18 @@ async def predict(image):
|
|
437 |
dogs = await detect_multiple_dogs(image)
|
438 |
# ๆดๆฐ้ก่ฒ็ตๅ
|
439 |
single_dog_color = '#34C759' # ๆธ
็ฝ็็ถ ่ฒไฝ็บๅฎ็้ก่ฒ
|
440 |
-
color_list = [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
441 |
annotated_image = image.copy()
|
442 |
draw = ImageDraw.Draw(annotated_image)
|
443 |
|
@@ -704,7 +533,7 @@ async def predict(image):
|
|
704 |
display: inline-flex;
|
705 |
align-items: center;
|
706 |
padding: 12px 24px;
|
707 |
-
background-color: #
|
708 |
color: white;
|
709 |
border-radius: 8px;
|
710 |
text-decoration: none;
|
@@ -714,7 +543,7 @@ async def predict(image):
|
|
714 |
}}
|
715 |
|
716 |
.akc-button:hover {{
|
717 |
-
background-color: #
|
718 |
transform: translateY(-1px);
|
719 |
color: white;
|
720 |
}}
|
@@ -805,7 +634,7 @@ async def predict(image):
|
|
805 |
}}
|
806 |
|
807 |
.akc-link {{
|
808 |
-
color: #
|
809 |
text-decoration: none;
|
810 |
font-weight: 500;
|
811 |
transition: all 0.3s ease;
|
@@ -813,7 +642,7 @@ async def predict(image):
|
|
813 |
|
814 |
.akc-link:hover {{
|
815 |
text-decoration: underline;
|
816 |
-
color: #
|
817 |
}}
|
818 |
</style>
|
819 |
{dogs_info}
|
|
|
243 |
return breeds_info, image, initial_state
|
244 |
|
245 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
246 |
|
247 |
async def predict(image):
|
248 |
if image is None:
|
|
|
255 |
dogs = await detect_multiple_dogs(image)
|
256 |
# ๆดๆฐ้ก่ฒ็ตๅ
|
257 |
single_dog_color = '#34C759' # ๆธ
็ฝ็็ถ ่ฒไฝ็บๅฎ็้ก่ฒ
|
258 |
+
color_list = [
|
259 |
+
'#FF5733', # ็็็ด
|
260 |
+
'#33FF57', # ่่ท็ถ
|
261 |
+
'#3357FF', # ๅฏถ่่ฒ
|
262 |
+
'#FF33F5', # ็ฒ็ดซ่ฒ
|
263 |
+
'#FFB733', # ๆฉ้ป่ฒ
|
264 |
+
'#33FFF5', # ้่่ฒ
|
265 |
+
'#A233FF', # ็ดซ่ฒ
|
266 |
+
'#FF3333', # ็ด
่ฒ
|
267 |
+
'#33FFB7', # ้็ถ ่ฒ
|
268 |
+
'#FFE033' # ้้ป่ฒ
|
269 |
+
]
|
270 |
annotated_image = image.copy()
|
271 |
draw = ImageDraw.Draw(annotated_image)
|
272 |
|
|
|
533 |
display: inline-flex;
|
534 |
align-items: center;
|
535 |
padding: 12px 24px;
|
536 |
+
background-color: #357ABD;
|
537 |
color: white;
|
538 |
border-radius: 8px;
|
539 |
text-decoration: none;
|
|
|
543 |
}}
|
544 |
|
545 |
.akc-button:hover {{
|
546 |
+
background-color: #2C6AA0;
|
547 |
transform: translateY(-1px);
|
548 |
color: white;
|
549 |
}}
|
|
|
634 |
}}
|
635 |
|
636 |
.akc-link {{
|
637 |
+
color: #357ABD;
|
638 |
text-decoration: none;
|
639 |
font-weight: 500;
|
640 |
transition: all 0.3s ease;
|
|
|
642 |
|
643 |
.akc-link:hover {{
|
644 |
text-decoration: underline;
|
645 |
+
color: #2C6AA0;
|
646 |
}}
|
647 |
</style>
|
648 |
{dogs_info}
|