Spaces:
Sleeping
Sleeping
kgupta21
commited on
Commit
·
4c3ec34
1
Parent(s):
9481ab3
Enhance ground truth handling - maintain analysis capability when findings are hidden
Browse files
app.py
CHANGED
@@ -76,26 +76,42 @@ def load_random_case(hide_ground_truth):
|
|
76 |
|
77 |
# Get the image, findings, and impression
|
78 |
image = random_case['image']
|
79 |
-
findings
|
80 |
-
|
|
|
81 |
|
82 |
-
|
|
|
|
|
|
|
|
|
|
|
83 |
except Exception as e:
|
84 |
logger.error(f"Error loading random case: {str(e)}")
|
85 |
-
return None, "Error loading case", "Error loading case"
|
86 |
|
87 |
-
def process_case(image, user_findings, hide_ground_truth, api_key, current_findings="", current_impression=""):
|
88 |
-
if
|
89 |
-
|
90 |
-
else
|
91 |
-
|
92 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
|
94 |
# Create the Gradio interface
|
95 |
with gr.Blocks() as demo:
|
96 |
gr.Markdown(f"# Radiology Report Training System v{APP_VERSION}")
|
97 |
gr.Markdown("### Practice your chest X-ray reading and reporting skills")
|
98 |
|
|
|
|
|
|
|
|
|
99 |
with gr.Row():
|
100 |
with gr.Column():
|
101 |
image_display = gr.Image(label="Chest X-ray Image", type="pil")
|
@@ -114,7 +130,13 @@ with gr.Blocks() as demo:
|
|
114 |
load_btn.click(
|
115 |
fn=load_random_case,
|
116 |
inputs=[hide_truth],
|
117 |
-
outputs=[
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
)
|
119 |
|
120 |
submit_btn.click(
|
@@ -125,7 +147,9 @@ with gr.Blocks() as demo:
|
|
125 |
hide_truth,
|
126 |
api_key_input,
|
127 |
ground_truth_findings,
|
128 |
-
ground_truth_impression
|
|
|
|
|
129 |
],
|
130 |
outputs=[
|
131 |
ground_truth_findings,
|
@@ -135,8 +159,8 @@ with gr.Blocks() as demo:
|
|
135 |
)
|
136 |
|
137 |
hide_truth.change(
|
138 |
-
fn=lambda x: (""
|
139 |
-
inputs=[hide_truth],
|
140 |
outputs=[ground_truth_findings, ground_truth_impression, analysis_output]
|
141 |
)
|
142 |
|
|
|
76 |
|
77 |
# Get the image, findings, and impression
|
78 |
image = random_case['image']
|
79 |
+
# Store full findings and impression regardless of hide_ground_truth
|
80 |
+
findings = random_case['findings']
|
81 |
+
impression = random_case['impression']
|
82 |
|
83 |
+
# Only hide display if hide_ground_truth is True
|
84 |
+
display_findings = "" if hide_ground_truth else findings
|
85 |
+
display_impression = "" if hide_ground_truth else impression
|
86 |
+
|
87 |
+
# Return both display values and actual values
|
88 |
+
return image, display_findings, display_impression, findings, impression
|
89 |
except Exception as e:
|
90 |
logger.error(f"Error loading random case: {str(e)}")
|
91 |
+
return None, "Error loading case", "Error loading case", "", ""
|
92 |
|
93 |
+
def process_case(image, user_findings, hide_ground_truth, api_key, current_findings="", current_impression="", actual_findings="", actual_impression=""):
|
94 |
+
# Use actual findings/impression for analysis if they exist, otherwise fall back to current values
|
95 |
+
findings_for_analysis = actual_findings if actual_findings else current_findings
|
96 |
+
impression_for_analysis = actual_impression if actual_impression else current_impression
|
97 |
+
|
98 |
+
analysis = analyze_report(user_findings, findings_for_analysis, impression_for_analysis, api_key)
|
99 |
+
|
100 |
+
# Return display values based on hide_ground_truth
|
101 |
+
display_findings = "" if hide_ground_truth else findings_for_analysis
|
102 |
+
display_impression = "" if hide_ground_truth else impression_for_analysis
|
103 |
+
|
104 |
+
return display_findings, display_impression, analysis
|
105 |
|
106 |
# Create the Gradio interface
|
107 |
with gr.Blocks() as demo:
|
108 |
gr.Markdown(f"# Radiology Report Training System v{APP_VERSION}")
|
109 |
gr.Markdown("### Practice your chest X-ray reading and reporting skills")
|
110 |
|
111 |
+
# Add state variables to store actual findings and impression
|
112 |
+
actual_findings_state = gr.State("")
|
113 |
+
actual_impression_state = gr.State("")
|
114 |
+
|
115 |
with gr.Row():
|
116 |
with gr.Column():
|
117 |
image_display = gr.Image(label="Chest X-ray Image", type="pil")
|
|
|
130 |
load_btn.click(
|
131 |
fn=load_random_case,
|
132 |
inputs=[hide_truth],
|
133 |
+
outputs=[
|
134 |
+
image_display,
|
135 |
+
ground_truth_findings,
|
136 |
+
ground_truth_impression,
|
137 |
+
actual_findings_state,
|
138 |
+
actual_impression_state
|
139 |
+
]
|
140 |
)
|
141 |
|
142 |
submit_btn.click(
|
|
|
147 |
hide_truth,
|
148 |
api_key_input,
|
149 |
ground_truth_findings,
|
150 |
+
ground_truth_impression,
|
151 |
+
actual_findings_state,
|
152 |
+
actual_impression_state
|
153 |
],
|
154 |
outputs=[
|
155 |
ground_truth_findings,
|
|
|
159 |
)
|
160 |
|
161 |
hide_truth.change(
|
162 |
+
fn=lambda x, f, i: ("" if x else f, "" if x else i, ""),
|
163 |
+
inputs=[hide_truth, actual_findings_state, actual_impression_state],
|
164 |
outputs=[ground_truth_findings, ground_truth_impression, analysis_output]
|
165 |
)
|
166 |
|