Update app.py
Browse files
app.py
CHANGED
|
@@ -2,30 +2,46 @@ import streamlit as st
|
|
| 2 |
from bokeh.plotting import figure
|
| 3 |
from bokeh.models import ColumnDataSource, HoverTool
|
| 4 |
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
data = {
|
| 7 |
-
'x': [
|
| 8 |
-
'y': [
|
| 9 |
-
'label': [
|
| 10 |
-
'image': [
|
| 11 |
-
|
| 12 |
-
'https://media-img.lucyinthesky.com/data/Nov24/560xAUTO/dfd0c2d3-af96-4700-8fb2-cccc585c0e8b.jpg',
|
| 13 |
-
'https://media-img.lucyinthesky.com/data/Nov24/560xAUTO/ef942b7d-52ad-415b-ae88-c7c29a2491b4.jpg',
|
| 14 |
-
'https://media-img.lucyinthesky.com/data/Nov24/560xAUTO/047928d0-9168-4d29-84a5-785aec57dd6b.jpg',
|
| 15 |
-
'https://media-img.lucyinthesky.com/data/Nov24/560xAUTO/03054e31-3812-454a-bc3a-0ff207798927.jpg'
|
| 16 |
-
]
|
| 17 |
}
|
| 18 |
|
| 19 |
source = ColumnDataSource(data=data)
|
| 20 |
|
| 21 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
p = figure(title="Scatter Plot with Image Hover", tools="hover", tooltips="""
|
| 23 |
<div>
|
| 24 |
<div><strong>@label</strong></div>
|
| 25 |
-
<div><img src="@image"
|
| 26 |
</div>
|
| 27 |
""")
|
| 28 |
-
p.circle('x', 'y', size=10, source=source)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
# Display the Bokeh figure in Streamlit
|
| 31 |
st.bokeh_chart(p)
|
|
|
|
| 2 |
from bokeh.plotting import figure
|
| 3 |
from bokeh.models import ColumnDataSource, HoverTool
|
| 4 |
|
| 5 |
+
from datasets import load_dataset
|
| 6 |
+
from bokeh.plotting import figure, show, output_notebook
|
| 7 |
+
from bokeh.models import ColumnDataSource, LinearColorMapper, ColorBar
|
| 8 |
+
from bokeh.transform import linear_cmap
|
| 9 |
+
from bokeh.palettes import Viridis256 # You can choose any palette you like and reverse it using [::-1]
|
| 10 |
+
from bokeh.models import BasicTicker
|
| 11 |
+
|
| 12 |
+
# Load the dataset
|
| 13 |
+
dataset = load_dataset("tonyassi/lucy6-embeddings-xy")['train']
|
| 14 |
+
|
| 15 |
+
# Extract data
|
| 16 |
data = {
|
| 17 |
+
'x': [item['x'] for item in dataset],
|
| 18 |
+
'y': [item['y'] for item in dataset],
|
| 19 |
+
'label': [f"ID: {item['id']}" for item in dataset],
|
| 20 |
+
'image': [item['image_url'] for item in dataset],
|
| 21 |
+
'id': [item['id'] for item in dataset] # Include 'id' for color mapping
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
}
|
| 23 |
|
| 24 |
source = ColumnDataSource(data=data)
|
| 25 |
|
| 26 |
+
# Configure Bokeh plot
|
| 27 |
+
output_notebook()
|
| 28 |
+
|
| 29 |
+
# Create a color mapper with reversed palette
|
| 30 |
+
color_mapper = linear_cmap(field_name='id', palette=Viridis256[::-1], low=0, high=100)
|
| 31 |
+
|
| 32 |
+
# Create the figure
|
| 33 |
p = figure(title="Scatter Plot with Image Hover", tools="hover", tooltips="""
|
| 34 |
<div>
|
| 35 |
<div><strong>@label</strong></div>
|
| 36 |
+
<div><img src="@image" ></div>
|
| 37 |
</div>
|
| 38 |
""")
|
| 39 |
+
p.circle('x', 'y', size=10, source=source, color=color_mapper) # Apply the color mapper
|
| 40 |
+
|
| 41 |
+
# Add color bar
|
| 42 |
+
color_bar = ColorBar(color_mapper=color_mapper['transform'], width=8, location=(0, 0),
|
| 43 |
+
ticker=BasicTicker(desired_num_ticks=10))
|
| 44 |
+
p.add_layout(color_bar, 'right') # Position the color bar to the right
|
| 45 |
|
| 46 |
# Display the Bokeh figure in Streamlit
|
| 47 |
st.bokeh_chart(p)
|