|
import gradio as gr |
|
import pandas as pd |
|
|
|
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.""" |
|
|
|
|
|
|
|
|
|
|
|
|
|
text = read_file(file.name) |
|
output = process_text(text) |
|
|
|
metadata = output["metadata"] |
|
|
|
|
|
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 |
|
|
|
|
|
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() |
|
|
|
|
|
|