Spaces:
Runtime error
Runtime error
Commit
·
f4d85d5
1
Parent(s):
925d019
app.py
CHANGED
@@ -25,8 +25,8 @@ descriptions = json.load(open('valid_list.json', 'r'))
|
|
25 |
# example_idx = int(col1.number_input('Sample an example (description + corresponding images) from the validation set', value=0, min_value=0, max_value=len(descriptions)-1))
|
26 |
if col1.button('Sample an example (description + corresponding images) from the validation set'):
|
27 |
st.session_state.example_idx = random.randint(0, len(descriptions)-1)
|
28 |
-
img_set,
|
29 |
-
|
30 |
images = [prefix+'/'+img_set+'/'+i for i in set2ids[img_set]]
|
31 |
img_urls = images.copy()
|
32 |
index = int(col2.number_input('Image Index from 0 to 9', value=0, min_value=0, max_value=9))
|
@@ -37,21 +37,27 @@ if col1.button('Click to reveal/hide groundtruth image index (try to guess yours
|
|
37 |
col1.markdown(f'**Description**:')
|
38 |
col1.markdown(f'**{descr}**')
|
39 |
|
40 |
-
|
41 |
-
|
42 |
-
|
|
|
|
|
43 |
|
44 |
caps = list(range(10))
|
45 |
cap = str(index)
|
46 |
|
47 |
if st.session_state.show:
|
48 |
-
caps[
|
49 |
-
|
50 |
-
|
|
|
|
|
|
|
|
|
51 |
else:
|
52 |
-
caps[
|
53 |
-
if
|
54 |
-
cap = f'{
|
55 |
|
56 |
-
col1.image(
|
57 |
col2.image(images, width=175, caption=caps)
|
|
|
25 |
# example_idx = int(col1.number_input('Sample an example (description + corresponding images) from the validation set', value=0, min_value=0, max_value=len(descriptions)-1))
|
26 |
if col1.button('Sample an example (description + corresponding images) from the validation set'):
|
27 |
st.session_state.example_idx = random.randint(0, len(descriptions)-1)
|
28 |
+
img_set, true_idx, descr = descriptions[st.session_state.example_idx]
|
29 |
+
true_idx = int(true_idx)
|
30 |
images = [prefix+'/'+img_set+'/'+i for i in set2ids[img_set]]
|
31 |
img_urls = images.copy()
|
32 |
index = int(col2.number_input('Image Index from 0 to 9', value=0, min_value=0, max_value=9))
|
|
|
37 |
col1.markdown(f'**Description**:')
|
38 |
col1.markdown(f'**{descr}**')
|
39 |
|
40 |
+
big_img = images[index]
|
41 |
+
img = Image.open(io.BytesIO(requests.get(images[index], stream=True).content))
|
42 |
+
img_width, img_height = img.size
|
43 |
+
smaller = min(img_width, img_height)
|
44 |
+
images[index]= ImageOps.expand(img,border=smaller//18,fill='blue')
|
45 |
|
46 |
caps = list(range(10))
|
47 |
cap = str(index)
|
48 |
|
49 |
if st.session_state.show:
|
50 |
+
caps[true_idx] = f'{true_idx} (TARGET IMAGE)'
|
51 |
+
img = Image.open(io.BytesIO(requests.get(img_urls[index], stream=True).content))
|
52 |
+
img_width, img_height = img.size
|
53 |
+
smaller = min(img_width, img_height)
|
54 |
+
images[true_idx] = ImageOps.expand(img,border=smaller//12,fill='green')
|
55 |
+
if true_idx == index:
|
56 |
+
cap = f'{true_idx} (TARGET IMAGE)'
|
57 |
else:
|
58 |
+
caps[true_idx] = f'{true_idx}'
|
59 |
+
if true_idx == index:
|
60 |
+
cap = f'{true_idx}'
|
61 |
|
62 |
+
col1.image(big_img, use_column_width=True, caption=cap)
|
63 |
col2.image(images, width=175, caption=caps)
|