Spaces:
Sleeping
Sleeping
compare to chicory-ui
Browse files- __pycache__/chicory_api.cpython-313.pyc +0 -0
- __pycache__/embeddings.cpython-313.pyc +0 -0
- __pycache__/similarity.cpython-313.pyc +0 -0
- __pycache__/ui.cpython-313.pyc +0 -0
- __pycache__/utils.cpython-313.pyc +0 -0
- ui.py +40 -12
- utils.py +24 -29
__pycache__/chicory_api.cpython-313.pyc
ADDED
Binary file (1.91 kB). View file
|
|
__pycache__/embeddings.cpython-313.pyc
ADDED
Binary file (2.93 kB). View file
|
|
__pycache__/similarity.cpython-313.pyc
ADDED
Binary file (2.3 kB). View file
|
|
__pycache__/ui.cpython-313.pyc
ADDED
Binary file (5.09 kB). View file
|
|
__pycache__/utils.cpython-313.pyc
ADDED
Binary file (5.87 kB). View file
|
|
ui.py
CHANGED
@@ -55,27 +55,55 @@ def categorize_products(product_input, is_file=False, top_n=5, confidence_thresh
|
|
55 |
|
56 |
def create_demo():
|
57 |
"""Create the Gradio interface"""
|
58 |
-
with gr.Blocks(
|
|
|
|
|
|
|
|
|
59 |
gr.Markdown("# Product Categorization Tool\nAnalyze products and find the most similar ingredients using AI embeddings.")
|
60 |
-
|
61 |
with gr.Tabs():
|
62 |
with gr.TabItem("Text Input"):
|
63 |
-
|
64 |
-
|
65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
fn=categorize_products,
|
67 |
-
inputs=[text_input, gr.State(False),
|
68 |
outputs=text_output
|
69 |
)
|
70 |
-
|
71 |
with gr.TabItem("File Upload"):
|
72 |
-
|
73 |
-
|
74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
fn=categorize_products,
|
76 |
-
inputs=[file_input, gr.State(True),
|
77 |
outputs=file_output
|
78 |
)
|
79 |
-
|
80 |
gr.Markdown("Powered by Voyage AI embeddings • Built with Gradio")
|
81 |
return demo
|
|
|
55 |
|
56 |
def create_demo():
|
57 |
"""Create the Gradio interface"""
|
58 |
+
with gr.Blocks(css="""
|
59 |
+
.results-container { min-height: 400px; }
|
60 |
+
.chicory-result { visibility: visible !important; display: block !important; }
|
61 |
+
.container { gap: 20px; }
|
62 |
+
""") as demo:
|
63 |
gr.Markdown("# Product Categorization Tool\nAnalyze products and find the most similar ingredients using AI embeddings.")
|
64 |
+
|
65 |
with gr.Tabs():
|
66 |
with gr.TabItem("Text Input"):
|
67 |
+
with gr.Row():
|
68 |
+
with gr.Column(scale=1):
|
69 |
+
# Input section
|
70 |
+
text_input = gr.Textbox(lines=10, placeholder="Enter product names, one per line", label="Product Names")
|
71 |
+
input_controls = gr.Row()
|
72 |
+
with input_controls:
|
73 |
+
top_n = gr.Slider(1, 10, 5, label="Top N Results")
|
74 |
+
confidence = gr.Slider(0.1, 0.9, 0.5, label="Confidence Threshold")
|
75 |
+
categorize_btn = gr.Button("Categorize")
|
76 |
+
|
77 |
+
with gr.Column(scale=1):
|
78 |
+
# Results section
|
79 |
+
text_output = gr.HTML(label="Categorization Results", elem_classes="results-container")
|
80 |
+
|
81 |
+
categorize_btn.click(
|
82 |
fn=categorize_products,
|
83 |
+
inputs=[text_input, gr.State(False), top_n, confidence],
|
84 |
outputs=text_output
|
85 |
)
|
86 |
+
|
87 |
with gr.TabItem("File Upload"):
|
88 |
+
with gr.Row():
|
89 |
+
with gr.Column(scale=1):
|
90 |
+
# Input section
|
91 |
+
file_input = gr.File(label="Upload JSON or text file with products", file_types=[".json", ".txt"])
|
92 |
+
file_controls = gr.Row()
|
93 |
+
with file_controls:
|
94 |
+
file_top_n = gr.Slider(1, 10, 5, label="Top N Results")
|
95 |
+
file_confidence = gr.Slider(0.1, 0.9, 0.5, label="Confidence Threshold")
|
96 |
+
process_btn = gr.Button("Process File")
|
97 |
+
|
98 |
+
with gr.Column(scale=1):
|
99 |
+
# Results section
|
100 |
+
file_output = gr.HTML(label="Categorization Results", elem_classes="results-container")
|
101 |
+
|
102 |
+
process_btn.click(
|
103 |
fn=categorize_products,
|
104 |
+
inputs=[file_input, gr.State(True), file_top_n, file_confidence],
|
105 |
outputs=file_output
|
106 |
)
|
107 |
+
|
108 |
gr.Markdown("Powered by Voyage AI embeddings • Built with Gradio")
|
109 |
return demo
|
utils.py
CHANGED
@@ -49,38 +49,33 @@ def parse_product_file(file_path):
|
|
49 |
|
50 |
return product_names
|
51 |
|
52 |
-
def format_categories_html(product,
|
53 |
-
"""Format
|
54 |
-
html = f"<div
|
55 |
|
56 |
-
# Add Chicory
|
57 |
if chicory_result:
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
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 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
|
|
|
|
|
|
|
|
84 |
|
85 |
html += "</div>"
|
86 |
return html
|
|
|
49 |
|
50 |
return product_names
|
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 explicit visibility classes
|
57 |
if chicory_result:
|
58 |
+
html += "<div class='chicory-result' style='visibility: visible; display: block;'>"
|
59 |
+
html += "<h4>Chicory Parser Results:</h4>"
|
60 |
+
html += "<ul>"
|
61 |
+
for ingredient in chicory_result:
|
62 |
+
html += f"<li>{ingredient}</li>"
|
63 |
+
html += "</ul></div>"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
|
65 |
+
# Add similarities
|
66 |
+
if similarities:
|
67 |
+
html += "<h4>Similar Ingredients:</h4>"
|
68 |
+
html += "<table style='width: 100%; border-collapse: collapse;'>"
|
69 |
+
html += "<tr><th style='text-align: left; padding: 8px;'>Ingredient</th><th style='text-align: right; padding: 8px;'>Confidence</th></tr>"
|
70 |
+
for ingredient, score in similarities:
|
71 |
+
# Format score as percentage with color gradient based on confidence
|
72 |
+
confidence = int(score * 100)
|
73 |
+
color = f"hsl({min(confidence, 100) * 1.2}, 70%, 45%)"
|
74 |
+
html += f"<tr><td style='padding: 8px;'>{ingredient}</td>"
|
75 |
+
html += f"<td style='text-align: right; padding: 8px;'><span style='color: {color}; font-weight: bold;'>{confidence}%</span></td></tr>"
|
76 |
+
html += "</table>"
|
77 |
+
else:
|
78 |
+
html += "<p>No similar ingredients found.</p>"
|
79 |
|
80 |
html += "</div>"
|
81 |
return html
|