import gradio as gr import pandas as pd from file_processing import FileProcessorFactory from entity_recognition import process_text from utils import safe_dataframe def show_to_UI(file): """Processes the uploaded file and extracts medical data.""" processor = FileProcessorFactory.get_processor(file.name) # Get the correct processor if processor is None: raise ValueError(f"Unsupported file format: {file.name}") text = processor.extract_text(file.name) # Extract content output = process_text(text) # Perform entity recognition metadata = output["metadata"] # Convert extracted data safely highs = safe_dataframe(output["reds"], "high") lows = safe_dataframe(output["reds"], "low") labtests = safe_dataframe(output, "lab_tests") metadata_str = f"**Patient Name:** {metadata['patient_name']}\n\n" \ f"**Age:** {metadata['age']}\n\n" \ f"**Gender:** {metadata['gender']}\n\n" \ f"**Lab Name:** {metadata['lab_name']}\n\n" \ f"**Report Date:** {metadata['report_date']}" print(f"Processed report for {metadata['patient_name']}") return metadata_str, highs, lows, labtests, output # ✅ Gradio Interface with gr.Blocks() as demo: gr.Markdown("# 🏥 Medical Lab Report Processor") with gr.Row(): pdf_input = gr.File(label="📂 Upload Report") submit_btn = gr.Button("Process") metadata_output = gr.Markdown("**Patient Name: Prashasst Dongre...**") with gr.Row(): high_output = gr.Dataframe(label="🔺 High Values") low_output = gr.Dataframe(label="🔻 Low Values") lab_test_output = gr.Dataframe(label="📊 Lab Test Results") output_JSON = gr.JSON(label="📜 Extracted Report") submit_btn.click(show_to_UI, inputs=[pdf_input], outputs=[metadata_output, high_output, low_output, lab_test_output, output_JSON]) demo.launch()