CarolineM5 commited on
Commit
efe8624
·
verified ·
1 Parent(s): 9af6198

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -24
app.py CHANGED
@@ -15,17 +15,17 @@ import numpy as np
15
  # -------------------------
16
  # Global parameters
17
  # -------------------------
18
- IMAGE_DIR = "images" # Dossier contenant les images
19
- NUM_PAIRS = 10 # Nombre total de paires à évaluer
20
- RESULTS_FILE = "results.csv" # Fichier CSV de sauvegarde des réponses
21
 
22
  # -------------------------
23
  # Helper functions
24
  # -------------------------
25
  def load_image_pair(index):
26
  """
27
- Pour un index donné (entier), retourne le chemin du ground truth et celui de la génération.
28
- Les fichiers sont nommés avec un index à 5 chiffres.
29
  """
30
  idx_str = str(index).zfill(5)
31
  gt_path = os.path.join(IMAGE_DIR, f"{idx_str}.png")
@@ -34,17 +34,6 @@ def load_image_pair(index):
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
50
  # -------------------------
@@ -58,7 +47,8 @@ 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
 
@@ -66,14 +56,14 @@ if "list_pair" not in st.session_state:
66
  # Intro page
67
  # -------------------------
68
  if st.session_state.page == "intro":
69
- st.title("Wood Surface Evaluation Study")
70
  st.markdown(
71
  """
72
  **Welcome!**
73
 
74
  In this study, you will be shown pairs of wood surface images.
75
- One image is a real photograph (Ground Truth) and the other is generated by AI.
76
- Your task is to select, by answering below each image, which one you believe is **real**.
77
 
78
  Please enter your name below and click **Start Evaluation** to begin.
79
  """
@@ -84,9 +74,10 @@ if st.session_state.page == "intro":
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
 
@@ -102,7 +93,7 @@ if st.session_state.page == "intro":
102
  # Evaluation page
103
  # -------------------------
104
  if st.session_state.page == "evaluation":
105
- st.title("Wood Surface Evaluation")
106
  # st.write(f"User: **{st.session_state.user_name}**")
107
 
108
  # If all pairs have been evaluated, display a message and save the results
@@ -118,7 +109,7 @@ if st.session_state.page == "evaluation":
118
 
119
  st.success(f"Number of correct answers: {nb_correct}/{NUM_PAIRS}")
120
 
121
- d = {'ID_img': rd_ID_list, 'Correct': correct_guess}
122
  df = pd.DataFrame(data=d)
123
  df.to_csv(st.session_state.user_name+'.csv')
124
 
 
15
  # -------------------------
16
  # Global parameters
17
  # -------------------------
18
+ IMAGE_DIR = "images" # Folder containing images
19
+ NUM_PAIRS = 10 # Total number of pairs to be assessed
20
+ # RESULTS_FILE = "results.csv" # CSV file for saving responses
21
 
22
  # -------------------------
23
  # Helper functions
24
  # -------------------------
25
  def load_image_pair(index):
26
  """
27
+ For a given index (integer), returns the path of the ground truth and the path of AI generated image.
28
+ Files are named with a 5-digit index.
29
  """
30
  idx_str = str(index).zfill(5)
31
  gt_path = os.path.join(IMAGE_DIR, f"{idx_str}.png")
 
34
 
35
 
36
 
 
 
 
 
 
 
 
 
 
 
 
37
  # -------------------------
38
  # Navigation via st.session_state
39
  # -------------------------
 
47
  st.session_state.results = []
48
  if "list_pair" not in st.session_state:
49
  st.session_state.list_pair = []
50
+ if "list_pair_ID" not in st.session_state:
51
+ st.session_state.list_pair_ID = []
52
 
53
 
54
 
 
56
  # Intro page
57
  # -------------------------
58
  if st.session_state.page == "intro":
59
+ st.title("Wood Evaluation Study")
60
  st.markdown(
61
  """
62
  **Welcome!**
63
 
64
  In this study, you will be shown pairs of wood surface images.
65
+ One image is a real photograph and the other is generated by AI.
66
+ Your task is to select the image you believe is **real**.
67
 
68
  Please enter your name below and click **Start Evaluation** to begin.
69
  """
 
74
  st.session_state.page = "evaluation"
75
  st.rerun()
76
 
77
+ st.session_state.list_pair_ID = random.sample(range(1, 51), NUM_PAIRS)
78
+
79
 
80
+ for i, index in enumerate(st.session_state.list_pair_ID):
81
 
82
  gt_path, pred_path = load_image_pair(index)
83
 
 
93
  # Evaluation page
94
  # -------------------------
95
  if st.session_state.page == "evaluation":
96
+ st.title("Wood Evaluation")
97
  # st.write(f"User: **{st.session_state.user_name}**")
98
 
99
  # If all pairs have been evaluated, display a message and save the results
 
109
 
110
  st.success(f"Number of correct answers: {nb_correct}/{NUM_PAIRS}")
111
 
112
+ d = {'ID_img': st.session_state.list_pair_ID, 'Correct': correct_guess}
113
  df = pd.DataFrame(data=d)
114
  df.to_csv(st.session_state.user_name+'.csv')
115