Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,9 @@
|
|
1 |
import streamlit as st
|
2 |
from bokeh.plotting import figure
|
3 |
-
from bokeh.models import ColumnDataSource, HoverTool
|
4 |
-
|
5 |
-
from datasets import load_dataset
|
6 |
-
from bokeh.models import ColumnDataSource, LinearColorMapper, ColorBar
|
7 |
from bokeh.transform import linear_cmap
|
8 |
-
from bokeh.palettes import Viridis256
|
9 |
-
from
|
10 |
|
11 |
# Load the dataset
|
12 |
dataset = load_dataset("tonyassi/lucy7-embeddings-xy")['train']
|
@@ -22,20 +19,17 @@ data = {
|
|
22 |
|
23 |
source = ColumnDataSource(data=data)
|
24 |
|
25 |
-
|
26 |
# Create a color mapper with reversed palette
|
27 |
color_mapper = linear_cmap(field_name='id', palette=Viridis256[::-1], low=0, high=len(data['id']))
|
28 |
|
29 |
# Create the figure
|
30 |
-
p = figure(title="Scatter Plot with Image Hover",tools="pan,box_zoom,wheel_zoom,zoom_in,zoom_out,save,reset,hover",
|
|
|
31 |
<div>
|
32 |
<div><strong>@label</strong></div>
|
33 |
<div><img src="@image" ></div>
|
34 |
</div>
|
35 |
""")
|
36 |
-
|
37 |
-
p.min_border_left = 10
|
38 |
-
|
39 |
p.circle('x', 'y', size=5, source=source, color=color_mapper) # Apply the color mapper
|
40 |
|
41 |
# Add color bar
|
@@ -43,9 +37,18 @@ color_bar = ColorBar(color_mapper=color_mapper['transform'], width=8, location=(
|
|
43 |
ticker=BasicTicker(desired_num_ticks=10))
|
44 |
p.add_layout(color_bar, 'right') # Position the color bar to the right
|
45 |
|
46 |
-
|
47 |
-
|
48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
|
50 |
# Display the Bokeh figure in Streamlit
|
51 |
st.bokeh_chart(p)
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
from bokeh.plotting import figure
|
3 |
+
from bokeh.models import ColumnDataSource, HoverTool, LinearColorMapper, ColorBar, BasicTicker
|
|
|
|
|
|
|
4 |
from bokeh.transform import linear_cmap
|
5 |
+
from bokeh.palettes import Viridis256
|
6 |
+
from datasets import load_dataset
|
7 |
|
8 |
# Load the dataset
|
9 |
dataset = load_dataset("tonyassi/lucy7-embeddings-xy")['train']
|
|
|
19 |
|
20 |
source = ColumnDataSource(data=data)
|
21 |
|
|
|
22 |
# Create a color mapper with reversed palette
|
23 |
color_mapper = linear_cmap(field_name='id', palette=Viridis256[::-1], low=0, high=len(data['id']))
|
24 |
|
25 |
# Create the figure
|
26 |
+
p = figure(title="Scatter Plot with Image Hover", tools="pan,box_zoom,wheel_zoom,zoom_in,zoom_out,save,reset,hover",
|
27 |
+
width=1500, height=1000, tooltips="""
|
28 |
<div>
|
29 |
<div><strong>@label</strong></div>
|
30 |
<div><img src="@image" ></div>
|
31 |
</div>
|
32 |
""")
|
|
|
|
|
|
|
33 |
p.circle('x', 'y', size=5, source=source, color=color_mapper) # Apply the color mapper
|
34 |
|
35 |
# Add color bar
|
|
|
37 |
ticker=BasicTicker(desired_num_ticks=10))
|
38 |
p.add_layout(color_bar, 'right') # Position the color bar to the right
|
39 |
|
40 |
+
# Add custom CSS to adjust layout
|
41 |
+
st.markdown("""
|
42 |
+
<style>
|
43 |
+
.bokeh-chart-container {
|
44 |
+
margin-left: -100px; /* Adjust the value as needed */
|
45 |
+
}
|
46 |
+
</style>
|
47 |
+
<div class="bokeh-chart-container">
|
48 |
+
""", unsafe_allow_html=True)
|
49 |
|
50 |
# Display the Bokeh figure in Streamlit
|
51 |
st.bokeh_chart(p)
|
52 |
+
|
53 |
+
# Close the div
|
54 |
+
st.markdown("</div>", unsafe_allow_html=True)
|