Spaces:
Sleeping
Sleeping
WebashalarForML
commited on
Commit
•
824f4e9
1
Parent(s):
a25ce68
Update app.py
Browse files
app.py
CHANGED
@@ -72,7 +72,7 @@ def upload_file():
|
|
72 |
session['uploaded_files'] = uploaded_files
|
73 |
flash('Files successfully uploaded')
|
74 |
logging.info(f"Files successfully uploaded: {uploaded_files}")
|
75 |
-
return process_file()
|
76 |
|
77 |
@app.route('/remove_file',methods=['POST'])
|
78 |
def remove_file():
|
@@ -108,56 +108,71 @@ def reset_upload():
|
|
108 |
flash('No file to remove.')
|
109 |
return redirect(url_for('index'))
|
110 |
|
111 |
-
@app.route('/
|
112 |
-
def process_file():
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
|
119 |
-
|
120 |
-
|
|
|
121 |
|
122 |
-
|
123 |
-
|
124 |
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
logging.info(f"LLM text: {llmText}")
|
132 |
-
|
133 |
-
LLMdata = Data_Extractor(llmText)
|
134 |
-
logging.info(f"LLM data: {LLMdata}")
|
135 |
-
|
136 |
-
except Exception as e:
|
137 |
-
logging.error(f"Error during LLM processing: {e}")
|
138 |
-
logging.info("Running backup model...")
|
139 |
-
|
140 |
-
LLMdata = {}
|
141 |
-
extracted_text, processed_Img = extract_text_from_images(file_paths)
|
142 |
-
logging.info(f"Extracted text(Backup): {extracted_text}")
|
143 |
-
logging.info(f"Processed images(Backup): {processed_Img}")
|
144 |
-
if extracted_text:
|
145 |
-
text = json_to_llm_str(extracted_text)
|
146 |
-
LLMdata = NER_Model(text)
|
147 |
-
logging.info(f"NER model data: {LLMdata}")
|
148 |
-
else:
|
149 |
-
logging.warning("No extracted text available for backup model")
|
150 |
-
|
151 |
-
cont_data = process_extracted_text(extracted_text)
|
152 |
-
logging.info(f"Contextual data: {cont_data}")
|
153 |
-
|
154 |
-
processed_data = process_resume_data(LLMdata, cont_data, extracted_text)
|
155 |
-
logging.info(f"Processed data: {processed_data}")
|
156 |
-
|
157 |
-
session['processed_data'] = processed_data
|
158 |
-
session['processed_Img'] = processed_Img
|
159 |
-
flash('Data processed and analyzed successfully')
|
160 |
-
logging.info("Data processed and analyzed successfully")
|
161 |
return redirect(url_for('result'))
|
162 |
|
163 |
@app.route('/result')
|
|
|
72 |
session['uploaded_files'] = uploaded_files
|
73 |
flash('Files successfully uploaded')
|
74 |
logging.info(f"Files successfully uploaded: {uploaded_files}")
|
75 |
+
return process_file(uploaded_files)
|
76 |
|
77 |
@app.route('/remove_file',methods=['POST'])
|
78 |
def remove_file():
|
|
|
108 |
flash('No file to remove.')
|
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')
|