File size: 2,055 Bytes
898d076 1449bf7 4f7c634 1e0b279 7eb51d2 1e0b279 7eb51d2 1449bf7 4f7c634 c937396 a6e539a 4f7c634 52bb493 c937396 898d076 4f7c634 4c39be6 4f7c634 898d076 4f7c634 898d076 4f7c634 6d2b657 898d076 4f7c634 898d076 6d2b657 de0131d 4f7c634 a6e539a 4f7c634 898d076 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
import gradio as gr
import pandas as pd
# from file_processing import FileProcessorFactory
from file_processing import read_file
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
text = read_file(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()
|