File size: 1,863 Bytes
61c7634
e15dae8
c9911aa
17bb1f6
 
fae45ed
61c7634
236866f
c34d9ea
4fbf998
 
 
3ce1a28
4fbf998
3ce1a28
d30d4ce
4d39816
921054e
ec11b9a
6f3fb83
62635cf
17bb1f6
5c5bd98
6f3fb83
1c0adda
3ce1a28
b6f3fea
cd7c7ec
6115563
31fec50
62635cf
a1b8369
 
1377bb8
1c0adda
 
1377bb8
5c5bd98
1c0adda
ec11b9a
db2e7bb
5c5bd98
a99f6a6
a0aec25
 
 
 
 
4d39816
a1b8369
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from turtle import color, onclick
import streamlit as st
from PIL import Image, ImageOps
import glob
import json
import requests
import random
import io

if 'index' not in st.session_state:
    st.session_state.index = 0

def set_back():
    st.session_state.index = 0

st.set_page_config(layout="wide")
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!**")

col1, col2 = st.columns(2)

prefix = 'https://raw.githubusercontent.com/BennoKrojer/imagecode-val-set/main/image-sets-val/'
set2ids = json.load(open('set2ids.json', 'r'))
descriptions = json.load(open('valid_list.json', 'r'))

st.session_state.index = int(col2.number_input('Image Index from 0 to 9', value=0, min_value=0, max_value=9))
example_idx = int(col1.number_input('Sample an example from the validation set', value=0, min_value=0, max_value=len(descriptions)-1, on_change=set_back))
img_set, idx, descr = descriptions[example_idx]
idx = int(idx)
images = [prefix+'/'+img_set+'/'+i for i in set2ids[img_set]]
img_urls = images.copy()

col1.markdown(f'**Description**:')
col1.markdown(descr)

img = images[st.session_state.index]
images[st.session_state.index] = ImageOps.expand(Image.open(io.BytesIO(requests.get(images[st.session_state.index], stream=True).content)),border=20,fill='blue')

caps = list(range(10))
cap = str(st.session_state.index)

col1.image(img, use_column_width=True, caption=cap)
col2.image(images, width=175, caption=caps)

st.markdown('#')
st.markdown('#')
st.markdown('#')
st.markdown('#')
st.markdown('#')
st.markdown('#')
st.markdown('#')
st.markdown('#')
st.markdown('#')
st.markdown('#')
st.markdown(f'**The correct target image index is: {idx}**')