Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
ubi integration
Browse files- pages/Semantic_Search.py +35 -24
pages/Semantic_Search.py
CHANGED
|
@@ -785,6 +785,7 @@ def render_answer(answer,index):
|
|
| 785 |
placeholder_no_results = st.empty()
|
| 786 |
|
| 787 |
col_1, col_2,col_3 = st.columns([70,10,20])
|
|
|
|
| 788 |
i = 0
|
| 789 |
filter_out = 0
|
| 790 |
if len(answer) == 0:
|
|
@@ -869,30 +870,40 @@ def render_answer(answer,index):
|
|
| 869 |
item_id = ans['id'] # use a real ID if available
|
| 870 |
expander_key = f"expander_{item_id}"
|
| 871 |
opened_key = f"{item_id}_opened"
|
| 872 |
-
|
| 873 |
-
|
| 874 |
-
|
| 875 |
-
|
| 876 |
-
|
| 877 |
-
st.
|
| 878 |
-
|
| 879 |
-
|
| 880 |
-
|
| 881 |
-
|
| 882 |
-
|
| 883 |
-
|
| 884 |
-
|
| 885 |
-
|
| 886 |
-
|
| 887 |
-
|
| 888 |
-
"
|
| 889 |
-
|
| 890 |
-
|
| 891 |
-
|
| 892 |
-
|
| 893 |
-
|
| 894 |
-
|
| 895 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 896 |
with inner_col_1:
|
| 897 |
|
| 898 |
if(st.session_state.input_evaluate == "enabled"):
|
|
|
|
| 785 |
placeholder_no_results = st.empty()
|
| 786 |
|
| 787 |
col_1, col_2,col_3 = st.columns([70,10,20])
|
| 788 |
+
lambda_url = "https://npf3wa47evhz44ee7us4gozomi0gcvkn.lambda-url.us-west-2.on.aws/"
|
| 789 |
i = 0
|
| 790 |
filter_out = 0
|
| 791 |
if len(answer) == 0:
|
|
|
|
| 870 |
item_id = ans['id'] # use a real ID if available
|
| 871 |
expander_key = f"expander_{item_id}"
|
| 872 |
opened_key = f"{item_id}_opened"
|
| 873 |
+
|
| 874 |
+
with expander:
|
| 875 |
+
st.write(":green[default:]")
|
| 876 |
+
st.json({"category:":ans['category'],"price":str(ans['price']),"gender_affinity":ans['gender_affinity'],"style":ans['style']},expanded = True)
|
| 877 |
+
if("rekog" in ans):
|
| 878 |
+
st.write(":green[enriched:]")
|
| 879 |
+
st.json(ans['rekog'],expanded = True)
|
| 880 |
+
# Inject the hidden div for JS to hook into
|
| 881 |
+
components.html(f"""
|
| 882 |
+
<div id="{doc_id}" onclick="sendEvent('{doc_id}')"></div>
|
| 883 |
+
|
| 884 |
+
<script>
|
| 885 |
+
function sendEvent(itemId) {{
|
| 886 |
+
fetch("{lambda_url}", {{
|
| 887 |
+
method: "POST",
|
| 888 |
+
headers: {{
|
| 889 |
+
"Content-Type": "application/json"
|
| 890 |
+
}},
|
| 891 |
+
body: JSON.stringify({{
|
| 892 |
+
action_name: "expander_open",
|
| 893 |
+
item_id: itemId,
|
| 894 |
+
session_id: "{st.session_state.get('session_id', 'unknown')}",
|
| 895 |
+
query_id: "{st.session_state.get('query_id', 'unknown')}",
|
| 896 |
+
timestamp: new Date().toISOString(),
|
| 897 |
+
message_type: "INFO",
|
| 898 |
+
message: "Expander opened for item " + itemId
|
| 899 |
+
}})
|
| 900 |
+
}}).then(response => console.log("Event sent for", itemId));
|
| 901 |
+
}}
|
| 902 |
+
|
| 903 |
+
// Automatically trigger click when the expander is opened
|
| 904 |
+
document.getElementById("{doc_id}").click();
|
| 905 |
+
</script>
|
| 906 |
+
""", height=0)
|
| 907 |
with inner_col_1:
|
| 908 |
|
| 909 |
if(st.session_state.input_evaluate == "enabled"):
|