rongo1 commited on
Commit
46dec01
Β·
1 Parent(s): 6ba44e8
Files changed (1) hide show
  1. app.py +25 -13
app.py CHANGED
@@ -51,8 +51,20 @@ else:
51
 
52
  # Create output directories
53
  logger.info("Setting up output directories")
54
- # Use /data for persistent storage in Hugging Face Spaces
55
- BASE_PATH = Path("/data")
 
 
 
 
 
 
 
 
 
 
 
 
56
  output_dir = BASE_PATH / "business_card_exports"
57
  images_dir = BASE_PATH / "business_cards"
58
  output_dir.mkdir(parents=True, exist_ok=True)
@@ -700,20 +712,20 @@ with gr.Blocks(title="Business Card Data Extractor") as demo:
700
  - πŸ“ **Current Run**: Contains only the cards you just processed
701
  - πŸ“Š **Total Database**: Contains ALL cards ever processed (cumulative)
702
 
703
- **πŸ”„ Persistent Storage & Hub Integration:**
704
- - πŸ’Ύ Files saved to `/data` directory (persistent across restarts)
705
- - 🌐 Automatically uploaded to Hub repository (if configured)
706
- - πŸ“‚ Excel files: `/data/business_card_exports/`
707
- - πŸ–ΌοΈ Images: `/data/business_cards/` (if save option enabled)
708
 
709
  **πŸ“Œ File Access:**
710
- - Download directly from interface or check Space's Files tab
711
- - Hub uploads available at: `exports/` and `images/` folders in repo
712
- - Check `FOLDER_CONTENTS.txt` for complete file listing
 
713
 
714
  **βš™οΈ Optional Hub Integration:**
715
- - Set `HF_TOKEN` in Space secrets to enable file uploads to repository
716
- - Files will be uploaded to `polygraf-ai/business_card_extractor`
717
  """
718
  )
719
 
@@ -772,7 +784,7 @@ with gr.Blocks(title="Business Card Data Extractor") as demo:
772
  - πŸ“„ **Data Extraction**: Names, emails, phone numbers, addresses, and more
773
  - πŸ“ž **Smart Combination**: Multiple emails/phones combined with commas
774
  - 🏠 **Address Merging**: All phone types and address fields combined
775
- - πŸ’Ύ **Persistent Storage**: Files saved to `/data` directory (survives restarts)
776
  - 🌐 **Hub Integration**: Auto-upload to repository (optional)
777
  - πŸ“Š **Dual Output**: Current run + cumulative database files
778
  - πŸ“ **Full Tracking**: Processing date, filename, image path, and AI model used
 
51
 
52
  # Create output directories
53
  logger.info("Setting up output directories")
54
+ # Try /data for persistent storage, fallback to current directory
55
+ try:
56
+ # Check if /data is available (persistent storage enabled)
57
+ data_path = Path("/data")
58
+ if data_path.exists() and os.access(data_path, os.W_OK):
59
+ BASE_PATH = data_path
60
+ logger.info("Using /data directory for persistent storage")
61
+ else:
62
+ raise PermissionError("No access to /data")
63
+ except (PermissionError, OSError):
64
+ # Fallback to current directory for free tier
65
+ BASE_PATH = Path(".")
66
+ logger.info("Using current directory (files will be ephemeral without persistent storage)")
67
+
68
  output_dir = BASE_PATH / "business_card_exports"
69
  images_dir = BASE_PATH / "business_cards"
70
  output_dir.mkdir(parents=True, exist_ok=True)
 
712
  - πŸ“ **Current Run**: Contains only the cards you just processed
713
  - πŸ“Š **Total Database**: Contains ALL cards ever processed (cumulative)
714
 
715
+ **πŸ’Ύ File Storage:**
716
+ - πŸ“‚ Excel files: `business_card_exports/` folder
717
+ - πŸ–ΌοΈ Images: `business_cards/` folder (if save option enabled)
718
+ - πŸ”„ **Persistent storage**: Enable in Space settings for files to survive restarts
719
+ - 🌐 **Hub uploads**: Files auto-uploaded to repository (if `HF_TOKEN` configured)
720
 
721
  **πŸ“Œ File Access:**
722
+ - ⬇️ Download directly from interface buttons
723
+ - πŸ“ Check Space's Files tab (if persistent storage enabled)
724
+ - 🌐 Hub repository: `exports/` and `images/` folders (if token set)
725
+ - πŸ“‹ `FOLDER_CONTENTS.txt` shows complete file listing
726
 
727
  **βš™οΈ Optional Hub Integration:**
728
+ - Set `HF_TOKEN` in Space secrets to upload files to `polygraf-ai/business_card_extractor`
 
729
  """
730
  )
731
 
 
784
  - πŸ“„ **Data Extraction**: Names, emails, phone numbers, addresses, and more
785
  - πŸ“ž **Smart Combination**: Multiple emails/phones combined with commas
786
  - 🏠 **Address Merging**: All phone types and address fields combined
787
+ - πŸ’Ύ **Smart Storage**: Auto-detects persistent storage, falls back gracefully
788
  - 🌐 **Hub Integration**: Auto-upload to repository (optional)
789
  - πŸ“Š **Dual Output**: Current run + cumulative database files
790
  - πŸ“ **Full Tracking**: Processing date, filename, image path, and AI model used