File size: 1,956 Bytes
898d076
 
f629a2f
4f7c634
 
 
 
 
7eb51d2
 
 
 
 
 
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
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()