DawnC commited on
Commit
47ad849
1 Parent(s): 6cec9b7

Update breed_recommendation.py

Browse files
Files changed (1) hide show
  1. breed_recommendation.py +31 -34
breed_recommendation.py CHANGED
@@ -460,40 +460,30 @@ def create_recommendation_tab(UserPreferences, get_breed_recommendations, format
460
  ]
461
 
462
  # 顯示初始加載訊息
463
- yield gr.HTML("""
464
- <div style="
465
- text-align: center;
466
- padding: 20px;
467
- background: rgba(255, 255, 255, 0.9);
468
- border-radius: 12px;
469
- box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
470
- margin: 20px 0;
471
- ">
472
- <div style="font-size: 1.1em; color: #4a5568; margin-bottom: 10px;">
473
- {}
474
- </div>
475
  <div style="
476
- width: 100%;
477
- height: 4px;
478
- background: #f0f0f0;
479
- border-radius: 2px;
480
- overflow: hidden;
 
481
  ">
482
- <div style="
483
- width: 30%;
484
- height: 100%;
485
- background: linear-gradient(to right, #ff8c42, #ff6b2b);
486
- animation: progress 2s infinite linear;
487
- "></div>
 
 
 
 
 
488
  </div>
489
- </div>
490
- <style>
491
- @keyframes progress {{
492
- 0% {{ transform: translateX(-100%); }}
493
- 100% {{ transform: translateX(400%); }}
494
- }}
495
- </style>
496
- """.format(loading_messages[0]))
497
 
498
  user_prefs = UserPreferences(
499
  living_space=args[0],
@@ -543,13 +533,19 @@ def create_recommendation_tab(UserPreferences, get_breed_recommendations, format
543
  results=history_results
544
  )
545
 
546
- return format_recommendation_html(recommendations, is_description_search=False)
 
547
 
548
  except Exception as e:
549
  print(f"Error in find match: {str(e)}")
550
  import traceback
551
  print(traceback.format_exc())
552
- return "Error getting recommendations"
 
 
 
 
 
553
 
554
 
555
  get_recommendations_btn.click(
@@ -568,7 +564,8 @@ def create_recommendation_tab(UserPreferences, get_breed_recommendations, format
568
  noise_tolerance
569
  ],
570
  outputs=recommendation_output,
571
- api_name=False # 支持生成器功能
 
572
  )
573
 
574
  return {
 
460
  ]
461
 
462
  # 顯示初始加載訊息
463
+ for message in loading_messages:
464
+ yield gr.HTML("""
 
 
 
 
 
 
 
 
 
 
465
  <div style="
466
+ text-align: center;
467
+ padding: 20px;
468
+ background: rgba(255, 255, 255, 0.9);
469
+ border-radius: 12px;
470
+ box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
471
+ margin: 20px 0;
472
  ">
473
+ <div style="font-size: 1.1em; color: #4a5568; margin-bottom: 10px;">
474
+ {message}
475
+ </div>
476
+ <div style="width: 100%; height: 4px; background: #f0f0f0; border-radius: 2px; overflow: hidden;">
477
+ <div style="
478
+ width: 30%;
479
+ height: 100%;
480
+ background: linear-gradient(to right, #ff8c42, #ff6b2b);
481
+ animation: progress 2s infinite linear;
482
+ "></div>
483
+ </div>
484
  </div>
485
+ """.format(message=message))
486
+ await asyncio.sleep(1) # 每個訊息顯示1秒
 
 
 
 
 
 
487
 
488
  user_prefs = UserPreferences(
489
  living_space=args[0],
 
533
  results=history_results
534
  )
535
 
536
+ final_result = format_recommendation_html(recommendations, is_description_search=False)
537
+ return final_result
538
 
539
  except Exception as e:
540
  print(f"Error in find match: {str(e)}")
541
  import traceback
542
  print(traceback.format_exc())
543
+ return gr.HTML("""
544
+ <div style="padding: 20px; background: #FEE2E2; border-radius: 8px; color: #991B1B;">
545
+ <p style="margin: 0; font-weight: 500;">Sorry, we encountered an error while processing your request.</p>
546
+ <p style="margin: 5px 0 0 0; font-size: 0.9em;">Please try again or contact support if the problem persists.</p>
547
+ </div>
548
+ """)
549
 
550
 
551
  get_recommendations_btn.click(
 
564
  noise_tolerance
565
  ],
566
  outputs=recommendation_output,
567
+ api_name=False,
568
+ queue=True
569
  )
570
 
571
  return {