Spaces:
Runtime error
Runtime error
BennoKrojer
commited on
Commit
•
8465f52
1
Parent(s):
1c0adda
app.py
CHANGED
@@ -7,11 +7,8 @@ import requests
|
|
7 |
import random
|
8 |
import io
|
9 |
|
10 |
-
if '
|
11 |
-
st.session_state.
|
12 |
-
|
13 |
-
def set_back():
|
14 |
-
st.session_state.index = 0
|
15 |
|
16 |
st.set_page_config(layout="wide")
|
17 |
st.markdown("**This is a demo of the *ImageCoDe* dataset. Sample an example description with the left +/- button on the right and compare all the images with the +/- button on the right. If you want to know the groundtruth solution, scroll down to the end of the page!**")
|
@@ -22,8 +19,13 @@ prefix = 'https://raw.githubusercontent.com/BennoKrojer/imagecode-val-set/main/i
|
|
22 |
set2ids = json.load(open('set2ids.json', 'r'))
|
23 |
descriptions = json.load(open('valid_list.json', 'r'))
|
24 |
|
25 |
-
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
27 |
img_set, idx, descr = descriptions[example_idx]
|
28 |
idx = int(idx)
|
29 |
images = [prefix+'/'+img_set+'/'+i for i in set2ids[img_set]]
|
@@ -32,23 +34,34 @@ img_urls = images.copy()
|
|
32 |
col1.markdown(f'**Description**:')
|
33 |
col1.markdown(descr)
|
34 |
|
35 |
-
img = images[
|
36 |
-
images[
|
37 |
|
38 |
caps = list(range(10))
|
39 |
-
cap = str(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
col1.image(img, use_column_width=True, caption=cap)
|
42 |
col2.image(images, width=175, caption=caps)
|
43 |
|
44 |
-
|
45 |
-
|
46 |
-
st.markdown('#')
|
47 |
-
st.markdown('#')
|
48 |
-
st.markdown('#')
|
49 |
-
st.markdown('#')
|
50 |
-
st.markdown('#')
|
51 |
-
st.markdown('#')
|
52 |
-
st.markdown('#')
|
53 |
-
st.markdown('#')
|
54 |
-
st.markdown(
|
|
|
|
|
|
7 |
import random
|
8 |
import io
|
9 |
|
10 |
+
if 'show' not in st.session_state:
|
11 |
+
st.session_state.show = False
|
|
|
|
|
|
|
12 |
|
13 |
st.set_page_config(layout="wide")
|
14 |
st.markdown("**This is a demo of the *ImageCoDe* dataset. Sample an example description with the left +/- button on the right and compare all the images with the +/- button on the right. If you want to know the groundtruth solution, scroll down to the end of the page!**")
|
|
|
19 |
set2ids = json.load(open('set2ids.json', 'r'))
|
20 |
descriptions = json.load(open('valid_list.json', 'r'))
|
21 |
|
22 |
+
if col1.button('Show groundtruth target image'):
|
23 |
+
st.session_state.show = True
|
24 |
+
if col1.button('Hide groundtruth target image'):
|
25 |
+
st.session_state.show = False
|
26 |
+
|
27 |
+
index = int(col2.number_input('Image Index from 0 to 9', value=0, min_value=0, max_value=9))
|
28 |
+
example_idx = int(col1.number_input('Sample an example from the validation set', value=0, min_value=0, max_value=len(descriptions)-1))
|
29 |
img_set, idx, descr = descriptions[example_idx]
|
30 |
idx = int(idx)
|
31 |
images = [prefix+'/'+img_set+'/'+i for i in set2ids[img_set]]
|
|
|
34 |
col1.markdown(f'**Description**:')
|
35 |
col1.markdown(descr)
|
36 |
|
37 |
+
img = images[index]
|
38 |
+
images[index] = ImageOps.expand(Image.open(io.BytesIO(requests.get(images[index], stream=True).content)),border=20,fill='blue')
|
39 |
|
40 |
caps = list(range(10))
|
41 |
+
cap = str(index)
|
42 |
+
|
43 |
+
if st.session_state.show:
|
44 |
+
caps[idx] = f'{idx} (TARGET IMAGE)'
|
45 |
+
if idx == index:
|
46 |
+
cap = f'{idx} (TARGET IMAGE)'
|
47 |
+
else:
|
48 |
+
caps[idx] = f'{idx}'
|
49 |
+
if idx == index:
|
50 |
+
cap = f'{idx}'
|
51 |
|
52 |
col1.image(img, use_column_width=True, caption=cap)
|
53 |
col2.image(images, width=175, caption=caps)
|
54 |
|
55 |
+
|
56 |
+
|
57 |
+
# st.markdown('#')
|
58 |
+
# st.markdown('#')
|
59 |
+
# st.markdown('#')
|
60 |
+
# st.markdown('#')
|
61 |
+
# st.markdown('#')
|
62 |
+
# st.markdown('#')
|
63 |
+
# st.markdown('#')
|
64 |
+
# st.markdown('#')
|
65 |
+
# st.markdown('#')
|
66 |
+
# st.markdown('#')
|
67 |
+
# st.markdown(f'**The correct target image index is: {idx}**')
|