bupa1018 commited on
Commit
375de0d
·
1 Parent(s): 3e90a0b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -9
app.py CHANGED
@@ -311,21 +311,36 @@ def setup_vectorstore(chunks, model_name):
311
  print("Persist directory:", vectorstore._persist_directory)
312
  print("Available methods in vectorstore:", dir(vectorstore))
313
 
314
- # At this point, you can use your API upload method to upload the persisted vectorstore files
315
- for root, _, files in os.walk(temp_dir):
316
- for file_name in files:
317
- file_path = os.path.join(root, file_name)
318
- target_path_in_repo = os.path.relpath(file_path, temp_dir)
319
- print(f"Uploading file: {file_path} -> {target_path_in_repo}")
 
 
 
 
 
 
 
 
 
 
 
 
320
  api.upload_file(
321
- path_or_fileobj=file_path,
322
  path_in_repo=target_path_in_repo,
323
  repo_id=HF_SPACE_NAME,
324
  repo_type="space"
325
  )
326
- print(f"Uploaded {file_path} to {target_path_in_repo}")
 
 
327
 
328
- print("All files uploaded successfully!")
 
329
 
330
 
331
  # Setup LLM
 
311
  print("Persist directory:", vectorstore._persist_directory)
312
  print("Available methods in vectorstore:", dir(vectorstore))
313
 
314
+ # Get the first subfolder and zip its contents
315
+ for root, dirs, files in os.walk(temp_dir):
316
+ if dirs: # Check for subfolders
317
+ next_subfolder = os.path.join(root, dirs[0]) # Take the first subfolder
318
+ zip_file_path = os.path.join(temp_dir, "subfolder_archive.zip")
319
+
320
+ # Create a zip file
321
+ with zipfile.ZipFile(zip_file_path, "w", zipfile.ZIP_DEFLATED) as zipf:
322
+ for folder_root, _, folder_files in os.walk(next_subfolder):
323
+ for file_name in folder_files:
324
+ file_path = os.path.join(folder_root, file_name)
325
+ arcname = os.path.relpath(file_path, next_subfolder) # Preserve relative paths
326
+ zipf.write(file_path, arcname)
327
+
328
+ print(f"Created zip file: {zip_file_path}")
329
+
330
+ # Upload the zip file
331
+ target_path_in_repo = "subfolder_archive.zip" # Define the target name in the repository
332
  api.upload_file(
333
+ path_or_fileobj=zip_file_path,
334
  path_in_repo=target_path_in_repo,
335
  repo_id=HF_SPACE_NAME,
336
  repo_type="space"
337
  )
338
+ print(f"Uploaded {zip_file_path} as {target_path_in_repo}")
339
+
340
+ break # Stop after processing the first subfolder
341
 
342
+ print("Process completed successfully!")
343
+
344
 
345
 
346
  # Setup LLM