WebashalarForML commited on
Commit
230d404
·
verified ·
1 Parent(s): 6032761

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -64
app.py CHANGED
@@ -109,72 +109,60 @@ def reset_upload():
109
  return redirect(url_for('index'))
110
 
111
  @app.route('/process_file/<filename>', methods=['GET', 'POST'])
112
- def process_file(filename):
 
 
 
 
 
 
 
 
 
 
 
113
  try:
114
- uploaded_files = session.get('uploaded_files', [])
115
- if not uploaded_files:
116
- print('No files selected for processing')
117
- logging.warning("No files selected for processing")
118
- return redirect(url_for('index'))
119
-
120
- # Joining the base and the requested path
121
- file_paths = [os.path.join(app.config['UPLOAD_FOLDER'], filename) for filename in uploaded_files]
122
- logging.info(f"Processing files: {file_paths}")
123
-
124
- extracted_text = {}
125
- processed_Img = {}
126
-
127
- # Try to process using the main model (Mistral 7b)
128
- try:
129
- extracted_text, processed_Img = extract_text_from_images(file_paths)
130
- logging.info(f"Extracted text: {extracted_text}")
131
- logging.info(f"Processed images: {processed_Img}")
132
-
133
  #run the model code only if the text is extracted.
134
- if extracted_text:
135
- llmText = json_to_llm_str(extracted_text)
136
- logging.info(f"LLM text: {llmText}")
137
-
138
- #run the model code only if the text is extracted.
139
- LLMdata = Data_Extractor(llmText)
140
- print("Json Output from model------------>",LLMdata)
141
- logging.info(f"LLM data: {LLMdata}")
142
- else:
143
- raise ('The text is not detected in the OCR')
144
-
145
- except Exception as model_error:
146
- logging.error(f"Error during LLM processing: {model_error}")
147
- logging.info("Running backup model...")
148
-
149
- # Use backup model in case of errors
150
- LLMdata = {}
151
- extracted_text, processed_Img = extract_text_from_images(file_paths)
152
- logging.info(f"Extracted text (Backup): {extracted_text}")
153
- logging.info(f"Processed images (Backup): {processed_Img}")
154
-
155
- if extracted_text:
156
- text = json_to_llm_str(extracted_text)
157
- LLMdata = NER_Model(text)
158
- print("Json Output from model------------>",LLMdata)
159
- logging.info(f"NER model data: {LLMdata}")
160
- else:
161
- logging.warning("No extracted text available for backup model")
162
-
163
- # Process extracted text and structure the output
164
- cont_data = process_extracted_text(extracted_text)
165
- logging.info(f"Contextual data: {cont_data}")
166
-
167
- processed_data = process_resume_data(LLMdata, cont_data, extracted_text)
168
- logging.info(f"Processed data: {processed_data}")
169
-
170
- # Save data in session for later use
171
- session['processed_data'] = processed_data
172
- session['processed_Img'] = processed_Img
173
-
174
- print('Data processed and analyzed successfully')
175
- logging.info("Data processed and analyzed successfully")
176
- return redirect(url_for('result'))
177
-
178
  @app.route('/result')
179
  def result():
180
  processed_data = session.get('processed_data', {})
 
109
  return redirect(url_for('index'))
110
 
111
  @app.route('/process_file/<filename>', methods=['GET', 'POST'])
112
+ def process_file(filename):
113
+ uploaded_files = session.get('uploaded_files', [])
114
+ if not uploaded_files:
115
+ print('No files selected for processing')
116
+ logging.warning("No files selected for processing")
117
+ return redirect(url_for('index'))
118
+ # Joining the base and the requested path
119
+ file_paths = [os.path.join(app.config['UPLOAD_FOLDER'], filename) for filename in uploaded_files]
120
+ logging.info(f"Processing files: {file_paths}")
121
+ extracted_text = {}
122
+ processed_Img = {}
123
+ # Try to process using the main model (Mistral 7b)
124
  try:
125
+ extracted_text, processed_Img = extract_text_from_images(file_paths)
126
+ logging.info(f"Extracted text: {extracted_text}")
127
+ logging.info(f"Processed images: {processed_Img}")
128
+ #run the model code only if the text is extracted.
129
+ if extracted_text:
130
+ llmText = json_to_llm_str(extracted_text)
131
+ logging.info(f"LLM text: {llmText}")
 
 
 
 
 
 
 
 
 
 
 
 
132
  #run the model code only if the text is extracted.
133
+ LLMdata = Data_Extractor(llmText)
134
+ print("Json Output from model------------>",LLMdata)
135
+ logging.info(f"LLM data: {LLMdata}")
136
+ else:
137
+ raise ('The text is not detected in the OCR')
138
+ except Exception as model_error:
139
+ logging.error(f"Error during LLM processing: {model_error}")
140
+ logging.info("Running backup model...")
141
+ # Use backup model in case of errors
142
+ LLMdata = {}
143
+ extracted_text, processed_Img = extract_text_from_images(file_paths)
144
+ logging.info(f"Extracted text (Backup): {extracted_text}")
145
+ logging.info(f"Processed images (Backup): {processed_Img}")
146
+
147
+ if extracted_text:
148
+ text = json_to_llm_str(extracted_text)
149
+ LLMdata = NER_Model(text)
150
+ print("Json Output from model------------>",LLMdata)
151
+ logging.info(f"NER model data: {LLMdata}")
152
+ else:
153
+ logging.warning("No extracted text available for backup model")
154
+ # Process extracted text and structure the output
155
+ cont_data = process_extracted_text(extracted_text)
156
+ logging.info(f"Contextual data: {cont_data}")
157
+ processed_data = process_resume_data(LLMdata, cont_data, extracted_text)
158
+ logging.info(f"Processed data: {processed_data}")
159
+ # Save data in session for later use
160
+ session['processed_data'] = processed_data
161
+ session['processed_Img'] = processed_Img
162
+ print('Data processed and analyzed successfully')
163
+ logging.info("Data processed and analyzed successfully")
164
+ return redirect(url_for('result'))
165
+
 
 
 
 
 
 
 
 
 
 
 
166
  @app.route('/result')
167
  def result():
168
  processed_data = session.get('processed_data', {})