Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
|
|
|
|
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
|
| 11 |
|
|
@@ -15,17 +23,22 @@ with gr.Blocks() as demo:
|
|
| 15 |
|
| 16 |
with gr.Row():
|
| 17 |
file_input = gr.File(label="π Upload Report")
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
|
| 21 |
-
# metadata_md = gr.Markdown("Report will show below....")
|
| 22 |
-
# submit_btn.click(fn=extract_it,inputs=file_input,outputs=metadata_md)
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
@gr.render(inputs=file_input,triggers=[file_input.upload])
|
| 27 |
def extract(file):
|
| 28 |
"""Processes the uploaded file and extracts medical data."""
|
|
|
|
|
|
|
| 29 |
|
| 30 |
text = read_file(file.name, reader) # Read the file (implement `read_file`)
|
| 31 |
print("Performing NER...")
|
|
@@ -44,6 +57,7 @@ with gr.Blocks() as demo:
|
|
| 44 |
print(f"Processed report for {metadata['patient_name']}")
|
| 45 |
metadata_md = gr.Markdown(metadata_str)
|
| 46 |
|
|
|
|
| 47 |
for test in output["report"]:
|
| 48 |
test_type = test["test_type"]
|
| 49 |
lab_tests = safe_dataframe(test,"lab_tests")
|
|
@@ -53,6 +67,7 @@ with gr.Blocks() as demo:
|
|
| 53 |
|
| 54 |
gr.JSON(output,label="π Extracted Report")
|
| 55 |
return output
|
| 56 |
-
|
|
|
|
| 57 |
|
| 58 |
demo.launch(debug=True, share=True)
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
import gradio as gr
|
| 4 |
import pandas as pd
|
| 5 |
import easyocr
|
| 6 |
+
from paddleocr import PaddleOCR
|
| 7 |
from file_processing import FileProcessor
|
| 8 |
from entity_recognition import process_text
|
| 9 |
from utils import safe_dataframe
|
| 10 |
|
| 11 |
+
|
| 12 |
+
# Initialize PaddleOCR globally (CPU mode)
|
| 13 |
+
reader = PaddleOCR(use_angle_cls=True, lang="en")
|
| 14 |
+
|
| 15 |
+
# reader = easyocr.Reader(['en'],download_enabled=True, gpu=True) # Initialize OCR model
|
| 16 |
+
|
| 17 |
|
| 18 |
|
| 19 |
|
|
|
|
| 23 |
|
| 24 |
with gr.Row():
|
| 25 |
file_input = gr.File(label="π Upload Report")
|
| 26 |
+
submit_btn = gr.Button("Extract",visible=False)
|
| 27 |
+
|
| 28 |
+
welcome_msg=gr.Markdown("# Please Upload any lab report file π and the processing will start automatically ")
|
| 29 |
+
|
| 30 |
+
def invisible():
|
| 31 |
+
return gr.update(visible=False)
|
| 32 |
+
file_input.upload(invisible,outputs=welcome_msg,api_name=False)
|
| 33 |
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
@gr.render(inputs=file_input,triggers=[file_input.upload])
|
| 38 |
def extract(file):
|
| 39 |
"""Processes the uploaded file and extracts medical data."""
|
| 40 |
+
# welcome_msg.update(visible=False)
|
| 41 |
+
|
| 42 |
|
| 43 |
text = read_file(file.name, reader) # Read the file (implement `read_file`)
|
| 44 |
print("Performing NER...")
|
|
|
|
| 57 |
print(f"Processed report for {metadata['patient_name']}")
|
| 58 |
metadata_md = gr.Markdown(metadata_str)
|
| 59 |
|
| 60 |
+
|
| 61 |
for test in output["report"]:
|
| 62 |
test_type = test["test_type"]
|
| 63 |
lab_tests = safe_dataframe(test,"lab_tests")
|
|
|
|
| 67 |
|
| 68 |
gr.JSON(output,label="π Extracted Report")
|
| 69 |
return output
|
| 70 |
+
output_JSON=gr.JSON(visible=False)
|
| 71 |
+
submit_btn.click(extract,inputs=file_input,outputs=output_JSON,api_name="extract_report")
|
| 72 |
|
| 73 |
demo.launch(debug=True, share=True)
|