Spaces:
Sleeping
Sleeping
Commit ·
0222c13
1
Parent(s): 952bc18
Refine consumer filtering and evidence layout
Browse files
app.py
CHANGED
|
@@ -276,6 +276,34 @@ def _product_names() -> List[str]:
|
|
| 276 |
return [p["name"] for p in PRODUCTS]
|
| 277 |
|
| 278 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 279 |
def _get_product(name: str) -> Dict[str, Any]:
|
| 280 |
return next((p for p in PRODUCTS if p["name"] == name), PRODUCTS[0])
|
| 281 |
|
|
@@ -762,27 +790,31 @@ def build_app() -> gr.Blocks:
|
|
| 762 |
with gr.Tab("Consumer Interface"):
|
| 763 |
with gr.Row():
|
| 764 |
with gr.Column(scale=4):
|
|
|
|
| 765 |
product_select = gr.Dropdown(_product_names(), value=_product_names()[0], label="Choose a product")
|
| 766 |
consumer_aspect = gr.Dropdown(["All"] + ASPECTS, value="All", label="Highlight aspect evidence")
|
| 767 |
product_detail = gr.HTML()
|
| 768 |
-
evidence_html = gr.HTML()
|
| 769 |
with gr.Column(scale=6):
|
| 770 |
aspect_html = gr.HTML()
|
|
|
|
| 771 |
consumer_table = gr.Dataframe(headers=["Aspect", "Prediction", "Confidence", "Key review evidence"], datatype=["str", "str", "number", "str"], label="Aspect-level result table", interactive=False)
|
| 772 |
with gr.Accordion("Product Finder filters", open=False):
|
| 773 |
gr.HTML('<div class="compact-note">Optional: filter products by aspect sentiment, category, tags, and minimum rating.</div>')
|
| 774 |
with gr.Row():
|
| 775 |
-
|
| 776 |
-
|
| 777 |
-
|
| 778 |
-
|
| 779 |
-
|
| 780 |
-
|
|
|
|
| 781 |
filter_btn = gr.Button("Filter Products", variant="primary")
|
| 782 |
filter_summary = gr.HTML()
|
| 783 |
filter_table = gr.Dataframe(headers=["Product", "Category", "Prediction", "Confidence", "Rating", "Price", "Metadata"], datatype=["str", "str", "str", "number", "number", "number", "str"], interactive=False, label="Filtered product candidates")
|
|
|
|
| 784 |
product_select.change(consumer_product_view, [product_select, consumer_aspect], [product_detail, aspect_html, evidence_html, consumer_table])
|
| 785 |
consumer_aspect.change(consumer_product_view, [product_select, consumer_aspect], [product_detail, aspect_html, evidence_html, consumer_table])
|
|
|
|
| 786 |
filter_btn.click(filter_products, [filter_aspect, filter_sentiment, filter_category, filter_tags, min_rating], [filter_table, filter_summary])
|
| 787 |
|
| 788 |
with gr.Tab("Merchant Interface"):
|
|
|
|
| 276 |
return [p["name"] for p in PRODUCTS]
|
| 277 |
|
| 278 |
|
| 279 |
+
def _product_names_for_category(category: str) -> List[str]:
|
| 280 |
+
if category == "All":
|
| 281 |
+
return _product_names()
|
| 282 |
+
names = [p["name"] for p in PRODUCTS if p.get("category") == category]
|
| 283 |
+
return names or _product_names()
|
| 284 |
+
|
| 285 |
+
|
| 286 |
+
def _tags_for_category(category: str) -> List[str]:
|
| 287 |
+
products = PRODUCTS if category == "All" else [p for p in PRODUCTS if p.get("category") == category]
|
| 288 |
+
return sorted({tag for p in products for tag in p.get("tags", [])})
|
| 289 |
+
|
| 290 |
+
|
| 291 |
+
def update_product_choices(category: str):
|
| 292 |
+
names = _product_names_for_category(category)
|
| 293 |
+
return gr.update(choices=names, value=names[0] if names else None)
|
| 294 |
+
|
| 295 |
+
|
| 296 |
+
def update_filter_tags(category: str):
|
| 297 |
+
return gr.update(choices=_tags_for_category(category), value=[])
|
| 298 |
+
|
| 299 |
+
|
| 300 |
+
def consumer_category_view(category: str, selected_aspect: str):
|
| 301 |
+
names = _product_names_for_category(category)
|
| 302 |
+
product_name = names[0] if names else _product_names()[0]
|
| 303 |
+
detail, aspects, evidence, rows = consumer_product_view(product_name, selected_aspect)
|
| 304 |
+
return gr.update(choices=names, value=product_name), detail, aspects, evidence, rows
|
| 305 |
+
|
| 306 |
+
|
| 307 |
def _get_product(name: str) -> Dict[str, Any]:
|
| 308 |
return next((p for p in PRODUCTS if p["name"] == name), PRODUCTS[0])
|
| 309 |
|
|
|
|
| 790 |
with gr.Tab("Consumer Interface"):
|
| 791 |
with gr.Row():
|
| 792 |
with gr.Column(scale=4):
|
| 793 |
+
consumer_category = gr.Dropdown(categories, value="All", label="Choose category")
|
| 794 |
product_select = gr.Dropdown(_product_names(), value=_product_names()[0], label="Choose a product")
|
| 795 |
consumer_aspect = gr.Dropdown(["All"] + ASPECTS, value="All", label="Highlight aspect evidence")
|
| 796 |
product_detail = gr.HTML()
|
|
|
|
| 797 |
with gr.Column(scale=6):
|
| 798 |
aspect_html = gr.HTML()
|
| 799 |
+
evidence_html = gr.HTML()
|
| 800 |
consumer_table = gr.Dataframe(headers=["Aspect", "Prediction", "Confidence", "Key review evidence"], datatype=["str", "str", "number", "str"], label="Aspect-level result table", interactive=False)
|
| 801 |
with gr.Accordion("Product Finder filters", open=False):
|
| 802 |
gr.HTML('<div class="compact-note">Optional: filter products by aspect sentiment, category, tags, and minimum rating.</div>')
|
| 803 |
with gr.Row():
|
| 804 |
+
with gr.Column(scale=1):
|
| 805 |
+
filter_aspect = gr.Dropdown(["Overall"] + ASPECTS, value="Overall", label="Target metric")
|
| 806 |
+
filter_sentiment = gr.Radio(["Any", "Positive", "Negative", "Not_Mentioned", "Neutral"], value="Any", label="Preferred prediction")
|
| 807 |
+
filter_category = gr.Dropdown(categories, value="All", label="Category")
|
| 808 |
+
with gr.Column(scale=1):
|
| 809 |
+
filter_tags = gr.CheckboxGroup(tags, label="Required metadata tags")
|
| 810 |
+
min_rating = gr.Slider(3.0, 5.0, value=4.0, step=0.1, label="Minimum product rating")
|
| 811 |
filter_btn = gr.Button("Filter Products", variant="primary")
|
| 812 |
filter_summary = gr.HTML()
|
| 813 |
filter_table = gr.Dataframe(headers=["Product", "Category", "Prediction", "Confidence", "Rating", "Price", "Metadata"], datatype=["str", "str", "str", "number", "number", "number", "str"], interactive=False, label="Filtered product candidates")
|
| 814 |
+
consumer_category.change(consumer_category_view, [consumer_category, consumer_aspect], [product_select, product_detail, aspect_html, evidence_html, consumer_table])
|
| 815 |
product_select.change(consumer_product_view, [product_select, consumer_aspect], [product_detail, aspect_html, evidence_html, consumer_table])
|
| 816 |
consumer_aspect.change(consumer_product_view, [product_select, consumer_aspect], [product_detail, aspect_html, evidence_html, consumer_table])
|
| 817 |
+
filter_category.change(update_filter_tags, filter_category, filter_tags)
|
| 818 |
filter_btn.click(filter_products, [filter_aspect, filter_sentiment, filter_category, filter_tags, min_rating], [filter_table, filter_summary])
|
| 819 |
|
| 820 |
with gr.Tab("Merchant Interface"):
|