rongo1 commited on
Commit
2b81079
·
1 Parent(s): c288165

fix: fixed not saving

Browse files
Files changed (1) hide show
  1. app.py +37 -3
app.py CHANGED
@@ -280,6 +280,15 @@ def process_business_cards(images, model_name="gemini-2.5-flash", save_images=Tr
280
  logger.error(f"Failed to save image {filename}: {e}")
281
 
282
  logger.info(f"Successfully saved {len(saved_image_paths)} images")
 
 
 
 
 
 
 
 
 
283
 
284
  # Group into batches
285
  logger.info(f"Grouping {len(loaded_images)} images into batches of {batch_size}")
@@ -421,6 +430,8 @@ def process_business_cards(images, model_name="gemini-2.5-flash", save_images=Tr
421
  # Write current run Excel file
422
  logger.info(f"Writing current run Excel file: {current_filename}")
423
  try:
 
 
424
  with pd.ExcelWriter(current_filename, engine='openpyxl') as writer:
425
  current_df.to_excel(writer, index=False, sheet_name='Current Run')
426
  logger.debug(f"Written {len(current_df)} rows to 'Current Run' sheet")
@@ -445,6 +456,8 @@ def process_business_cards(images, model_name="gemini-2.5-flash", save_images=Tr
445
  # Write cumulative Excel file
446
  logger.info(f"Writing cumulative Excel file: {cumulative_filename}")
447
  try:
 
 
448
  with pd.ExcelWriter(cumulative_filename, engine='openpyxl') as writer:
449
  cumulative_df.to_excel(writer, index=False, sheet_name='All Business Cards')
450
  logger.debug(f"Written {len(cumulative_df)} rows to 'All Business Cards' sheet")
@@ -499,6 +512,27 @@ def process_business_cards(images, model_name="gemini-2.5-flash", save_images=Tr
499
  logger.info("Business card processing session completed successfully")
500
  logger.info(f"Session summary - Cards: {len(all_data)}, Batches: {num_batches}, API calls: {num_batches}, Total DB size: {len(cumulative_df)}")
501
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
502
  return str(current_filename), str(cumulative_filename), summary, preview_df
503
 
504
  # Create Gradio interface
@@ -530,8 +564,8 @@ with gr.Blocks(title="Business Card Data Extractor") as demo:
530
  )
531
 
532
  model_selector = gr.Dropdown(
533
- choices=["gemini-2.5-flash", "gemini-2.5-pro"],
534
- value="gemini-2.5-flash",
535
  label="AI Model Selection"
536
  )
537
 
@@ -585,4 +619,4 @@ with gr.Blocks(title="Business Card Data Extractor") as demo:
585
 
586
  # Launch for Hugging Face Spaces deployment
587
  logger.info("Starting Gradio demo")
588
- demo.launch(share=True)
 
280
  logger.error(f"Failed to save image {filename}: {e}")
281
 
282
  logger.info(f"Successfully saved {len(saved_image_paths)} images")
283
+
284
+ # List directory contents for debugging
285
+ try:
286
+ images_list = list(images_dir.iterdir())
287
+ logger.info(f"Images directory contains {len(images_list)} files")
288
+ for img_file in images_list[-5:]: # Show last 5 files
289
+ logger.debug(f" - {img_file.name}")
290
+ except Exception as e:
291
+ logger.error(f"Error listing images directory: {e}")
292
 
293
  # Group into batches
294
  logger.info(f"Grouping {len(loaded_images)} images into batches of {batch_size}")
 
430
  # Write current run Excel file
431
  logger.info(f"Writing current run Excel file: {current_filename}")
432
  try:
433
+ # Ensure the file path is a Path object
434
+ current_filename = Path(current_filename)
435
  with pd.ExcelWriter(current_filename, engine='openpyxl') as writer:
436
  current_df.to_excel(writer, index=False, sheet_name='Current Run')
437
  logger.debug(f"Written {len(current_df)} rows to 'Current Run' sheet")
 
456
  # Write cumulative Excel file
457
  logger.info(f"Writing cumulative Excel file: {cumulative_filename}")
458
  try:
459
+ # Ensure the file path is a Path object
460
+ cumulative_filename = Path(cumulative_filename)
461
  with pd.ExcelWriter(cumulative_filename, engine='openpyxl') as writer:
462
  cumulative_df.to_excel(writer, index=False, sheet_name='All Business Cards')
463
  logger.debug(f"Written {len(cumulative_df)} rows to 'All Business Cards' sheet")
 
512
  logger.info("Business card processing session completed successfully")
513
  logger.info(f"Session summary - Cards: {len(all_data)}, Batches: {num_batches}, API calls: {num_batches}, Total DB size: {len(cumulative_df)}")
514
 
515
+ # Verify files exist and return as strings for Gradio
516
+ if current_filename.exists():
517
+ logger.info(f"Current file exists: {current_filename}")
518
+ else:
519
+ logger.error(f"Current file NOT found: {current_filename}")
520
+
521
+ if cumulative_filename.exists():
522
+ logger.info(f"Cumulative file exists: {cumulative_filename}")
523
+ else:
524
+ logger.error(f"Cumulative file NOT found: {cumulative_filename}")
525
+
526
+ # List export directory contents for debugging
527
+ try:
528
+ export_list = list(output_dir.iterdir())
529
+ logger.info(f"Export directory contains {len(export_list)} files")
530
+ for exp_file in export_list[-5:]: # Show last 5 files
531
+ logger.debug(f" - {exp_file.name}")
532
+ except Exception as e:
533
+ logger.error(f"Error listing export directory: {e}")
534
+
535
+ # Return string paths for Gradio File components
536
  return str(current_filename), str(cumulative_filename), summary, preview_df
537
 
538
  # Create Gradio interface
 
564
  )
565
 
566
  model_selector = gr.Dropdown(
567
+ choices=["gemini-2.5-pro", "gemini-2.5-flash"],
568
+ value="gemini-2.5-pro",
569
  label="AI Model Selection"
570
  )
571
 
 
619
 
620
  # Launch for Hugging Face Spaces deployment
621
  logger.info("Starting Gradio demo")
622
+ demo.launch()