vasdevaman6 commited on
Commit
46f882e
·
verified ·
1 Parent(s): 4bf981c

Upload ocr_utils.py

Browse files
Files changed (1) hide show
  1. ocr_utils.py +8 -2
ocr_utils.py CHANGED
@@ -5,9 +5,13 @@ import os
5
  # 'en' is for English language
6
  # In ocr_utils.py
7
  # Set model_storage_directory to a folder inside your writable app directory (/app)
8
- MODELS_DIR = os.path.join(os.getcwd(), 'easyocr_models')
 
9
  os.makedirs(MODELS_DIR, exist_ok=True) # Ensure the directory exists
10
 
 
 
 
11
  reader = easyocr.Reader(['en'], model_storage_directory=MODELS_DIR)
12
 
13
  def extract_keywords_from_report(file_path):
@@ -62,11 +66,13 @@ def score_text_for_risk(text):
62
 
63
  # Cap the score at 1.0
64
  return min(score, 1.0), keywords_found
 
65
  # Example usage (Optional, can be removed once integrated into app.py)
66
  if __name__ == '__main__':
67
  # You would test this with a sample image report
68
  # print(extract_keywords_from_report('path/to/sample_report.jpg'))
69
  pass
 
70
  if __name__ == '__main__':
71
  # ⚠️ Replace 'test_report.png' with the actual file name
72
  test_file_path = 'test_report.png'
@@ -79,4 +85,4 @@ if __name__ == '__main__':
79
  print(f"Extracted Text: {extracted_text}")
80
  print(f"Calculated Risk Score: {risk_score}")
81
  else:
82
- print("Error: test_report.png not found. Cannot run direct test.")
 
5
  # 'en' is for English language
6
  # In ocr_utils.py
7
  # Set model_storage_directory to a folder inside your writable app directory (/app)
8
+ # ⚠️ Use absolute path to prevent EasyOCR from defaulting to /.EasyOCR
9
+ MODELS_DIR = "/app/easyocr_models" # <-- Changed to absolute path
10
  os.makedirs(MODELS_DIR, exist_ok=True) # Ensure the directory exists
11
 
12
+ # DEBUG: Verify the directory
13
+ print(f"[DEBUG] EasyOCR models directory: {MODELS_DIR}")
14
+
15
  reader = easyocr.Reader(['en'], model_storage_directory=MODELS_DIR)
16
 
17
  def extract_keywords_from_report(file_path):
 
66
 
67
  # Cap the score at 1.0
68
  return min(score, 1.0), keywords_found
69
+
70
  # Example usage (Optional, can be removed once integrated into app.py)
71
  if __name__ == '__main__':
72
  # You would test this with a sample image report
73
  # print(extract_keywords_from_report('path/to/sample_report.jpg'))
74
  pass
75
+
76
  if __name__ == '__main__':
77
  # ⚠️ Replace 'test_report.png' with the actual file name
78
  test_file_path = 'test_report.png'
 
85
  print(f"Extracted Text: {extracted_text}")
86
  print(f"Calculated Risk Score: {risk_score}")
87
  else:
88
+ print("Error: test_report.png not found. Cannot run direct test.")