PedroC11 commited on
Commit
dc3e18c
·
verified ·
1 Parent(s): 35d174d

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +34 -26
src/streamlit_app.py CHANGED
@@ -58,7 +58,7 @@ st.title("Image Preference Study")
58
  st.header("Instructions", divider=True)
59
  #st.markdown(f"**Instructions:**
60
  st.markdown(f"You will be shown 20 pairs of images. For each pair, please select which image \"Option A\" (left) or \"Option B\" (right) you find more \
61
- **visually appealing** and to have **better quality**.")
62
  st.markdown(f"Please, evaluate each pair of images **independetly** of the other pairs.")
63
  st.markdown(f"If needed, we advice looking closer to the screen and/or zoom in the pictures.")
64
 
@@ -76,7 +76,7 @@ results = {}
76
  # ---- LOOP THROUGH PAIRS ----
77
  for i, (imgA, imgB) in enumerate(image_pairs):
78
  st.markdown(f"### Pair {i+1}")
79
- col1, col2 = st.columns(2)
80
 
81
  with col1:
82
  st.image(imgA, caption="Option A", use_container_width=True)
@@ -85,38 +85,46 @@ for i, (imgA, imgB) in enumerate(image_pairs):
85
 
86
  choice = st.radio(
87
  f"Which image do you prefer for Pair {i+1}?",
88
- ("A", "B"),
89
  key=f"choice_{i}"
90
  )
91
  results[f"pair_{i+1}"] = choice
92
 
93
  # ---- SUBMIT ----
94
  if st.button("Submit"):
95
- #st.success("Thank you! Your responses have been recorded.")
96
- #st.write("Thank you! Your selection has been recorded.")
97
- st.success("Thank you! Your selection has been recorded.")
98
- #st.write("Your final selection is in the green box below. Please, copy them and send them to my email. Thanks a lot!")
99
- #s_rp = "SELECTION: "
100
- #for i in range(len(image_pairs)):
101
- # if i == (len(image_pairs) - 1):
102
- # s_rp = s_rp + results[f"pair_{i+1}"] + "."
103
- # else:
104
- # s_rp = s_rp + results[f"pair_{i+1}"] + ", "
105
- ##st.badge(s_rp, width = "stretch")
106
- #st.success(s_rp)
107
-
108
- # st.json(results)
109
 
110
- #====
111
- current_time = datetime.datetime.now()
112
- results["day"] = str(current_time.day)
113
- results["time"] = str(current_time.hour) + ":" + str(current_time.minute) + ":" + str(current_time.second)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
114
 
115
- with scheduler.lock:
116
- with feedback_file.open("a") as f:
117
- f.write(json.dumps(results))
118
- f.write("\n")
119
- #====
 
 
 
 
 
120
 
121
 
122
  # Save to file (you could also save to a database)
 
58
  st.header("Instructions", divider=True)
59
  #st.markdown(f"**Instructions:**
60
  st.markdown(f"You will be shown 20 pairs of images. For each pair, please select which image \"Option A\" (left) or \"Option B\" (right) you find more \
61
+ **visually appealing** and to have **better quality in its features**.")
62
  st.markdown(f"Please, evaluate each pair of images **independetly** of the other pairs.")
63
  st.markdown(f"If needed, we advice looking closer to the screen and/or zoom in the pictures.")
64
 
 
76
  # ---- LOOP THROUGH PAIRS ----
77
  for i, (imgA, imgB) in enumerate(image_pairs):
78
  st.markdown(f"### Pair {i+1}")
79
+ col0, col1, col2 = st.columns(3)
80
 
81
  with col1:
82
  st.image(imgA, caption="Option A", use_container_width=True)
 
85
 
86
  choice = st.radio(
87
  f"Which image do you prefer for Pair {i+1}?",
88
+ ("-","A", "B"),
89
  key=f"choice_{i}"
90
  )
91
  results[f"pair_{i+1}"] = choice
92
 
93
  # ---- SUBMIT ----
94
  if st.button("Submit"):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
 
96
+ cont = 0
97
+ for key in results:
98
+ if results[key] == "-":
99
+ cont += 1
100
+ if cont != 0:
101
+ st.error("Sorry, you have not evaluated all pairs. Please, check again.")
102
+ else:
103
+ #st.success("Thank you! Your responses have been recorded.")
104
+ #st.write("Thank you! Your selection has been recorded.")
105
+ st.success("Thank you! Your selection has been recorded.")
106
+ #st.write("Your final selection is in the green box below. Please, copy them and send them to my email. Thanks a lot!")
107
+ #s_rp = "SELECTION: "
108
+ #for i in range(len(image_pairs)):
109
+ # if i == (len(image_pairs) - 1):
110
+ # s_rp = s_rp + results[f"pair_{i+1}"] + "."
111
+ # else:
112
+ # s_rp = s_rp + results[f"pair_{i+1}"] + ", "
113
+ ##st.badge(s_rp, width = "stretch")
114
+ #st.success(s_rp)
115
+
116
+ # st.json(results)
117
 
118
+ #====
119
+ current_time = datetime.datetime.now()
120
+ results["day"] = str(current_time.day)
121
+ results["time"] = str(current_time.hour) + ":" + str(current_time.minute) + ":" + str(current_time.second)
122
+
123
+ with scheduler.lock:
124
+ with feedback_file.open("a") as f:
125
+ f.write(json.dumps(results))
126
+ f.write("\n")
127
+ #====
128
 
129
 
130
  # Save to file (you could also save to a database)