Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -84,15 +84,17 @@ def save_evaluations(evaluations, doctor_name):
|
|
| 84 |
df.to_csv(filepath, index=False)
|
| 85 |
return filepath, filename
|
| 86 |
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
def get_preference_a():
|
| 90 |
-
"""Wrapper for preference A."""
|
| 91 |
if not state["session_active"]:
|
| 92 |
-
return None, None, "Session not active."
|
| 93 |
|
| 94 |
current_pair = state["image_pairs"][state["current_index"]]
|
| 95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
|
| 97 |
state["evaluations"].append({
|
| 98 |
'timestamp': datetime.now().isoformat(),
|
|
@@ -104,65 +106,21 @@ def get_preference_a():
|
|
| 104 |
|
| 105 |
state["current_index"] += 1
|
| 106 |
|
| 107 |
-
|
| 108 |
-
state["session_active"] = False
|
| 109 |
-
return None, None, "✅ Evaluation complete! All images have been reviewed."
|
| 110 |
-
|
| 111 |
-
current_pair = state["image_pairs"][state["current_index"]]
|
| 112 |
-
|
| 113 |
-
if current_pair['roentgen_left']:
|
| 114 |
-
left_image = load_image("roentgen", current_pair['roentgen'])
|
| 115 |
-
right_image = load_image("pedisynth", current_pair['pedisynth'])
|
| 116 |
-
state["current_left_source"] = "roentgen"
|
| 117 |
-
state["current_right_source"] = "pedisynth"
|
| 118 |
-
else:
|
| 119 |
-
left_image = load_image("pedisynth", current_pair['pedisynth'])
|
| 120 |
-
right_image = load_image("roentgen", current_pair['roentgen'])
|
| 121 |
-
state["current_left_source"] = "pedisynth"
|
| 122 |
-
state["current_right_source"] = "roentgen"
|
| 123 |
|
| 124 |
-
|
|
|
|
|
|
|
| 125 |
|
| 126 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
|
| 128 |
def get_preference_b():
|
| 129 |
"""Wrapper for preference B."""
|
| 130 |
-
|
| 131 |
-
return None, None, "Session not active."
|
| 132 |
-
|
| 133 |
-
current_pair = state["image_pairs"][state["current_index"]]
|
| 134 |
-
preferred_source = state["current_right_source"]
|
| 135 |
-
|
| 136 |
-
state["evaluations"].append({
|
| 137 |
-
'timestamp': datetime.now().isoformat(),
|
| 138 |
-
'condition': current_pair['condition'],
|
| 139 |
-
'base_name': current_pair['base_name'],
|
| 140 |
-
'preference': preferred_source.capitalize(),
|
| 141 |
-
'doctor': state["doctor_name"]
|
| 142 |
-
})
|
| 143 |
-
|
| 144 |
-
state["current_index"] += 1
|
| 145 |
-
|
| 146 |
-
if state["current_index"] >= len(state["image_pairs"]):
|
| 147 |
-
state["session_active"] = False
|
| 148 |
-
return None, None, "✅ Evaluation complete! All images have been reviewed."
|
| 149 |
-
|
| 150 |
-
current_pair = state["image_pairs"][state["current_index"]]
|
| 151 |
-
|
| 152 |
-
if current_pair['roentgen_left']:
|
| 153 |
-
left_image = load_image("roentgen", current_pair['roentgen'])
|
| 154 |
-
right_image = load_image("pedisynth", current_pair['pedisynth'])
|
| 155 |
-
state["current_left_source"] = "roentgen"
|
| 156 |
-
state["current_right_source"] = "pedisynth"
|
| 157 |
-
else:
|
| 158 |
-
left_image = load_image("pedisynth", current_pair['pedisynth'])
|
| 159 |
-
right_image = load_image("roentgen", current_pair['roentgen'])
|
| 160 |
-
state["current_left_source"] = "pedisynth"
|
| 161 |
-
state["current_right_source"] = "roentgen"
|
| 162 |
-
|
| 163 |
-
progress = f"Image {state['current_index'] + 1} of {len(state['image_pairs'])} | Condition: {current_pair['condition']}"
|
| 164 |
-
|
| 165 |
-
return left_image, right_image, progress
|
| 166 |
|
| 167 |
def start_session(doctor_name):
|
| 168 |
"""Start a new evaluation session."""
|
|
@@ -180,19 +138,10 @@ def start_session(doctor_name):
|
|
| 180 |
|
| 181 |
return update_display()
|
| 182 |
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
def update_display():
|
| 186 |
-
"""Update the display with current image pair."""
|
| 187 |
if not state["session_active"] or state["current_index"] >= len(state["image_pairs"]):
|
| 188 |
-
|
| 189 |
-
state["session_active"] = False
|
| 190 |
-
return (
|
| 191 |
-
gr.update(visible=False),
|
| 192 |
-
None,
|
| 193 |
-
None,
|
| 194 |
-
gr.update(value="✅ Evaluation complete! All images have been reviewed.")
|
| 195 |
-
)
|
| 196 |
|
| 197 |
current_pair = state["image_pairs"][state["current_index"]]
|
| 198 |
|
|
@@ -211,10 +160,26 @@ def update_display():
|
|
| 211 |
condition = current_pair['condition']
|
| 212 |
progress = f"Image {state['current_index'] + 1} of {len(state['image_pairs'])}"
|
| 213 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 214 |
return (
|
| 215 |
gr.update(visible=True),
|
| 216 |
-
|
| 217 |
-
|
| 218 |
gr.update(value=f"{progress} | Condition: {condition}")
|
| 219 |
)
|
| 220 |
|
|
|
|
| 84 |
df.to_csv(filepath, index=False)
|
| 85 |
return filepath, filename
|
| 86 |
|
| 87 |
+
def record_preference(choice):
|
| 88 |
+
"""Record the doctor's preference and move to next image."""
|
|
|
|
|
|
|
| 89 |
if not state["session_active"]:
|
| 90 |
+
return None, None, "Session not active.", ""
|
| 91 |
|
| 92 |
current_pair = state["image_pairs"][state["current_index"]]
|
| 93 |
+
|
| 94 |
+
if choice == "A":
|
| 95 |
+
preferred_source = state["current_left_source"]
|
| 96 |
+
else: # choice == "B"
|
| 97 |
+
preferred_source = state["current_right_source"]
|
| 98 |
|
| 99 |
state["evaluations"].append({
|
| 100 |
'timestamp': datetime.now().isoformat(),
|
|
|
|
| 106 |
|
| 107 |
state["current_index"] += 1
|
| 108 |
|
| 109 |
+
left_img, right_img, condition, progress = get_current_display()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
|
| 111 |
+
if left_img is None:
|
| 112 |
+
state["session_active"] = False
|
| 113 |
+
return None, None, f"{progress} | Condition: {condition}", ""
|
| 114 |
|
| 115 |
+
return left_img, right_img, f"{progress} | Condition: {condition}", ""
|
| 116 |
+
|
| 117 |
+
def get_preference_a():
|
| 118 |
+
"""Wrapper for preference A."""
|
| 119 |
+
return record_preference("A")
|
| 120 |
|
| 121 |
def get_preference_b():
|
| 122 |
"""Wrapper for preference B."""
|
| 123 |
+
return record_preference("B")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
|
| 125 |
def start_session(doctor_name):
|
| 126 |
"""Start a new evaluation session."""
|
|
|
|
| 138 |
|
| 139 |
return update_display()
|
| 140 |
|
| 141 |
+
def get_current_display():
|
| 142 |
+
"""Get current image pair and metadata."""
|
|
|
|
|
|
|
| 143 |
if not state["session_active"] or state["current_index"] >= len(state["image_pairs"]):
|
| 144 |
+
return None, None, "", ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
|
| 146 |
current_pair = state["image_pairs"][state["current_index"]]
|
| 147 |
|
|
|
|
| 160 |
condition = current_pair['condition']
|
| 161 |
progress = f"Image {state['current_index'] + 1} of {len(state['image_pairs'])}"
|
| 162 |
|
| 163 |
+
return left_image, right_image, condition, progress
|
| 164 |
+
|
| 165 |
+
def update_display():
|
| 166 |
+
"""Update the display with current image pair."""
|
| 167 |
+
left_img, right_img, condition, progress = get_current_display()
|
| 168 |
+
|
| 169 |
+
if left_img is None:
|
| 170 |
+
# Session complete
|
| 171 |
+
state["session_active"] = False
|
| 172 |
+
return (
|
| 173 |
+
gr.update(visible=False),
|
| 174 |
+
None,
|
| 175 |
+
None,
|
| 176 |
+
gr.update(visible=True, value="✅ Evaluation complete! All images have been reviewed.")
|
| 177 |
+
)
|
| 178 |
+
|
| 179 |
return (
|
| 180 |
gr.update(visible=True),
|
| 181 |
+
left_img,
|
| 182 |
+
right_img,
|
| 183 |
gr.update(value=f"{progress} | Condition: {condition}")
|
| 184 |
)
|
| 185 |
|