DevWild commited on
Commit
4362635
·
verified ·
1 Parent(s): 1ab5ffa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -17
app.py CHANGED
@@ -3,6 +3,7 @@ import subprocess
3
  from typing import Union
4
  from huggingface_hub import whoami
5
  from huggingface_hub import HfApi
 
6
  is_spaces = True if os.environ.get("SPACE_ID") else False
7
 
8
  import tempfile
@@ -284,23 +285,13 @@ def start_training(
284
  except Exception as e:
285
  print(f"Failed to add HF_TOKEN secret to new space: {e}")
286
 
287
- # Clone the subspace repo and push the dataset files into it
288
- with tempfile.TemporaryDirectory() as clone_dir:
289
- subspace_repo_url = f"https://{hf_token}@huggingface.co/spaces/{new_space_id}"
290
- repo = Repo.clone_from(subspace_repo_url, clone_dir)
291
-
292
- # Copy all dataset_folder contents to the clone dir
293
- for item in os.listdir(dataset_folder):
294
- s = os.path.join(dataset_folder, item)
295
- d = os.path.join(clone_dir, item)
296
- if os.path.isdir(s):
297
- shutil.copytree(s, d, dirs_exist_ok=True)
298
- else:
299
- shutil.copy2(s, d)
300
-
301
- repo.index.add(["."])
302
- repo.index.commit("Push training files from controller")
303
- repo.remote().push()
304
 
305
  cmd = f"autotrain spacerunner --project-name {slugged_lora_name} --script-path {dataset_folder}"
306
  cmd += f" --username {profile.username} --token {hf_token} --backend spaces-l4x1"
 
3
  from typing import Union
4
  from huggingface_hub import whoami
5
  from huggingface_hub import HfApi
6
+ from huggingface_hub import upload_folder
7
  is_spaces = True if os.environ.get("SPACE_ID") else False
8
 
9
  import tempfile
 
285
  except Exception as e:
286
  print(f"Failed to add HF_TOKEN secret to new space: {e}")
287
 
288
+ upload_folder(
289
+ folder_path=dataset_folder,
290
+ repo_id=new_space_id,
291
+ repo_type="space",
292
+ token=hf_token,
293
+ commit_message="Pushing training files from controller"
294
+ )
 
 
 
 
 
 
 
 
 
 
295
 
296
  cmd = f"autotrain spacerunner --project-name {slugged_lora_name} --script-path {dataset_folder}"
297
  cmd += f" --username {profile.username} --token {hf_token} --backend spaces-l4x1"