Spaces:
Build error
Build error
Upload app.py
Browse files
app.py
CHANGED
|
@@ -14,6 +14,8 @@ import numpy as np
|
|
| 14 |
import gspread
|
| 15 |
from oauth2client.service_account import ServiceAccountCredentials
|
| 16 |
from skimage.exposure import match_histograms
|
|
|
|
|
|
|
| 17 |
|
| 18 |
# -------------------------
|
| 19 |
# Global parameters
|
|
@@ -52,9 +54,9 @@ def match_brightness(source_img, target_img):
|
|
| 52 |
|
| 53 |
def match_histograms_pil(img_reference, img_to_adjust):
|
| 54 |
"""
|
| 55 |
-
|
| 56 |
-
(
|
| 57 |
-
|
| 58 |
"""
|
| 59 |
# Convertir les deux images en tableaux numpy
|
| 60 |
ref_array = np.array(img_reference)
|
|
@@ -130,6 +132,11 @@ if st.session_state.page == "evaluation":
|
|
| 130 |
st.title("AI Wood Generation Evaluation")
|
| 131 |
# st.write(f"User: **{st.session_state.user_name}**")
|
| 132 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
# If all pairs have been evaluated, display a message and save the results
|
| 134 |
if st.session_state.current_index+1 > NUM_PAIRS:
|
| 135 |
|
|
@@ -194,13 +201,27 @@ if st.session_state.page == "evaluation":
|
|
| 194 |
# else:
|
| 195 |
# img1 = match_brightness(img2, img1)
|
| 196 |
|
|
|
|
|
|
|
|
|
|
| 197 |
col1, col2 = st.columns(2)
|
| 198 |
|
| 199 |
-
with col1:
|
| 200 |
-
|
| 201 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 202 |
with col2:
|
| 203 |
-
|
|
|
|
|
|
|
|
|
|
| 204 |
|
| 205 |
choice = st.radio("Select the real image: ", options=["1", "2"], horizontal = True) #, index=None
|
| 206 |
|
|
@@ -216,6 +237,8 @@ if st.session_state.page == "evaluation":
|
|
| 216 |
|
| 217 |
# Passer à la paire suivante
|
| 218 |
st.session_state.current_index += 1
|
|
|
|
|
|
|
| 219 |
st.rerun()
|
| 220 |
|
| 221 |
|
|
|
|
| 14 |
import gspread
|
| 15 |
from oauth2client.service_account import ServiceAccountCredentials
|
| 16 |
from skimage.exposure import match_histograms
|
| 17 |
+
import time
|
| 18 |
+
from streamlit_autorefresh import st_autorefresh
|
| 19 |
|
| 20 |
# -------------------------
|
| 21 |
# Global parameters
|
|
|
|
| 54 |
|
| 55 |
def match_histograms_pil(img_reference, img_to_adjust):
|
| 56 |
"""
|
| 57 |
+
Layer the histogram of `img_reference` on `img_to_adjust`
|
| 58 |
+
(both images are PIL.Image objects).
|
| 59 |
+
Returns a PIL image with adjusted histogram.
|
| 60 |
"""
|
| 61 |
# Convertir les deux images en tableaux numpy
|
| 62 |
ref_array = np.array(img_reference)
|
|
|
|
| 132 |
st.title("AI Wood Generation Evaluation")
|
| 133 |
# st.write(f"User: **{st.session_state.user_name}**")
|
| 134 |
|
| 135 |
+
if "start_time" not in st.session_state or st.session_state.page_changed:
|
| 136 |
+
st.session_state.start_time = time.time()
|
| 137 |
+
st.session_state.page_changed = False
|
| 138 |
+
st_autorefresh(interval=1000, key=f"timer_{st.session_state.current_index}")
|
| 139 |
+
|
| 140 |
# If all pairs have been evaluated, display a message and save the results
|
| 141 |
if st.session_state.current_index+1 > NUM_PAIRS:
|
| 142 |
|
|
|
|
| 201 |
# else:
|
| 202 |
# img1 = match_brightness(img2, img1)
|
| 203 |
|
| 204 |
+
elapsed = time.time() - st.session_state.start_time
|
| 205 |
+
placeholder = Image.new("L", img1.size, 128)
|
| 206 |
+
|
| 207 |
col1, col2 = st.columns(2)
|
| 208 |
|
| 209 |
+
# with col1:
|
| 210 |
+
# st.image(img1, caption="Image 1", use_container_width =True)
|
| 211 |
|
| 212 |
+
# with col2:
|
| 213 |
+
# st.image(img2, caption="Image 2", use_container_width =True)
|
| 214 |
+
|
| 215 |
+
with col1:
|
| 216 |
+
if elapsed < 10:
|
| 217 |
+
st.image(img1, caption="Image 1", use_container_width=True)
|
| 218 |
+
else:
|
| 219 |
+
st.image(placeholder, caption="Time’s up!", use_container_width=True)
|
| 220 |
with col2:
|
| 221 |
+
if elapsed < 10:
|
| 222 |
+
st.image(img2, caption="Image 2", use_container_width=True)
|
| 223 |
+
else:
|
| 224 |
+
st.image(placeholder, caption="Time’s up!", use_container_width=True)
|
| 225 |
|
| 226 |
choice = st.radio("Select the real image: ", options=["1", "2"], horizontal = True) #, index=None
|
| 227 |
|
|
|
|
| 237 |
|
| 238 |
# Passer à la paire suivante
|
| 239 |
st.session_state.current_index += 1
|
| 240 |
+
st.session_state.start_time = time.time()
|
| 241 |
+
st.session_state.page_changed = True
|
| 242 |
st.rerun()
|
| 243 |
|
| 244 |
|