Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -84,6 +84,44 @@ def save_evaluations(evaluations, doctor_name):
|
|
| 84 |
df.to_csv(filepath, index=False)
|
| 85 |
return filepath, filename
|
| 86 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
def start_session(doctor_name):
|
| 88 |
"""Start a new evaluation session."""
|
| 89 |
if not doctor_name.strip():
|
|
@@ -238,13 +276,18 @@ with gr.Blocks(title="X-Ray Quality Evaluation") as demo:
|
|
| 238 |
)
|
| 239 |
|
| 240 |
# Event handlers
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 241 |
start_btn.click(
|
| 242 |
-
|
| 243 |
inputs=doctor_name_input,
|
| 244 |
-
outputs=[eval_section, error_section, result_message]
|
| 245 |
-
).then(
|
| 246 |
-
update_display,
|
| 247 |
-
outputs=[eval_section, image_a, image_b, progress_text]
|
| 248 |
)
|
| 249 |
|
| 250 |
pref_a.click(
|
|
|
|
| 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(),
|
| 101 |
+
'condition': current_pair['condition'],
|
| 102 |
+
'base_name': current_pair['base_name'],
|
| 103 |
+
'preference': preferred_source.capitalize(),
|
| 104 |
+
'doctor': state["doctor_name"]
|
| 105 |
+
})
|
| 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."""
|
| 127 |
if not doctor_name.strip():
|
|
|
|
| 276 |
)
|
| 277 |
|
| 278 |
# Event handlers
|
| 279 |
+
def start_and_display(doctor_name):
|
| 280 |
+
result = start_session(doctor_name)
|
| 281 |
+
if result[0]["visible"] == False:
|
| 282 |
+
return result[0], result[1], result[2], None, None, ""
|
| 283 |
+
else:
|
| 284 |
+
left_img, right_img, condition, progress = get_current_display()
|
| 285 |
+
return result[0], result[1], result[2], left_img, right_img, progress
|
| 286 |
+
|
| 287 |
start_btn.click(
|
| 288 |
+
start_and_display,
|
| 289 |
inputs=doctor_name_input,
|
| 290 |
+
outputs=[eval_section, error_section, result_message, image_a, image_b, progress_text]
|
|
|
|
|
|
|
|
|
|
| 291 |
)
|
| 292 |
|
| 293 |
pref_a.click(
|