Spaces:
Runtime error
Runtime error
Federico Galatolo
commited on
Commit
·
2faec1b
1
Parent(s):
2e3820b
first version
Browse files
app.py
CHANGED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import os
|
3 |
+
import json
|
4 |
+
|
5 |
+
def batch(iterable, n=1):
|
6 |
+
l = len(iterable)
|
7 |
+
for ndx in range(0, l, n):
|
8 |
+
yield iterable[ndx:min(ndx + n, l)]
|
9 |
+
|
10 |
+
data_path = "./data/TeTIm-Eval-Mini"
|
11 |
+
category_map = {
|
12 |
+
"Digital art": "sampled_art_digital",
|
13 |
+
"Digital sketches": "sampled_art_sketch",
|
14 |
+
"Traditional art": "sampled_art_traditional",
|
15 |
+
"Baroque paintings": "sampled_painting_baroque",
|
16 |
+
"High renaissance paintings": "sampled_painting_high-renaissance",
|
17 |
+
"Neoclassicism paintings": "sampled_painting_neoclassicism",
|
18 |
+
"Animal photography": "sampled_photo_animal",
|
19 |
+
"Food photography": "sampled_photo_food",
|
20 |
+
"Landscape photography": "sampled_photo_landscape",
|
21 |
+
"Portrait photography": "sampled_photo_person"
|
22 |
+
}
|
23 |
+
models_map = {
|
24 |
+
"real": "Real picture",
|
25 |
+
"DALLE2": "DALL-E 2"
|
26 |
+
}
|
27 |
+
|
28 |
+
if "current" not in st.session_state:
|
29 |
+
st.session_state["current"] = 1
|
30 |
+
|
31 |
+
st.header("TeTIm-Eval-mini showcase")
|
32 |
+
category = st.selectbox("Category", category_map.keys())
|
33 |
+
|
34 |
+
path = os.path.join(data_path, "real", category_map[category], "images")
|
35 |
+
real_images = sorted(os.listdir(path), key=lambda e: int(e.split(".")[0]))
|
36 |
+
|
37 |
+
coll, _, colc, _, colr = st.columns(5)
|
38 |
+
|
39 |
+
prev = coll.button("« Previous")
|
40 |
+
state = colc.empty()
|
41 |
+
next = colr.button("Next »")
|
42 |
+
|
43 |
+
if prev:
|
44 |
+
st.session_state["current"] = max(st.session_state["current"] - 1, 1)
|
45 |
+
|
46 |
+
if next:
|
47 |
+
st.session_state["current"] = min(st.session_state["current"] + 1, len(real_images))
|
48 |
+
|
49 |
+
state.write(f"{st.session_state['current']}/{len(real_images)}")
|
50 |
+
|
51 |
+
path = os.path.join(data_path, "real", category_map[category], "annotations")
|
52 |
+
annotations = sorted(os.listdir(path), key=lambda e: int(e.split(".")[0]))
|
53 |
+
|
54 |
+
with open(os.path.join(path, annotations[st.session_state["current"]-1])) as annotation_f:
|
55 |
+
annotation = json.load(annotation_f)
|
56 |
+
|
57 |
+
st.subheader(annotation["caption"])
|
58 |
+
|
59 |
+
for (modell, modell_name), (modelr, modelr_name) in batch(list(models_map.items()), n=2):
|
60 |
+
coll_title, colr_title = st.columns(2)
|
61 |
+
coll_title.subheader(modell_name)
|
62 |
+
colr_title.subheader(modelr_name)
|
63 |
+
|
64 |
+
pathl = os.path.join(data_path, modell, category_map[category])
|
65 |
+
if modell == "real": pathl = os.path.join(pathl, "images")
|
66 |
+
imagesl = sorted(os.listdir(pathl), key=lambda e: int(e.split(".")[0]))
|
67 |
+
|
68 |
+
pathr = os.path.join(data_path, modelr, category_map[category])
|
69 |
+
if modelr == "real": pathr = os.path.join(pathr, "images")
|
70 |
+
imagesr = sorted(os.listdir(pathr), key=lambda e: int(e.split(".")[0]))
|
71 |
+
|
72 |
+
coll_image, colr_image = st.columns(2)
|
73 |
+
coll_image.image(os.path.join(pathl, imagesl[st.session_state["current"]-1]))
|
74 |
+
colr_image.image(os.path.join(pathr, imagesr[st.session_state["current"]-1]))
|
75 |
+
|
76 |
+
|