Spaces:
Running
Running
Update product_search.py
Browse files- product_search.py +21 -3
product_search.py
CHANGED
|
@@ -549,6 +549,24 @@ _PROGRESS_HTML = """
|
|
| 549 |
"""
|
| 550 |
|
| 551 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 552 |
def _build_card(row: pd.Series, show_relevance: bool) -> str:
|
| 553 |
name = html_escape(row["name"])
|
| 554 |
category = html_escape(row["category"])
|
|
@@ -601,10 +619,10 @@ def _build_card(row: pd.Series, show_relevance: bool) -> str:
|
|
| 601 |
def build_modal_html(products: pd.DataFrame, subtitle: str, show_relevance: bool = False) -> str:
|
| 602 |
cards_html = "\n".join(_build_card(row, show_relevance) for _, row in products.iterrows())
|
| 603 |
|
| 604 |
-
css = _BASE_CSS
|
| 605 |
progress_html = ""
|
| 606 |
if CLOSE_DELAY_SECONDS and CLOSE_DELAY_SECONDS > 0:
|
| 607 |
-
css += _LOCK_CSS.replace("__DELAY__", str(int(CLOSE_DELAY_SECONDS)))
|
| 608 |
progress_html = _PROGRESS_HTML
|
| 609 |
|
| 610 |
return f"""
|
|
@@ -703,4 +721,4 @@ if __name__ == "__main__":
|
|
| 703 |
],
|
| 704 |
},
|
| 705 |
}
|
| 706 |
-
print(debug_search(sample))
|
|
|
|
| 549 |
"""
|
| 550 |
|
| 551 |
|
| 552 |
+
_SCOPE = "#affiliate-modal-container"
|
| 553 |
+
|
| 554 |
+
|
| 555 |
+
def _scope_css(css: str) -> str:
|
| 556 |
+
"""
|
| 557 |
+
Awali setiap selector berbasis class dengan #affiliate-modal-container.
|
| 558 |
+
Gradio membungkus gr.HTML dalam `.prose` dan memaksa warna teks tema lewat
|
| 559 |
+
`.gradio-container-x .prose *` (spesifisitas 0,2,0). Selector satu class
|
| 560 |
+
(0,1,0) kalah, sehingga teks modal jadi pucat. Dengan prefix ID (1,x,0)
|
| 561 |
+
warna modal menang tanpa memakai !important di mana-mana.
|
| 562 |
+
"""
|
| 563 |
+
return re.sub(
|
| 564 |
+
r"(?m)^(\s*)(\.[^{}\n]+)\{",
|
| 565 |
+
lambda m: f"{m.group(1)}{_SCOPE} {m.group(2)}{{",
|
| 566 |
+
css,
|
| 567 |
+
)
|
| 568 |
+
|
| 569 |
+
|
| 570 |
def _build_card(row: pd.Series, show_relevance: bool) -> str:
|
| 571 |
name = html_escape(row["name"])
|
| 572 |
category = html_escape(row["category"])
|
|
|
|
| 619 |
def build_modal_html(products: pd.DataFrame, subtitle: str, show_relevance: bool = False) -> str:
|
| 620 |
cards_html = "\n".join(_build_card(row, show_relevance) for _, row in products.iterrows())
|
| 621 |
|
| 622 |
+
css = _scope_css(_BASE_CSS)
|
| 623 |
progress_html = ""
|
| 624 |
if CLOSE_DELAY_SECONDS and CLOSE_DELAY_SECONDS > 0:
|
| 625 |
+
css += _scope_css(_LOCK_CSS.replace("__DELAY__", str(int(CLOSE_DELAY_SECONDS))))
|
| 626 |
progress_html = _PROGRESS_HTML
|
| 627 |
|
| 628 |
return f"""
|
|
|
|
| 721 |
],
|
| 722 |
},
|
| 723 |
}
|
| 724 |
+
print(debug_search(sample))
|