Spaces:
Running
on
Zero
Running
on
Zero
Update recommendation_html_format.py
Browse files- recommendation_html_format.py +19 -10
recommendation_html_format.py
CHANGED
@@ -70,26 +70,35 @@ def format_recommendation_html(recommendations: List[Dict], is_description_searc
|
|
70 |
# return min(100, max(20, width))
|
71 |
|
72 |
def _generate_progress_bar(score: float) -> float:
|
73 |
-
"""
|
74 |
-
|
75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
|
77 |
-
#
|
78 |
if score > 0.9:
|
79 |
-
#
|
80 |
width = 90 + (score - 0.9) * 100
|
81 |
elif score > 0.7:
|
82 |
# 中高分區間稍微展開
|
83 |
width = 70 + (score - 0.7) * 100
|
84 |
else:
|
85 |
-
#
|
86 |
-
width =
|
87 |
|
88 |
-
#
|
89 |
import random
|
90 |
-
width += random.uniform(-
|
91 |
|
92 |
-
|
|
|
93 |
|
94 |
html_content = "<div class='recommendations-container'>"
|
95 |
|
|
|
70 |
# return min(100, max(20, width))
|
71 |
|
72 |
def _generate_progress_bar(score: float) -> float:
|
73 |
+
"""
|
74 |
+
優化進度條寬度計算
|
75 |
+
|
76 |
+
改進:
|
77 |
+
- 確保100%時完全填滿
|
78 |
+
- 更線性的視覺呈現
|
79 |
+
- 保持合理的視覺比例
|
80 |
+
"""
|
81 |
+
# 基礎寬度計算
|
82 |
+
if score >= 1.0:
|
83 |
+
return 100.0 # 確保100%時完全填滿
|
84 |
|
85 |
+
# 一般情況的寬度計算
|
86 |
if score > 0.9:
|
87 |
+
# 高分區間線性延伸
|
88 |
width = 90 + (score - 0.9) * 100
|
89 |
elif score > 0.7:
|
90 |
# 中高分區間稍微展開
|
91 |
width = 70 + (score - 0.7) * 100
|
92 |
else:
|
93 |
+
# 基礎線性關係
|
94 |
+
width = score * 100
|
95 |
|
96 |
+
# 加入微小的隨機變化,使顯示更自然
|
97 |
import random
|
98 |
+
width += random.uniform(-0.5, 0.5)
|
99 |
|
100 |
+
# 確保範圍合理
|
101 |
+
return min(99.5, max(20, width)) if score < 1.0 else 100.0
|
102 |
|
103 |
html_content = "<div class='recommendations-container'>"
|
104 |
|