vinid/webplip
34
1from pathlib import Path2import streamlit as st3import streamlit.components.v1 as components4import plotly.figure_factory as ff5import numpy as np6import pandas as pd7#from streamlit_plotly_events import plotly_events8 9 10 11def app():12 st.markdown('#### Visualization')13 14 img_2d_embed = pd.read_csv('data/img_2d_embedding.csv', index_col=0)15 img_2d_embed = img_2d_embed.sample(frac=0.1, random_state=0)16 17 txt_2d_embed = pd.read_csv('data/txt_2d_embedding.csv', index_col=0)18 txt_2d_embed = txt_2d_embed.sample(frac=0.1, random_state=0)19 20 col1, col2 = st.columns(2)21 with col1:22 fig1 = ff.create_2d_density(23 x=img_2d_embed['UMAP_1'],24 y=img_2d_embed['UMAP_2'],25 #colors=img_2d_embed['tag'],26 colorscale='Blues', # set the color map27 height=500, # set height of the figure28 width=500, # set width of the figure29 title='Image embedding visualized in 2D UMAP'30 )31 #selected_points = plotly_events(fig1, click_event=True, hover_event=True)32 st.plotly_chart(fig1, use_container_width=True)33 34 with col2:35 fig2 = ff.create_2d_density(36 x=txt_2d_embed['UMAP_1'],37 y=txt_2d_embed['UMAP_2'],38 #colors=img_2d_embed['tag'],39 colorscale='Blues', # set the color map40 height=500, # set height of the figure41 width=500, # set width of the figure42 title='Text embedding visualized in 2D UMAP'43 )44 st.plotly_chart(fig2, use_container_width=True)