Update visualizer_app.py
Browse files- visualizer_app.py +32 -21
visualizer_app.py
CHANGED
|
@@ -2010,28 +2010,39 @@ def combined_chart_visualization(
|
|
| 2010 |
):
|
| 2011 |
# Usage with highlight_closest=True
|
| 2012 |
if chart_dataframe is not None and query.value:
|
| 2013 |
-
|
| 2014 |
-
|
| 2015 |
-
|
| 2016 |
-
|
| 2017 |
-
|
| 2018 |
-
|
| 2019 |
-
|
| 2020 |
-
|
| 2021 |
-
|
| 2022 |
-
|
| 2023 |
-
|
| 2024 |
-
|
| 2025 |
-
existing_chart=emb_plot,
|
| 2026 |
-
query_coords=query_coords,
|
| 2027 |
-
query_text=query.value,
|
| 2028 |
-
)
|
| 2029 |
-
|
| 2030 |
-
chart_with_query = result
|
| 2031 |
|
| 2032 |
-
|
| 2033 |
-
|
| 2034 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2035 |
else:
|
| 2036 |
combined_viz = None
|
| 2037 |
return
|
|
|
|
| 2010 |
):
|
| 2011 |
# Usage with highlight_closest=True
|
| 2012 |
if chart_dataframe is not None and query.value:
|
| 2013 |
+
with mo.status.spinner(title="Embedding Query...", remove_on_exit=True) as _spinner:
|
| 2014 |
+
query_emb = embedding.embed_documents([query.value])
|
| 2015 |
+
set_query_state(query_emb)
|
| 2016 |
+
|
| 2017 |
+
_spinner.update("Preparing Query Coordinates") # --- --- ---
|
| 2018 |
+
time.sleep(1.0)
|
| 2019 |
+
|
| 2020 |
+
# Get appropriate coordinates for the query
|
| 2021 |
+
query_coords = get_query_coordinates(
|
| 2022 |
+
reference_embeddings=chart_dataframe,
|
| 2023 |
+
query_embedding=get_query_state()
|
| 2024 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2025 |
|
| 2026 |
+
_spinner.update("Adding Query to Chart") # --- --- ---
|
| 2027 |
+
time.sleep(1.0)
|
| 2028 |
+
|
| 2029 |
+
# Add the query to the chart with closest points highlighted
|
| 2030 |
+
result = add_query_to_embedding_chart(
|
| 2031 |
+
existing_chart=emb_plot,
|
| 2032 |
+
query_coords=query_coords,
|
| 2033 |
+
query_text=query.value,
|
| 2034 |
+
)
|
| 2035 |
+
|
| 2036 |
+
chart_with_query = result
|
| 2037 |
+
|
| 2038 |
+
_spinner.update("Preparing Visualization") # --- --- ---
|
| 2039 |
+
time.sleep(1.0)
|
| 2040 |
+
|
| 2041 |
+
# Create the visualization
|
| 2042 |
+
combined_viz = mo.ui.plotly(chart_with_query)
|
| 2043 |
+
set_chart_state(combined_viz)
|
| 2044 |
+
|
| 2045 |
+
_spinner.update("Done") # --- --- ---
|
| 2046 |
else:
|
| 2047 |
combined_viz = None
|
| 2048 |
return
|