Spaces:
Paused
Paused
kgupta21 commited on
Commit ·
4c3ec34
1
Parent(s): 9481ab3
Enhance ground truth handling - maintain analysis capability when findings are hidden
Browse files75 unmodified lines76777879808182838485868788899091929394959697989910010112 unmodified lines1141151161171181191204 unmodified lines1251261271281291301313 unmodified lines13513613713813914014114275 unmodified lines# Get the image, findings, and impressionimage = random_case['image']findings = "" if hide_ground_truth else random_case['findings']impression = "" if hide_ground_truth else random_case['impression']return image, findings, impressionexcept Exception as e:logger.error(f"Error loading random case: {str(e)}")return None, "Error loading case", "Error loading case"def process_case(image, user_findings, hide_ground_truth, api_key, current_findings="", current_impression=""):if hide_ground_truth:return "", "", ""else:analysis = analyze_report(user_findings, current_findings, current_impression, api_key)return current_findings, current_impression, analysis# Create the Gradio interfacewith gr.Blocks() as demo:gr.Markdown(f"# Radiology Report Training System v{APP_VERSION}")gr.Markdown("### Practice your chest X-ray reading and reporting skills")with gr.Row():with gr.Column():image_display = gr.Image(label="Chest X-ray Image", type="pil")12 unmodified linesload_btn.click(fn=load_random_case,inputs=[hide_truth],outputs=[image_display, ground_truth_findings, ground_truth_impression])submit_btn.click(4 unmodified lineshide_truth,api_key_input,ground_truth_findings,ground_truth_impression],outputs=[ground_truth_findings,3 unmodified lines)hide_truth.change(fn=lambda x: ("", "", "") if x else (ground_truth_findings.value, ground_truth_impression.value, ""),inputs=[hide_truth],outputs=[ground_truth_findings, ground_truth_impression, analysis_output])75 unmodified lines76777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611712 unmodified lines1301311321331341351361371381391401411424 unmodified lines1471481491501511521531541553 unmodified lines15916016116216316416516675 unmodified lines# Get the image, findings, and impressionimage = random_case['image']# Store full findings and impression regardless of hide_ground_truthfindings = random_case['findings']impression = random_case['impression']# Only hide display if hide_ground_truth is Truedisplay_findings = "" if hide_ground_truth else findingsdisplay_impression = "" if hide_ground_truth else impression# Return both display values and actual valuesreturn image, display_findings, display_impression, findings, impressionexcept Exception as e:logger.error(f"Error loading random case: {str(e)}")return None, "Error loading case", "Error loading case", "", ""def process_case(image, user_findings, hide_ground_truth, api_key, current_findings="", current_impression="", actual_findings="", actual_impression=""):# Use actual findings/impression for analysis if they exist, otherwise fall back to current valuesfindings_for_analysis = actual_findings if actual_findings else current_findingsimpression_for_analysis = actual_impression if actual_impression else current_impressionanalysis = analyze_report(user_findings, findings_for_analysis, impression_for_analysis, api_key)# Return display values based on hide_ground_truthdisplay_findings = "" if hide_ground_truth else findings_for_analysisdisplay_impression = "" if hide_ground_truth else impression_for_analysisreturn display_findings, display_impression, analysis# Create the Gradio interfacewith gr.Blocks() as demo:gr.Markdown(f"# Radiology Report Training System v{APP_VERSION}")gr.Markdown("### Practice your chest X-ray reading and reporting skills")# Add state variables to store actual findings and impressionactual_findings_state = gr.State("")actual_impression_state = gr.State("")with gr.Row():with gr.Column():image_display = gr.Image(label="Chest X-ray Image", type="pil")12 unmodified linesload_btn.click(fn=load_random_case,inputs=[hide_truth],outputs=[image_display,ground_truth_findings,ground_truth_impression,actual_findings_state,actual_impression_state])submit_btn.click(4 unmodified lineshide_truth,api_key_input,ground_truth_findings,ground_truth_impression,actual_findings_state,actual_impression_state],outputs=[ground_truth_findings,3 unmodified lines)hide_truth.change(fn=lambda x, f, i: ("" if x else f, "" if x else i, ""),inputs=[hide_truth, actual_findings_state, actual_impression_state],outputs=[ground_truth_findings, ground_truth_impression, analysis_output])
app.py+38-14