File size: 1,832 Bytes
898d076
 
f6f5a9a
 
4f7c634
 
 
6087673
f6f5a9a
 
 
898d076
 
f6f5a9a
6d2b657
898d076
f6f5a9a
 
6d2b657
4f7c634
f6f5a9a
 
 
4f7c634
6087673
f6f5a9a
6087673
f6f5a9a
4f7c634
f6f5a9a
 
 
4f7c634
898d076
f6f5a9a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6087673
f6f5a9a
 
 
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
import easyocr
from file_processing import FileProcessor
from entity_recognition import process_text
from utils import safe_dataframe

reader = easyocr.Reader(['en'],download_enabled=True, gpu=True)  # Initialize OCR model




with gr.Blocks() as demo:
    gr.Markdown("# πŸ₯ Medical Lab Test Report Extracter")

    with gr.Row():
        file_input = gr.File(label="πŸ“‚ Upload Report")
        # submit_btn = gr.Button("Extract")

    
    # metadata_md = gr.Markdown("Report will show below....")
    # submit_btn.click(fn=extract_it,inputs=file_input,outputs=metadata_md)



    @gr.render(inputs=file_input,triggers=[file_input.upload])
    def extract(file):
        """Processes the uploaded file and extracts medical data."""

        text = read_file(file.name, reader)  # Read the file (implement `read_file`)
        print("Performing NER...")
        output = process_text(text)  # Perform entity recognition (implement `process_text`)


        metadata = output["metadata"]


        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']}")
        metadata_md = gr.Markdown(metadata_str)

        for test in output["report"]:
            test_type = test["test_type"]
            lab_tests = safe_dataframe(test,"lab_tests")

            gr.Markdown(f"### πŸ“Š Test : {test_type}")
            gr.Dataframe(lab_tests)

        gr.JSON(output,label="πŸ“œ Extracted Report")
        return output
    

demo.launch(debug=True, share=True)