Matchball commited on
Commit
2df403d
·
verified ·
1 Parent(s): 449bcca

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -14
app.py CHANGED
@@ -1197,6 +1197,39 @@ def format_reagent_error(error_text):
1197
 
1198
  return clean_text, has_red_color, has_asterisk
1199
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1200
  def main():
1201
  st.set_page_config(
1202
  page_title="PDF Reagent Checker",
@@ -1239,22 +1272,16 @@ def main():
1239
  # Display file path
1240
  st.code(f"File: {uploaded_file.name}")
1241
 
1242
- # Display each reagent error with proper formatting
1243
- high_error_count = 0
1244
  for i, reagent_error in enumerate(reagent_list, 1):
1245
- clean_text, has_red_color, has_asterisk = format_reagent_error(reagent_error)
1246
 
1247
- if has_red_color or has_asterisk:
1248
- # High priority error (red color or asterisk)
1249
- st.error(f"⚠️ **Issue {i}**: {clean_text}")
1250
- high_error_count += 1
1251
  else:
1252
- # Normal issue
1253
- st.warning(f"⚡ **Issue {i}**: {clean_text}")
1254
-
1255
- # Summary
1256
- if high_error_count > 0:
1257
- st.error(f"🔴 **{high_error_count} high-priority issue(s)** require attention!")
1258
 
1259
  # Option to download results
1260
  results_text = f"File: {uploaded_file.name}\n\n"
@@ -1296,4 +1323,4 @@ def main():
1296
  """)
1297
 
1298
  if __name__ == "__main__":
1299
- main()
 
1197
 
1198
  return clean_text, has_red_color, has_asterisk
1199
 
1200
+ def check_reagents(pdf_file_path):
1201
+ """
1202
+ Replace this entire function with your actual implementation.
1203
+ """
1204
+ # This is just a placeholder - replace with your real function
1205
+ return [] # Returns empty list so no fake errors show
1206
+
1207
+ def clean_ansi_codes(text):
1208
+ """
1209
+ Remove ANSI escape codes from text and return clean text.
1210
+ """
1211
+ ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')
1212
+ return ansi_escape.sub('', text)
1213
+
1214
+ def format_reagent_error(error_text):
1215
+ """
1216
+ Format reagent error text for Streamlit display.
1217
+ Converts ANSI color codes and determines if mass error >= 10%.
1218
+ """
1219
+ # Clean the text of ANSI codes
1220
+ clean_text = clean_ansi_codes(error_text)
1221
+
1222
+ # Extract mass error percentage using regex
1223
+ mass_error_pattern = r'Mass error:\s*(\d+\.?\d*)%'
1224
+ match = re.search(mass_error_pattern, clean_text)
1225
+
1226
+ is_high_error = False
1227
+ if match:
1228
+ mass_error_percent = float(match.group(1))
1229
+ is_high_error = mass_error_percent >= 10.0
1230
+
1231
+ return clean_text, is_high_error
1232
+
1233
  def main():
1234
  st.set_page_config(
1235
  page_title="PDF Reagent Checker",
 
1272
  # Display file path
1273
  st.code(f"File: {uploaded_file.name}")
1274
 
1275
+ # Display each reagent error
 
1276
  for i, reagent_error in enumerate(reagent_list, 1):
1277
+ clean_text, is_high_error = format_reagent_error(reagent_error)
1278
 
1279
+ if is_high_error:
1280
+ # Mass error >= 10% - display in red text
1281
+ st.markdown(f'<p style="color: red;">Issue {i}: {clean_text}</p>', unsafe_allow_html=True)
 
1282
  else:
1283
+ # Normal issue - display normally
1284
+ st.write(f"Issue {i}: {clean_text}")
 
 
 
 
1285
 
1286
  # Option to download results
1287
  results_text = f"File: {uploaded_file.name}\n\n"
 
1323
  """)
1324
 
1325
  if __name__ == "__main__":
1326
+ main()