Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -164,6 +164,13 @@ def process_file():
|
|
| 164 |
logging.info(f"Extracted text blobs: {extracted_text}")
|
| 165 |
logging.info(f"Processed images: {processed_Img}")
|
| 166 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 167 |
# Regex fallback / augmentation from model text
|
| 168 |
cont_data = process_extracted_text(extracted_text)
|
| 169 |
logging.info(f"Contextual data: {cont_data}")
|
|
@@ -178,26 +185,28 @@ def process_file():
|
|
| 178 |
return redirect(url_for('result'))
|
| 179 |
|
| 180 |
except Exception as e:
|
| 181 |
-
logging.exception(f"Error during processing: {e}")
|
| 182 |
-
flash('
|
| 183 |
|
| 184 |
-
|
| 185 |
-
extracted_text, processed_Img = extract_text_from_images(file_paths)
|
| 186 |
logging.info(f"Extracted text(Backup): {extracted_text}")
|
| 187 |
logging.info(f"Processed images(Backup): {processed_Img}")
|
|
|
|
|
|
|
| 188 |
try:
|
| 189 |
if extracted_text:
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
logging.info(f"NER model data: {LLMdata}")
|
| 194 |
else:
|
| 195 |
logging.warning("No extracted text available for backup model")
|
| 196 |
-
except Exception as
|
| 197 |
-
logging.exception(f"Error during processing: {
|
| 198 |
-
flash('
|
| 199 |
return redirect(url_for('index'))
|
| 200 |
|
|
|
|
| 201 |
cont_data = process_extracted_text(extracted_text)
|
| 202 |
logging.info(f"Contextual data: {cont_data}")
|
| 203 |
|
|
@@ -206,9 +215,10 @@ def process_file():
|
|
| 206 |
|
| 207 |
session['processed_data'] = processed_data
|
| 208 |
session['processed_Img'] = processed_Img
|
| 209 |
-
flash('Data processed
|
| 210 |
-
logging.info("Data processed
|
| 211 |
return redirect(url_for('result'))
|
|
|
|
| 212 |
|
| 213 |
@app.route('/result')
|
| 214 |
def result():
|
|
@@ -224,4 +234,4 @@ def uploaded_file(filename):
|
|
| 224 |
|
| 225 |
if __name__ == '__main__':
|
| 226 |
logging.info("Starting Flask app")
|
| 227 |
-
app.run(debug=True)
|
|
|
|
| 164 |
logging.info(f"Extracted text blobs: {extracted_text}")
|
| 165 |
logging.info(f"Processed images: {processed_Img}")
|
| 166 |
|
| 167 |
+
# If LLMdata is essentially empty (all values are empty lists), we might want to try backup
|
| 168 |
+
is_empty = all(len(v) == 0 for k, v in LLMdata.items() if k != 'extracted_text')
|
| 169 |
+
|
| 170 |
+
if is_empty:
|
| 171 |
+
logging.info("Groq VLM returned empty data. Trying backup model...")
|
| 172 |
+
raise ValueError("Empty data from Groq VLM")
|
| 173 |
+
|
| 174 |
# Regex fallback / augmentation from model text
|
| 175 |
cont_data = process_extracted_text(extracted_text)
|
| 176 |
logging.info(f"Contextual data: {cont_data}")
|
|
|
|
| 185 |
return redirect(url_for('result'))
|
| 186 |
|
| 187 |
except Exception as e:
|
| 188 |
+
logging.exception(f"Error during primary processing: {e}")
|
| 189 |
+
flash('Primary processing failed, attempting backup model...')
|
| 190 |
|
| 191 |
+
# Correct unpacking (3 values)
|
| 192 |
+
LLMdata_v1, extracted_text, processed_Img = extract_text_from_images(file_paths)
|
| 193 |
logging.info(f"Extracted text(Backup): {extracted_text}")
|
| 194 |
logging.info(f"Processed images(Backup): {processed_Img}")
|
| 195 |
+
|
| 196 |
+
LLMdata = {}
|
| 197 |
try:
|
| 198 |
if extracted_text:
|
| 199 |
+
text = json_to_llm_str(extracted_text)
|
| 200 |
+
LLMdata = NER_Model(text)
|
| 201 |
+
logging.info(f"NER model data: {LLMdata}")
|
|
|
|
| 202 |
else:
|
| 203 |
logging.warning("No extracted text available for backup model")
|
| 204 |
+
except Exception as backup_e:
|
| 205 |
+
logging.exception(f"Error during backup processing: {backup_e}")
|
| 206 |
+
flash('Backup processing also failed')
|
| 207 |
return redirect(url_for('index'))
|
| 208 |
|
| 209 |
+
# Final merge using backup data if we reached here
|
| 210 |
cont_data = process_extracted_text(extracted_text)
|
| 211 |
logging.info(f"Contextual data: {cont_data}")
|
| 212 |
|
|
|
|
| 215 |
|
| 216 |
session['processed_data'] = processed_data
|
| 217 |
session['processed_Img'] = processed_Img
|
| 218 |
+
flash('Data processed using backup model')
|
| 219 |
+
logging.info("Data processed using backup model")
|
| 220 |
return redirect(url_for('result'))
|
| 221 |
+
|
| 222 |
|
| 223 |
@app.route('/result')
|
| 224 |
def result():
|
|
|
|
| 234 |
|
| 235 |
if __name__ == '__main__':
|
| 236 |
logging.info("Starting Flask app")
|
| 237 |
+
app.run(debug=True)
|