Prashasst commited on
Commit
6087673
·
verified ·
1 Parent(s): f6f5a9a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -23
app.py CHANGED
@@ -5,30 +5,9 @@ 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:
@@ -43,8 +22,9 @@ with gr.Blocks() as demo:
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`)
@@ -72,6 +52,7 @@ with gr.Blocks() as demo:
72
  gr.Dataframe(lab_tests)
73
 
74
  gr.JSON(output,label="📜 Extracted Report")
 
75
 
76
 
77
  demo.launch(debug=True, share=True)
 
5
  from entity_recognition import process_text
6
  from utils import safe_dataframe
7
 
8
+ reader = easyocr.Reader(['en'],download_enabled=True, gpu=True) # Initialize OCR model
9
 
10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
 
13
  with gr.Blocks() as demo:
 
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`)
 
52
  gr.Dataframe(lab_tests)
53
 
54
  gr.JSON(output,label="📜 Extracted Report")
55
+ return output
56
 
57
 
58
  demo.launch(debug=True, share=True)