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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -27
app.py CHANGED
@@ -293,6 +293,7 @@ def split_into_chunks(texts, references, chunk_size, chunk_overlap):
293
  # return vectorstore
294
 
295
 
 
296
  def setup_vectorstore(chunks, model_name):
297
  print("Start setup_vectorstore_function")
298
 
@@ -311,33 +312,26 @@ def setup_vectorstore(chunks, model_name):
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
 
 
293
  # return vectorstore
294
 
295
 
296
+
297
  def setup_vectorstore(chunks, model_name):
298
  print("Start setup_vectorstore_function")
299
 
 
312
  print("Persist directory:", vectorstore._persist_directory)
313
  print("Available methods in vectorstore:", dir(vectorstore))
314
 
315
+ # Zip the entire folder
316
+ zip_file_path = os.path.join(temp_dir, "folder_archive.zip")
317
+ with zipfile.ZipFile(zip_file_path, "w", zipfile.ZIP_DEFLATED) as zipf:
318
+ for folder_root, _, folder_files in os.walk(temp_dir):
319
+ for file_name in folder_files:
320
+ file_path = os.path.join(folder_root, file_name)
321
+ arcname = os.path.relpath(file_path, temp_dir) # Preserve relative paths
322
+ zipf.write(file_path, arcname)
323
+
324
+ print(f"Created zip file: {zip_file_path}")
325
+
326
+ # Upload the zip file
327
+ target_path_in_repo = "folder_archive.zip" # Define the target name in the repository
328
+ api.upload_file(
329
+ path_or_fileobj=zip_file_path,
330
+ path_in_repo=target_path_in_repo,
331
+ repo_id=HF_SPACE_NAME,
332
+ repo_type="space"
333
+ )
334
+ print(f"Uploaded {zip_file_path} as {target_path_in_repo}")
 
 
 
 
 
 
 
335
 
336
  print("Process completed successfully!")
337