Spaces:
Sleeping
Sleeping
compare to chicory-ui
Browse files
ui.py
CHANGED
@@ -68,31 +68,50 @@ def create_demo():
|
|
68 |
min-height: 600px !important;
|
69 |
overflow-y: auto !important;
|
70 |
padding: 15px !important;
|
71 |
-
border: 1px solid #
|
72 |
-
background-color: #
|
73 |
-
color: #fff !important;
|
74 |
}
|
75 |
-
|
76 |
-
background-color: #
|
|
|
|
|
|
|
77 |
}
|
78 |
-
.container { gap: 30px !important; }
|
79 |
.product-result h3 {
|
80 |
-
margin-top:
|
81 |
-
border-bottom: 2px solid #
|
82 |
-
padding-bottom:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
}
|
84 |
""", js="""
|
85 |
// Add keyboard shortcut support for Cmd+Enter (Mac) or Ctrl+Enter (Windows/Linux)
|
86 |
document.addEventListener('keydown', function(e) {
|
87 |
if ((e.metaKey || e.ctrlKey) && e.key === 'Enter') {
|
88 |
-
//
|
89 |
-
const
|
90 |
-
|
|
|
|
|
|
|
|
|
91 |
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
e.preventDefault();
|
97 |
}
|
98 |
}
|
|
|
68 |
min-height: 600px !important;
|
69 |
overflow-y: auto !important;
|
70 |
padding: 15px !important;
|
71 |
+
border: 1px solid #333 !important;
|
72 |
+
background-color: #121212 !important;
|
73 |
+
color: #fff !important;
|
74 |
}
|
75 |
+
.product-result {
|
76 |
+
background-color: #1e1e1e !important;
|
77 |
+
border-radius: 8px !important;
|
78 |
+
padding: 15px !important;
|
79 |
+
margin-bottom: 20px !important;
|
80 |
}
|
|
|
81 |
.product-result h3 {
|
82 |
+
margin-top: 5px !important;
|
83 |
+
border-bottom: 2px solid #333 !important;
|
84 |
+
padding-bottom: 8px !important;
|
85 |
+
color: #e0e0e0 !important;
|
86 |
+
}
|
87 |
+
.result-section {
|
88 |
+
margin: 15px 0 !important;
|
89 |
+
border-radius: 8px !important;
|
90 |
+
}
|
91 |
+
.result-section h4 {
|
92 |
+
color: #e0e0e0 !important;
|
93 |
+
font-size: 16px !important;
|
94 |
+
font-weight: 500 !important;
|
95 |
+
}
|
96 |
+
hr {
|
97 |
+
border-color: #333 !important;
|
98 |
}
|
99 |
""", js="""
|
100 |
// Add keyboard shortcut support for Cmd+Enter (Mac) or Ctrl+Enter (Windows/Linux)
|
101 |
document.addEventListener('keydown', function(e) {
|
102 |
if ((e.metaKey || e.ctrlKey) && e.key === 'Enter') {
|
103 |
+
// Find the active tab
|
104 |
+
const activeTabButton = document.querySelector('.tab-nav button[aria-selected="true"]');
|
105 |
+
if (!activeTabButton) return;
|
106 |
+
|
107 |
+
// Find the active tab content
|
108 |
+
const activeTabContent = document.querySelector('.tab-panel[style*="display: block"]');
|
109 |
+
if (!activeTabContent) return;
|
110 |
|
111 |
+
// Find the submit button in the active tab
|
112 |
+
const submitButton = activeTabContent.querySelector('button');
|
113 |
+
if (submitButton) {
|
114 |
+
submitButton.click();
|
115 |
e.preventDefault();
|
116 |
}
|
117 |
}
|
utils.py
CHANGED
@@ -51,47 +51,40 @@ def parse_product_file(file_path):
|
|
51 |
|
52 |
def format_categories_html(product, similarities, chicory_result=None):
|
53 |
"""Format the similarities as HTML with bootstrap styling"""
|
54 |
-
html = f"<div class='product-result'><h3>{product}</h3>"
|
55 |
|
56 |
-
# Add Chicory results with
|
57 |
-
if
|
58 |
-
html += "<
|
59 |
-
html += "<
|
60 |
-
html += "<table style='width: 100%; border-collapse: collapse; margin-bottom: 10px;'>"
|
61 |
-
html += "<tr><th style='text-align: left; padding: 8px; border-bottom: 2px solid #ddd;'>Ingredient</th>"
|
62 |
-
html += "<th style='text-align: right; padding: 8px; border-bottom: 2px solid #ddd;'>Confidence</th></tr>"
|
63 |
|
64 |
if isinstance(chicory_result, dict):
|
65 |
-
#
|
66 |
ingredient = chicory_result.get("ingredient", "Not found")
|
67 |
confidence = chicory_result.get("confidence", 0)
|
68 |
confidence_pct = int(confidence * 100) if confidence else 0
|
69 |
-
color = get_confidence_color(confidence)
|
70 |
|
71 |
-
html += f"<
|
72 |
-
html += f"<
|
73 |
-
html += f"<span style='color: {color}; font-weight: bold;'>{confidence_pct}%</span
|
74 |
-
|
75 |
-
html += "</
|
76 |
-
else:
|
77 |
-
html += "<p style='color: #757575; font-style: italic; margin: 10px 0;'>No Chicory parser results available.</p>"
|
78 |
|
79 |
-
# Add similarities with
|
80 |
if similarities:
|
81 |
-
html += "<
|
82 |
-
html += "<
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
html +=
|
90 |
-
|
91 |
-
|
92 |
-
html += "</table></div>"
|
93 |
else:
|
94 |
-
html += "<p style='color: #
|
95 |
|
96 |
html += "</div>"
|
97 |
return html
|
@@ -105,4 +98,22 @@ def get_confidence_color(score):
|
|
105 |
elif score >= 0.5:
|
106 |
return "#8bc34a" # Light green
|
107 |
else:
|
108 |
-
return "#9e9e9e" # Gray
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
def format_categories_html(product, similarities, chicory_result=None):
|
53 |
"""Format the similarities as HTML with bootstrap styling"""
|
54 |
+
html = f"<div class='product-result'><h3 style='color: #fff;'>{product}</h3>"
|
55 |
|
56 |
+
# Add Chicory results with enhanced styling
|
57 |
+
if chicory_result:
|
58 |
+
html += "<div class='result-section chicory-section' style='background-color: #1a3c6e; color: white; padding: 15px; border-radius: 5px; margin: 10px 0; box-shadow: 0 2px 4px rgba(0,0,0,0.1);'>"
|
59 |
+
html += "<h4 style='margin-top: 0; border-bottom: 1px solid rgba(255,255,255,0.3); padding-bottom: 8px;'>Chicory Parser Results</h4>"
|
|
|
|
|
|
|
60 |
|
61 |
if isinstance(chicory_result, dict):
|
62 |
+
# Extract important fields with better formatting
|
63 |
ingredient = chicory_result.get("ingredient", "Not found")
|
64 |
confidence = chicory_result.get("confidence", 0)
|
65 |
confidence_pct = int(confidence * 100) if confidence else 0
|
|
|
66 |
|
67 |
+
html += f"<div style='display: flex; justify-content: space-between; align-items: center; background-color: rgba(255,255,255,0.1); padding: 10px; border-radius: 4px;'>"
|
68 |
+
html += f"<span style='font-size: 1.1em;'>{ingredient}</span>"
|
69 |
+
html += f"<span style='background-color: {get_confidence_bg_color(confidence)}; color: {get_confidence_text_color(confidence)}; padding: 4px 8px; border-radius: 12px; font-weight: bold;'>{confidence_pct}%</span>"
|
70 |
+
html += "</div>"
|
71 |
+
html += "</div>"
|
|
|
|
|
72 |
|
73 |
+
# Add embedding similarities with matching styling
|
74 |
if similarities:
|
75 |
+
html += "<div class='result-section embedding-section' style='background-color: #263238; color: white; padding: 15px; border-radius: 5px; margin: 15px 0; box-shadow: 0 2px 4px rgba(0,0,0,0.1);'>"
|
76 |
+
html += "<h4 style='margin-top: 0; border-bottom: 1px solid rgba(255,255,255,0.3); padding-bottom: 8px;'>Embedding Similarity</h4>"
|
77 |
+
|
78 |
+
for i, (ingredient, score) in enumerate(similarities):
|
79 |
+
confidence_pct = int(score * 100)
|
80 |
+
html += f"<div style='display: flex; justify-content: space-between; align-items: center; padding: 8px; border-radius: 4px; margin: 4px 0; background-color: rgba(255,255,255,{0.07 + (i * 0.01)});'>"
|
81 |
+
html += f"<span>{ingredient}</span>"
|
82 |
+
html += f"<span style='background-color: {get_confidence_bg_color(score)}; color: {get_confidence_text_color(score)}; padding: 4px 8px; border-radius: 12px; font-weight: bold;'>{confidence_pct}%</span>"
|
83 |
+
html += "</div>"
|
84 |
+
|
85 |
+
html += "</div>"
|
|
|
86 |
else:
|
87 |
+
html += "<p style='color: #b0bec5; font-style: italic; padding: 10px; background-color: rgba(255,255,255,0.05); border-radius: 4px; margin: 10px 0;'>No similar ingredients found above the confidence threshold.</p>"
|
88 |
|
89 |
html += "</div>"
|
90 |
return html
|
|
|
98 |
elif score >= 0.5:
|
99 |
return "#8bc34a" # Light green
|
100 |
else:
|
101 |
+
return "#9e9e9e" # Gray
|
102 |
+
|
103 |
+
def get_confidence_bg_color(score):
|
104 |
+
"""Get background color for confidence badge based on score"""
|
105 |
+
if score >= 0.8:
|
106 |
+
return "#2e7d32" # Dark green
|
107 |
+
elif score >= 0.65:
|
108 |
+
return "#558b2f" # Medium green
|
109 |
+
elif score >= 0.5:
|
110 |
+
return "#9e9d24" # Light green/yellow
|
111 |
+
else:
|
112 |
+
return "#757575" # Gray
|
113 |
+
|
114 |
+
def get_confidence_text_color(score):
|
115 |
+
"""Get text color that's readable on the confidence background"""
|
116 |
+
if score >= 0.5:
|
117 |
+
return "#ffffff" # White text on dark backgrounds
|
118 |
+
else:
|
119 |
+
return "#f5f5f5" # Light gray on gray background
|