WebashalarForML commited on
Commit
1acf205
1 Parent(s): 6c1d851

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -3
app.py CHANGED
@@ -31,6 +31,9 @@ if not os.path.exists(app.config['UPLOAD_FOLDER']):
31
  if not os.path.exists(app.config['RESULT_FOLDER']):
32
  os.makedirs(app.config['RESULT_FOLDER'])
33
 
 
 
 
34
  @app.route('/')
35
  def index():
36
  uploaded_files = session.get('uploaded_files', [])
@@ -91,6 +94,7 @@ def process_file():
91
  file_paths = [os.path.join(app.config['UPLOAD_FOLDER'], filename) for filename in uploaded_files]
92
  logging.info(f"Processing files: {file_paths}")
93
 
 
94
  try:
95
  # Extract text from all images
96
  extracted_text, processed_Img = extract_text_from_images(file_paths, RESULT_FOLDER)
@@ -109,9 +113,12 @@ def process_file():
109
  logging.info("Running backup model...")
110
 
111
  # Run the backup model in case of an exception
112
- text = json_to_llm_str(extracted_text)
113
- LLMdata = NER_Model(text)
114
- logging.info(f"NER model data: {LLMdata}")
 
 
 
115
 
116
  cont_data = process_extracted_text(extracted_text)
117
  logging.info(f"Contextual data: {cont_data}")
 
31
  if not os.path.exists(app.config['RESULT_FOLDER']):
32
  os.makedirs(app.config['RESULT_FOLDER'])
33
 
34
+ # Set the PaddleOCR home directory to a writable location
35
+ os.environ['PADDLEOCR_HOME'] = os.path.join(app.config['UPLOAD_FOLDER'], '.paddleocr') # Change made here
36
+
37
  @app.route('/')
38
  def index():
39
  uploaded_files = session.get('uploaded_files', [])
 
94
  file_paths = [os.path.join(app.config['UPLOAD_FOLDER'], filename) for filename in uploaded_files]
95
  logging.info(f"Processing files: {file_paths}")
96
 
97
+ extracted_text = {} # Initialize extracted_text # Change made here
98
  try:
99
  # Extract text from all images
100
  extracted_text, processed_Img = extract_text_from_images(file_paths, RESULT_FOLDER)
 
113
  logging.info("Running backup model...")
114
 
115
  # Run the backup model in case of an exception
116
+ if extracted_text: # Ensure extracted_text has a value before using it # Change made here
117
+ text = json_to_llm_str(extracted_text)
118
+ LLMdata = NER_Model(text)
119
+ logging.info(f"NER model data: {LLMdata}")
120
+ else:
121
+ logging.warning("No extracted text available for backup model") # Change made here
122
 
123
  cont_data = process_extracted_text(extracted_text)
124
  logging.info(f"Contextual data: {cont_data}")