Spaces:
Build error
Build error
Upload app.py
Browse files
app.py
CHANGED
|
@@ -32,20 +32,18 @@ def load_image_pair(index):
|
|
| 32 |
pred_path = os.path.join(IMAGE_DIR, f"{idx_str}_gen0.png")
|
| 33 |
return gt_path, pred_path
|
| 34 |
|
| 35 |
-
def open_image(path):
|
| 36 |
-
"""Ouvre l'image avec PIL."""
|
| 37 |
-
return Image.open(path)
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
|
|
|
| 49 |
|
| 50 |
# -------------------------
|
| 51 |
# Navigation via st.session_state
|
|
@@ -55,13 +53,15 @@ if "page" not in st.session_state:
|
|
| 55 |
if "user_name" not in st.session_state:
|
| 56 |
st.session_state.user_name = ""
|
| 57 |
if "current_index" not in st.session_state:
|
| 58 |
-
st.session_state.current_index =
|
| 59 |
if "results" not in st.session_state:
|
| 60 |
st.session_state.results = []
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
-
|
| 65 |
# -------------------------
|
| 66 |
# Intro page
|
| 67 |
# -------------------------
|
|
@@ -83,6 +83,17 @@ if st.session_state.page == "intro":
|
|
| 83 |
st.session_state.user_name = name
|
| 84 |
st.session_state.page = "evaluation"
|
| 85 |
st.rerun()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
st.stop()
|
| 87 |
|
| 88 |
|
|
@@ -110,25 +121,30 @@ if st.session_state.page == "evaluation":
|
|
| 110 |
|
| 111 |
st.stop()
|
| 112 |
|
| 113 |
-
st.write(f"Image Pair {st.session_state.current_index} of {NUM_PAIRS}")
|
| 114 |
|
| 115 |
# Charger et mélanger la paire pour l'index courant
|
| 116 |
-
pair =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
# Affichage dans deux colonnes avec radio buttons sous chacune
|
| 118 |
col1, col2 = st.columns(2)
|
| 119 |
|
| 120 |
with col1:
|
| 121 |
-
st.image(
|
| 122 |
|
| 123 |
with col2:
|
| 124 |
-
st.image(
|
| 125 |
|
| 126 |
-
choice = st.radio("", options=["1
|
| 127 |
|
| 128 |
|
| 129 |
if st.button("Next"):
|
| 130 |
|
| 131 |
-
if (choice == "1
|
| 132 |
correct_guess = 1
|
| 133 |
else:
|
| 134 |
correct_guess = 0
|
|
|
|
| 32 |
pred_path = os.path.join(IMAGE_DIR, f"{idx_str}_gen0.png")
|
| 33 |
return gt_path, pred_path
|
| 34 |
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
+
|
| 37 |
+
# def get_shuffled_pair(index):
|
| 38 |
+
# """Charge la paire d'images et retourne une liste de tuples (label, image) dans un ordre aléatoire.
|
| 39 |
+
# Le label est 'GT' pour ground truth et 'Pred' pour generated.
|
| 40 |
+
# """
|
| 41 |
+
# gt_path, pred_path = load_image_pair(index)
|
| 42 |
+
# img_gt = open_image(gt_path)
|
| 43 |
+
# img_pred = open_image(pred_path)
|
| 44 |
+
# pair = [("GT", img_gt), ("Pred", img_pred)]
|
| 45 |
+
# random.shuffle(pair)
|
| 46 |
+
# return pair
|
| 47 |
|
| 48 |
# -------------------------
|
| 49 |
# Navigation via st.session_state
|
|
|
|
| 53 |
if "user_name" not in st.session_state:
|
| 54 |
st.session_state.user_name = ""
|
| 55 |
if "current_index" not in st.session_state:
|
| 56 |
+
st.session_state.current_index = 0
|
| 57 |
if "results" not in st.session_state:
|
| 58 |
st.session_state.results = []
|
| 59 |
+
if "list_pair" not in st.session_state:
|
| 60 |
+
st.session_state.list_pair = []
|
| 61 |
+
|
| 62 |
|
| 63 |
|
| 64 |
|
|
|
|
| 65 |
# -------------------------
|
| 66 |
# Intro page
|
| 67 |
# -------------------------
|
|
|
|
| 83 |
st.session_state.user_name = name
|
| 84 |
st.session_state.page = "evaluation"
|
| 85 |
st.rerun()
|
| 86 |
+
|
| 87 |
+
rd_ID_list = random.sample(range(1, 51), NUM_PAIRS)
|
| 88 |
+
|
| 89 |
+
for i, index in enumerate(rd_ID_list):
|
| 90 |
+
|
| 91 |
+
gt_path, pred_path = load_image_pair(index)
|
| 92 |
+
|
| 93 |
+
pair = [("GT", gt_path), ("Pred", pred_path)]
|
| 94 |
+
random.shuffle(pair)
|
| 95 |
+
st.session_state.list_pair.append(pair)
|
| 96 |
+
|
| 97 |
st.stop()
|
| 98 |
|
| 99 |
|
|
|
|
| 121 |
|
| 122 |
st.stop()
|
| 123 |
|
| 124 |
+
st.write(f"Image Pair {st.session_state.current_index+1} of {NUM_PAIRS}")
|
| 125 |
|
| 126 |
# Charger et mélanger la paire pour l'index courant
|
| 127 |
+
pair = st.session_state.list_pair[st.session_state.current_index]
|
| 128 |
+
|
| 129 |
+
img1 = Image.open(pair[0][1])
|
| 130 |
+
img2 = Image.open(pair[1][1])
|
| 131 |
+
|
| 132 |
+
|
| 133 |
# Affichage dans deux colonnes avec radio buttons sous chacune
|
| 134 |
col1, col2 = st.columns(2)
|
| 135 |
|
| 136 |
with col1:
|
| 137 |
+
st.image(img1, caption="Image 1", use_container_width =True)
|
| 138 |
|
| 139 |
with col2:
|
| 140 |
+
st.image(img2, caption="Image 2", use_container_width =True)
|
| 141 |
|
| 142 |
+
choice = st.radio("", options=["1", "2"], index=0, horizontal = True)
|
| 143 |
|
| 144 |
|
| 145 |
if st.button("Next"):
|
| 146 |
|
| 147 |
+
if (choice == "1" and pair[0][0] == "GT") or (choice == "2" and pair[1][0] == "GT"):
|
| 148 |
correct_guess = 1
|
| 149 |
else:
|
| 150 |
correct_guess = 0
|