Spaces:
Sleeping
Sleeping
Synced repo using 'sync_with_huggingface' Github Action
Browse files- app.py +20 -1
- dataset_wrangler.html +0 -0
- dataset_wrangler.py +75 -17
- image_analysis.py +4 -0
app.py
CHANGED
@@ -1,14 +1,33 @@
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
|
3 |
import dataset_wrangler
|
4 |
|
|
|
5 |
|
6 |
st.write(
|
7 |
"Scrambled Images from [https://www.slv.vic.gov.au/images](https://www.slv.vic.gov.au/images)"
|
8 |
)
|
9 |
|
10 |
|
11 |
-
p = dataset_wrangler.create_grid()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
|
|
13 |
|
14 |
st.bokeh_chart(p, use_container_width=True)
|
|
|
1 |
+
from bokeh import events
|
2 |
+
from bokeh.models import CustomJS
|
3 |
+
|
4 |
import streamlit as st
|
5 |
|
6 |
import dataset_wrangler
|
7 |
|
8 |
+
dataset = "https://raw.githubusercontent.com/StateLibraryVictoria/public-domain-hack-2024/refs/heads/ch4-data-viz/datasets/ch3_colour_data_viz_suggestions_set_2_augmented.csv"
|
9 |
|
10 |
st.write(
|
11 |
"Scrambled Images from [https://www.slv.vic.gov.au/images](https://www.slv.vic.gov.au/images)"
|
12 |
)
|
13 |
|
14 |
|
15 |
+
p = dataset_wrangler.create_grid(dataset)
|
16 |
+
|
17 |
+
callback = CustomJS(
|
18 |
+
code="""
|
19 |
+
console.log(Math.floor(cb_obj.x))
|
20 |
+
console.log(Math.floor(cb_obj.y))
|
21 |
+
|
22 |
+
try {
|
23 |
+
console.log("Hello mum")
|
24 |
+
st.write("Hello mum")
|
25 |
+
} catch {
|
26 |
+
console.log("error")
|
27 |
+
}
|
28 |
+
"""
|
29 |
+
)
|
30 |
|
31 |
+
p.js_on_event(events.Tap, callback)
|
32 |
|
33 |
st.bokeh_chart(p, use_container_width=True)
|
dataset_wrangler.html
CHANGED
The diff for this file is too large to render.
See raw diff
|
|
dataset_wrangler.py
CHANGED
@@ -1,13 +1,21 @@
|
|
1 |
import pandas as pd
|
2 |
import math
|
3 |
|
4 |
-
from bokeh.
|
|
|
|
|
5 |
|
6 |
|
7 |
-
|
8 |
|
|
|
|
|
|
|
9 |
|
10 |
-
|
|
|
|
|
|
|
11 |
|
12 |
df = pd.read_csv(dataset)
|
13 |
|
@@ -51,27 +59,52 @@ def get_square_coords(df):
|
|
51 |
return coords
|
52 |
|
53 |
|
54 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
|
56 |
markers = {
|
57 |
"pal_1": "circle",
|
|
|
58 |
"pal_3": "square_pin",
|
|
|
59 |
"pal_5": "triangle",
|
60 |
}
|
61 |
|
62 |
-
df = clean_df(subset=palette_columns)
|
|
|
63 |
coords = get_square_coords(df)
|
64 |
|
65 |
-
|
66 |
-
|
|
|
|
|
67 |
|
68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
|
70 |
-
p = figure(tools=TOOLS)
|
|
|
|
|
|
|
|
|
71 |
|
72 |
-
radius =
|
73 |
-
alpha = 0.
|
74 |
-
hover_alpha = 0.
|
75 |
|
76 |
for col in palette_columns:
|
77 |
|
@@ -92,21 +125,46 @@ def create_grid(palette_columns=["pal_1", "pal_3", "pal_5"]):
|
|
92 |
+ ")"
|
93 |
)
|
94 |
|
95 |
-
|
96 |
|
97 |
p.scatter(
|
98 |
-
x=x,
|
99 |
-
y=y,
|
100 |
size=radius,
|
101 |
-
color=
|
102 |
alpha=alpha,
|
103 |
hover_alpha=hover_alpha,
|
104 |
hover_line_color="white",
|
105 |
marker=markers[col],
|
|
|
106 |
)
|
107 |
|
108 |
return p
|
109 |
|
110 |
|
111 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
# show(p)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import pandas as pd
|
2 |
import math
|
3 |
|
4 |
+
from bokeh.models import HoverTool
|
5 |
+
from bokeh.plotting import figure
|
6 |
+
from bokeh.models import CustomJS
|
7 |
|
8 |
|
9 |
+
def display_event() -> CustomJS:
|
10 |
|
11 |
+
js_code = """
|
12 |
+
console.log('Hello mum!)
|
13 |
+
"""
|
14 |
|
15 |
+
return CustomJS(code=js_code)
|
16 |
+
|
17 |
+
|
18 |
+
def clean_df(columns=None, dataset="", subset=[]):
|
19 |
|
20 |
df = pd.read_csv(dataset)
|
21 |
|
|
|
59 |
return coords
|
60 |
|
61 |
|
62 |
+
def get_tooltips_dict(df, columns):
|
63 |
+
|
64 |
+
df = df[columns]
|
65 |
+
|
66 |
+
tooltips = df.to_dict()
|
67 |
+
|
68 |
+
return tooltips
|
69 |
+
|
70 |
+
|
71 |
+
def create_grid(dataset, palette_columns=["pal_1", "pal_3", "pal_5"]):
|
72 |
|
73 |
markers = {
|
74 |
"pal_1": "circle",
|
75 |
+
"pal_2": "hex",
|
76 |
"pal_3": "square_pin",
|
77 |
+
"pal_4": "plus",
|
78 |
"pal_5": "triangle",
|
79 |
}
|
80 |
|
81 |
+
df = clean_df(dataset=dataset, subset=palette_columns)
|
82 |
+
|
83 |
coords = get_square_coords(df)
|
84 |
|
85 |
+
# bodge the df to ensure the length matches the coords
|
86 |
+
df = df.head(len(coords))
|
87 |
+
|
88 |
+
TOOLS = "crosshair,pan,wheel_zoom,zoom_in,zoom_out,box_zoom,undo,redo,reset"
|
89 |
|
90 |
+
data = pd.DataFrame(
|
91 |
+
{
|
92 |
+
"x": [coord[0] for coord in coords],
|
93 |
+
"y": [coord[1] for coord in coords],
|
94 |
+
"titles": df["Title (DC)"].values.tolist(),
|
95 |
+
"created": df["Created - W 3 CDTF (DCTERMS)"].values.tolist(),
|
96 |
+
}
|
97 |
+
)
|
98 |
|
99 |
+
p = figure(sizing_mode="stretch_width", max_width=1000, tools=TOOLS)
|
100 |
+
p.grid.grid_line_color = None
|
101 |
+
p.axis.visible = False
|
102 |
+
hover = HoverTool(tooltips=[("Title", "@titles"), ("Date created", "@created")])
|
103 |
+
p.add_tools(hover)
|
104 |
|
105 |
+
radius = 12
|
106 |
+
alpha = 0.25
|
107 |
+
hover_alpha = 0.5
|
108 |
|
109 |
for col in palette_columns:
|
110 |
|
|
|
125 |
+ ")"
|
126 |
)
|
127 |
|
128 |
+
data["rgba"] = df[f"rgba_{col}"].values.tolist()
|
129 |
|
130 |
p.scatter(
|
131 |
+
x="x",
|
132 |
+
y="y",
|
133 |
size=radius,
|
134 |
+
color="rgba",
|
135 |
alpha=alpha,
|
136 |
hover_alpha=hover_alpha,
|
137 |
hover_line_color="white",
|
138 |
marker=markers[col],
|
139 |
+
source=data,
|
140 |
)
|
141 |
|
142 |
return p
|
143 |
|
144 |
|
145 |
+
# div = Div(width=1000)
|
146 |
+
# curdoc().on_event(events.DocumentReady, display_event(div))
|
147 |
+
|
148 |
+
# from bokeh import events
|
149 |
+
|
150 |
+
# dataset = "https://raw.githubusercontent.com/StateLibraryVictoria/public-domain-hack-2024/refs/heads/ch4-data-viz/datasets/ch3_colour_data_viz_suggestions_set_2_augmented.csv"
|
151 |
+
|
152 |
+
# p = create_grid(dataset)
|
153 |
+
|
154 |
+
# callback = CustomJS(
|
155 |
+
# code="""
|
156 |
+
# console.log("Hello mum!")
|
157 |
+
# console.log(Math.floor(cb_obj.x))
|
158 |
+
# console.log(Math.floor(cb_obj.y))
|
159 |
+
# """
|
160 |
+
# )
|
161 |
+
|
162 |
+
# p.js_on_event(events.Tap, callback)
|
163 |
# show(p)
|
164 |
+
|
165 |
+
|
166 |
+
# point_attributes = ["x", "y", "sx", "sy"]
|
167 |
+
# p.js_on_event(events.Tap, display_event(div, attributes=point_attributes))
|
168 |
+
|
169 |
+
# layout = column(p, div)
|
170 |
+
# show(layout)
|
image_analysis.py
CHANGED
@@ -2,6 +2,7 @@ import cv2 as cv
|
|
2 |
import numpy as np
|
3 |
import requests
|
4 |
from pathlib import Path
|
|
|
5 |
|
6 |
import matplotlib.pyplot as plt
|
7 |
|
@@ -36,6 +37,9 @@ def get_iiif_image_urls(ie_pid: str):
|
|
36 |
return image_urls
|
37 |
|
38 |
|
|
|
|
|
|
|
39 |
def show_img_compare(img_1, img_2):
|
40 |
f, ax = plt.subplots(1, 2, figsize=(10, 10))
|
41 |
ax[0].imshow(img_1)
|
|
|
2 |
import numpy as np
|
3 |
import requests
|
4 |
from pathlib import Path
|
5 |
+
import pandas as pd
|
6 |
|
7 |
import matplotlib.pyplot as plt
|
8 |
|
|
|
37 |
return image_urls
|
38 |
|
39 |
|
40 |
+
# print(get_iiif_image_urls("IE1258179"))
|
41 |
+
|
42 |
+
|
43 |
def show_img_compare(img_1, img_2):
|
44 |
f, ax = plt.subplots(1, 2, figsize=(10, 10))
|
45 |
ax[0].imshow(img_1)
|