Update app.py
Browse files
app.py
CHANGED
@@ -1,57 +1,77 @@
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
3 |
-
|
4 |
-
from file_processing import
|
5 |
from entity_recognition import process_text
|
6 |
from utils import safe_dataframe
|
7 |
|
8 |
-
|
|
|
|
|
|
|
9 |
"""Processes the uploaded file and extracts medical data."""
|
10 |
-
# processor = FileProcessorFactory.get_processor(file.name) # Get the correct processor
|
11 |
|
12 |
-
#
|
13 |
-
|
|
|
|
|
|
|
14 |
|
15 |
-
# text = processor.extract_text(file.name) # Extract content
|
16 |
-
text = read_file(file.name) # Extract content
|
17 |
-
output = process_text(text) # Perform entity recognition
|
18 |
-
|
19 |
metadata = output["metadata"]
|
20 |
|
21 |
-
# Convert extracted data safely
|
22 |
-
highs = safe_dataframe(output["reds"], "high")
|
23 |
-
lows = safe_dataframe(output["reds"], "low")
|
24 |
-
labtests = safe_dataframe(output, "lab_tests")
|
25 |
|
26 |
metadata_str = f"**Patient Name:** {metadata['patient_name']}\n\n" \
|
27 |
-
f"**Age:** {metadata['age']}\n\n" \
|
28 |
f"**Gender:** {metadata['gender']}\n\n" \
|
29 |
f"**Lab Name:** {metadata['lab_name']}\n\n" \
|
30 |
f"**Report Date:** {metadata['report_date']}"
|
31 |
|
32 |
print(f"Processed report for {metadata['patient_name']}")
|
33 |
|
34 |
-
return metadata_str
|
|
|
35 |
|
36 |
-
# β
Gradio Interface
|
37 |
with gr.Blocks() as demo:
|
38 |
-
gr.Markdown("# π₯ Medical Lab Report
|
39 |
|
40 |
with gr.Row():
|
41 |
-
|
42 |
-
submit_btn = gr.Button("
|
43 |
|
44 |
-
metadata_output = gr.Markdown("**Patient Name: Prashasst Dongre...**")
|
45 |
-
|
46 |
-
with gr.Row():
|
47 |
-
high_output = gr.Dataframe(label="πΊ High Values")
|
48 |
-
low_output = gr.Dataframe(label="π» Low Values")
|
49 |
|
50 |
-
|
51 |
-
|
|
|
52 |
|
53 |
-
|
|
|
|
|
54 |
|
55 |
-
|
|
|
|
|
56 |
|
57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
3 |
+
import easyocr
|
4 |
+
from file_processing import FileProcessor
|
5 |
from entity_recognition import process_text
|
6 |
from utils import safe_dataframe
|
7 |
|
8 |
+
reader = easyocr.Reader(['en'], gpu=True) # Initialize OCR model
|
9 |
+
|
10 |
+
|
11 |
+
def extract_it(file):
|
12 |
"""Processes the uploaded file and extracts medical data."""
|
|
|
13 |
|
14 |
+
text = read_file(file.name, reader) # Read the file (implement `read_file`)
|
15 |
+
print("Performing NER...")
|
16 |
+
global output
|
17 |
+
output = process_text(text) # Perform entity recognition (implement `process_text`)
|
18 |
+
|
19 |
|
|
|
|
|
|
|
|
|
20 |
metadata = output["metadata"]
|
21 |
|
|
|
|
|
|
|
|
|
22 |
|
23 |
metadata_str = f"**Patient Name:** {metadata['patient_name']}\n\n" \
|
24 |
+
f"**Age:** {metadata['age']} \n\n" \
|
25 |
f"**Gender:** {metadata['gender']}\n\n" \
|
26 |
f"**Lab Name:** {metadata['lab_name']}\n\n" \
|
27 |
f"**Report Date:** {metadata['report_date']}"
|
28 |
|
29 |
print(f"Processed report for {metadata['patient_name']}")
|
30 |
|
31 |
+
return metadata_str
|
32 |
+
|
33 |
|
|
|
34 |
with gr.Blocks() as demo:
|
35 |
+
gr.Markdown("# π₯ Medical Lab Test Report Extracter")
|
36 |
|
37 |
with gr.Row():
|
38 |
+
file_input = gr.File(label="π Upload Report")
|
39 |
+
# submit_btn = gr.Button("Extract")
|
40 |
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
+
# metadata_md = gr.Markdown("Report will show below....")
|
43 |
+
# submit_btn.click(fn=extract_it,inputs=file_input,outputs=metadata_md)
|
44 |
+
|
45 |
|
46 |
+
@gr.render(inputs=file_input,triggers=[file_input.upload])
|
47 |
+
def extract_it(file):
|
48 |
+
"""Processes the uploaded file and extracts medical data."""
|
49 |
|
50 |
+
text = read_file(file.name, reader) # Read the file (implement `read_file`)
|
51 |
+
print("Performing NER...")
|
52 |
+
output = process_text(text) # Perform entity recognition (implement `process_text`)
|
53 |
|
54 |
|
55 |
+
metadata = output["metadata"]
|
56 |
+
|
57 |
+
|
58 |
+
metadata_str = f"**Patient Name:** {metadata['patient_name']}\n\n" \
|
59 |
+
f"**Age:** {metadata['age']} \n\n" \
|
60 |
+
f"**Gender:** {metadata['gender']}\n\n" \
|
61 |
+
f"**Lab Name:** {metadata['lab_name']}\n\n" \
|
62 |
+
f"**Report Date:** {metadata['report_date']}"
|
63 |
+
|
64 |
+
print(f"Processed report for {metadata['patient_name']}")
|
65 |
+
metadata_md = gr.Markdown(metadata_str)
|
66 |
+
|
67 |
+
for test in output["report"]:
|
68 |
+
test_type = test["test_type"]
|
69 |
+
lab_tests = safe_dataframe(test,"lab_tests")
|
70 |
+
|
71 |
+
gr.Markdown(f"### π Test : {test_type}")
|
72 |
+
gr.Dataframe(lab_tests)
|
73 |
+
|
74 |
+
gr.JSON(output,label="π Extracted Report")
|
75 |
+
|
76 |
+
|
77 |
+
demo.launch(debug=True, share=True)
|