Spaces:
Sleeping
Sleeping
Commit ·
0222c13
1
Parent(s): 952bc18
Refine consumer filtering and evidence layout
Browse files275 unmodified lines276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309480 unmodified lines790791792793794795796768797798799800801802803804775776777778779780805806807808809810811812813814815816817818819820275 unmodified lines return [p["name"] for p in PRODUCTS]
def _product_names_for_category(category: str) -> List[str]: if category == "All": return _product_names() names = [p["name"] for p in PRODUCTS if p.get("category") == category] return names or _product_names()
def _tags_for_category(category: str) -> List[str]: products = PRODUCTS if category == "All" else [p for p in PRODUCTS if p.get("category") == category] return sorted({tag for p in products for tag in p.get("tags", [])})
def update_product_choices(category: str): names = _product_names_for_category(category) return gr.update(choices=names, value=names[0] if names else None)
def update_filter_tags(category: str): return gr.update(choices=_tags_for_category(category), value=[])
def consumer_category_view(category: str, selected_aspect: str): names = _product_names_for_category(category) product_name = names[0] if names else _product_names()[0] detail, aspects, evidence, rows = consumer_product_view(product_name, selected_aspect) return gr.update(choices=names, value=product_name), detail, aspects, evidence, rows
def _get_product(name: str) -> Dict[str, Any]: return next((p for p in PRODUCTS if p["name"] == name), PRODUCTS[0])
480 unmodified lines with gr.Tab("Consumer Interface"): with gr.Row(): with gr.Column(scale=4): consumer_category = gr.Dropdown(categories, value="All", label="Choose category") product_select = gr.Dropdown(_product_names(), value=_product_names()[0], label="Choose a product") consumer_aspect = gr.Dropdown(["All"] + ASPECTS, value="All", label="Highlight aspect evidence") product_detail = gr.HTML() evidence_html = gr.HTML() with gr.Column(scale=6): aspect_html = gr.HTML() evidence_html = gr.HTML() consumer_table = gr.Dataframe(headers=["Aspect", "Prediction", "Confidence", "Key review evidence"], datatype=["str", "str", "number", "str"], label="Aspect-level result table", interactive=False) with gr.Accordion("Product Finder filters", open=False): gr.HTML('<div class="compact-note">Optional: filter products by aspect sentiment, category, tags, and minimum rating.</div>') with gr.Row(): with gr.Column(scale=1): filter_aspect = gr.Dropdown(["Overall"] + ASPECTS, value="Overall", label="Target metric") filter_sentiment = gr.Radio(["Any", "Positive", "Negative", "Not_Mentioned", "Neutral"], value="Any", label="Preferred prediction") filter_category = gr.Dropdown(categories, value="All", label="Category") with gr.Row(): filter_tags = gr.CheckboxGroup(tags, label="Required metadata tags") min_rating = gr.Slider(3.0, 5.0, value=4.0, step=0.1, label="Minimum product rating") filter_aspect = gr.Dropdown(["Overall"] + ASPECTS, value="Overall", label="Target metric") filter_sentiment = gr.Radio(["Any", "Positive", "Negative", "Not_Mentioned", "Neutral"], value="Any", label="Preferred prediction") filter_category = gr.Dropdown(categories, value="All", label="Category") with gr.Column(scale=1): filter_tags = gr.CheckboxGroup(tags, label="Required metadata tags") min_rating = gr.Slider(3.0, 5.0, value=4.0, step=0.1, label="Minimum product rating") filter_btn = gr.Button("Filter Products", variant="primary") filter_summary = gr.HTML() 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") consumer_category.change(consumer_category_view, [consumer_category, consumer_aspect], [product_select, product_detail, aspect_html, evidence_html, consumer_table]) product_select.change(consumer_product_view, [product_select, consumer_aspect], [product_detail, aspect_html, evidence_html, consumer_table]) consumer_aspect.change(consumer_product_view, [product_select, consumer_aspect], [product_detail, aspect_html, evidence_html, consumer_table]) filter_category.change(update_filter_tags, filter_category, filter_tags) filter_btn.click(filter_products, [filter_aspect, filter_sentiment, filter_category, filter_tags, min_rating], [filter_table, filter_summary])
with gr.Tab("Merchant Interface"):app.py+39-7