Fred808 commited on
Commit
9a8fae4
·
verified ·
1 Parent(s): 775f409

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -6
app.py CHANGED
@@ -25,16 +25,17 @@ import pickle
25
  # Set up logging
26
  logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
27
 
28
- # Check if the current directory is writable
29
- if not os.access(os.getcwd(), os.W_OK):
30
- logging.warning("Current directory is not writable. Switching to /tmp.")
31
- os.chdir('/tmp') # Change to a writable directory
 
32
 
33
  # Verify the current directory
34
  logging.info(f"Current working directory: {os.getcwd()}")
35
 
36
  # Cache file to store extracted text
37
- CACHE_FILE = "/tmp/image_text_cache.pkl"
38
 
39
  # Load cache if it exists
40
  if os.path.exists(CACHE_FILE):
@@ -178,7 +179,7 @@ new_images = process_new_images(new_images)
178
  combined_df.update(new_images)
179
 
180
  # Save the updated dataset
181
- combined_df.to_csv('/tmp/data_with_extracted_text.csv', index=False)
182
 
183
  # Save the cache
184
  with open(CACHE_FILE, "wb") as f:
 
25
  # Set up logging
26
  logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
27
 
28
+ # Set the working directory to a writable location
29
+ WORKING_DIR = "/app" # Use /app or /tmp
30
+ if not os.path.exists(WORKING_DIR):
31
+ os.makedirs(WORKING_DIR)
32
+ os.chdir(WORKING_DIR)
33
 
34
  # Verify the current directory
35
  logging.info(f"Current working directory: {os.getcwd()}")
36
 
37
  # Cache file to store extracted text
38
+ CACHE_FILE = os.path.join(WORKING_DIR, "image_text_cache.pkl")
39
 
40
  # Load cache if it exists
41
  if os.path.exists(CACHE_FILE):
 
179
  combined_df.update(new_images)
180
 
181
  # Save the updated dataset
182
+ combined_df.to_csv(os.path.join(WORKING_DIR, "data_with_extracted_text.csv"), index=False)
183
 
184
  # Save the cache
185
  with open(CACHE_FILE, "wb") as f: