Spaces:
Sleeping
Sleeping
compare to chicory-ui
Browse files
utils.py
CHANGED
@@ -49,10 +49,28 @@ def parse_product_file(file_path):
|
|
49 |
|
50 |
return product_names
|
51 |
|
52 |
-
def format_categories_html(product, categories):
|
53 |
-
"""Format categories as HTML with color-coded confidence scores"""
|
54 |
html = f"<div style='margin-bottom: 10px;'><b>{product}</b></div>"
|
55 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
if not categories:
|
57 |
html += "<div style='color: #666; font-style: italic;'>No matching categories found.</div>"
|
58 |
return html
|
@@ -60,16 +78,20 @@ def format_categories_html(product, categories):
|
|
60 |
html += "<div style='margin-left: 15px;'>"
|
61 |
for i, (category, score) in enumerate(categories, 1):
|
62 |
# Color code based on confidence
|
63 |
-
|
64 |
-
color = "#1a8a38" # Strong green
|
65 |
-
elif score >= 0.65:
|
66 |
-
color = "#4caf50" # Medium green
|
67 |
-
elif score >= 0.5:
|
68 |
-
color = "#8bc34a" # Light green
|
69 |
-
else:
|
70 |
-
color = "#9e9e9e" # Gray
|
71 |
|
72 |
html += f"<div style='margin-bottom: 5px;'>{i}. <span style='font-weight: 500;'>{category}</span> <span style='color: {color}; font-weight: bold;'>({score:.3f})</span></div>"
|
73 |
|
74 |
html += "</div>"
|
75 |
return html
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
|
50 |
return product_names
|
51 |
|
52 |
+
def format_categories_html(product, categories, chicory_result=None):
|
53 |
+
"""Format categories as HTML with color-coded confidence scores and optional Chicory comparison"""
|
54 |
html = f"<div style='margin-bottom: 10px;'><b>{product}</b></div>"
|
55 |
|
56 |
+
# Add Chicory result if available
|
57 |
+
if chicory_result:
|
58 |
+
chicory_status = chicory_result.get("status", "UNKNOWN")
|
59 |
+
chicory_confidence = chicory_result.get("confidence", 0)
|
60 |
+
chicory_ingredient = chicory_result.get("ingredient", "Unknown")
|
61 |
+
|
62 |
+
status_color = "#4caf50" if chicory_status == "SUCCESS" else "#f44336"
|
63 |
+
confidence_color = get_confidence_color(chicory_confidence)
|
64 |
+
|
65 |
+
html += f"""
|
66 |
+
<div style='margin-bottom: 15px; padding: 10px; background-color: #f5f5f5; border-left: 4px solid {status_color}; border-radius: 4px;'>
|
67 |
+
<div style='font-weight: bold; margin-bottom: 5px;'>Chicory Parser Result:</div>
|
68 |
+
<div>Matched Ingredient: <span style='font-weight: 500;'>{chicory_ingredient}</span></div>
|
69 |
+
<div>Confidence: <span style='color: {confidence_color}; font-weight: bold;'>{chicory_confidence:.3f}</span></div>
|
70 |
+
<div>Status: <span style='color: {status_color};'>{chicory_status}</span></div>
|
71 |
+
</div>
|
72 |
+
"""
|
73 |
+
|
74 |
if not categories:
|
75 |
html += "<div style='color: #666; font-style: italic;'>No matching categories found.</div>"
|
76 |
return html
|
|
|
78 |
html += "<div style='margin-left: 15px;'>"
|
79 |
for i, (category, score) in enumerate(categories, 1):
|
80 |
# Color code based on confidence
|
81 |
+
color = get_confidence_color(score)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
|
83 |
html += f"<div style='margin-bottom: 5px;'>{i}. <span style='font-weight: 500;'>{category}</span> <span style='color: {color}; font-weight: bold;'>({score:.3f})</span></div>"
|
84 |
|
85 |
html += "</div>"
|
86 |
return html
|
87 |
+
|
88 |
+
def get_confidence_color(score):
|
89 |
+
"""Get color based on confidence score"""
|
90 |
+
if score >= 0.8:
|
91 |
+
return "#1a8a38" # Strong green
|
92 |
+
elif score >= 0.65:
|
93 |
+
return "#4caf50" # Medium green
|
94 |
+
elif score >= 0.5:
|
95 |
+
return "#8bc34a" # Light green
|
96 |
+
else:
|
97 |
+
return "#9e9e9e" # Gray
|