Spaces:
Sleeping
Sleeping
Synced repo using 'sync_with_huggingface' Github Action
Browse files- app.py +31 -4
- image_analysis.py +9 -6
app.py
CHANGED
@@ -4,11 +4,12 @@ import dataset_wrangler, image_analysis
|
|
4 |
|
5 |
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"
|
6 |
|
|
|
|
|
7 |
st.write(
|
8 |
"Scrambled Images from [https://www.slv.vic.gov.au/images](https://www.slv.vic.gov.au/images)"
|
9 |
)
|
10 |
|
11 |
-
palette_columns = ["pal_1", "pal_3", "pal_5"]
|
12 |
|
13 |
df = dataset_wrangler.clean_df(dataset=dataset, subset=palette_columns)
|
14 |
|
@@ -19,7 +20,7 @@ df["created_year"] = df["Created - W 3 CDTF (DCTERMS)"].apply(
|
|
19 |
|
20 |
|
21 |
with st.form("my_form"):
|
22 |
-
st.write
|
23 |
min_year = df["created_year"].min()
|
24 |
max_year = df["created_year"].max()
|
25 |
values = st.slider(
|
@@ -42,8 +43,15 @@ col1, col2 = st.columns([0.3, 0.7])
|
|
42 |
|
43 |
with col1:
|
44 |
st.write(f"Random image selection")
|
45 |
-
for img in random_selection["iiif_url"].values.tolist():
|
46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
|
49 |
p = dataset_wrangler.create_grid(df)
|
@@ -51,3 +59,22 @@ p = dataset_wrangler.create_grid(df)
|
|
51 |
with col2:
|
52 |
st.write(f"Plotting images from {values[0]} to {values[1]}")
|
53 |
st.bokeh_chart(p, use_container_width=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
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"
|
6 |
|
7 |
+
palette_columns = ["pal_1", "pal_3", "pal_5"]
|
8 |
+
|
9 |
st.write(
|
10 |
"Scrambled Images from [https://www.slv.vic.gov.au/images](https://www.slv.vic.gov.au/images)"
|
11 |
)
|
12 |
|
|
|
13 |
|
14 |
df = dataset_wrangler.clean_df(dataset=dataset, subset=palette_columns)
|
15 |
|
|
|
20 |
|
21 |
|
22 |
with st.form("my_form"):
|
23 |
+
# st.write("")
|
24 |
min_year = df["created_year"].min()
|
25 |
max_year = df["created_year"].max()
|
26 |
values = st.slider(
|
|
|
43 |
|
44 |
with col1:
|
45 |
st.write(f"Random image selection")
|
46 |
+
# for img in random_selection["iiif_url"].values.tolist():
|
47 |
+
# st.image(img, use_container_width=True)
|
48 |
+
for img in random_selection.values.tolist():
|
49 |
+
iiif_url = img[-1][0]
|
50 |
+
title = img[2]
|
51 |
+
palette = image_analysis.get_colour_palette_iiif_image(iiif_url=iiif_url)
|
52 |
+
|
53 |
+
st.image(img, use_container_width=True, caption=title)
|
54 |
+
st.image(palette[0], use_container_width=True)
|
55 |
|
56 |
|
57 |
p = dataset_wrangler.create_grid(df)
|
|
|
59 |
with col2:
|
60 |
st.write(f"Plotting images from {values[0]} to {values[1]}")
|
61 |
st.bokeh_chart(p, use_container_width=True)
|
62 |
+
|
63 |
+
|
64 |
+
# # !
|
65 |
+
|
66 |
+
# df = dataset_wrangler.clean_df(dataset=dataset, subset=palette_columns)
|
67 |
+
|
68 |
+
# random_selection = df.sample()
|
69 |
+
|
70 |
+
# random_selection["iiif_url"] = random_selection["IE PID"].apply(
|
71 |
+
# lambda x: image_analysis.get_iiif_image_urls(x)
|
72 |
+
# )
|
73 |
+
|
74 |
+
# for img in random_selection.values.tolist():
|
75 |
+
# iiif_url = img[-1][0]
|
76 |
+
# title = img[2]
|
77 |
+
# palette = image_analysis.get_colour_palette_iiif_image(iiif_url=iiif_url)
|
78 |
+
|
79 |
+
# st.image(img, use_container_width=True, caption=title)
|
80 |
+
# st.image(palette[0], use_container_width=True)
|
image_analysis.py
CHANGED
@@ -69,13 +69,16 @@ def get_palette_clusters(img, no_of_clusters=5):
|
|
69 |
return clusters
|
70 |
|
71 |
|
72 |
-
def get_colour_palette_iiif_image(ie_pid
|
73 |
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
|
|
|
|
|
|
79 |
|
80 |
# decode image
|
81 |
img = cv.imdecode(np.frombuffer(response.content, np.uint8), -1)
|
|
|
69 |
return clusters
|
70 |
|
71 |
|
72 |
+
def get_colour_palette_iiif_image(ie_pid="", dim=(500, 300), iiif_url=None):
|
73 |
|
74 |
+
if not iiif_url:
|
75 |
+
# get iiif image urls
|
76 |
+
image_urls = get_iiif_image_urls(ie_pid)
|
77 |
+
iiif_url = image_urls[0]
|
78 |
+
if not image_urls:
|
79 |
+
return False
|
80 |
+
|
81 |
+
response = requests.get(iiif_url)
|
82 |
|
83 |
# decode image
|
84 |
img = cv.imdecode(np.frombuffer(response.content, np.uint8), -1)
|