lysandre HF staff commited on
Commit
1c179c5
1 Parent(s): 7e9cddf

Remove logs

Browse files
Files changed (1) hide show
  1. app.py +23 -15
app.py CHANGED
@@ -1,31 +1,39 @@
1
  import tempfile
2
 
3
  import gradio as gr
4
- from huggingface_hub import create_repo, whoami, repo_exists, upload_folder, snapshot_download
 
5
  import os
6
 
7
 
 
 
 
 
8
  def submit(source_repo, token):
9
- hfa = os.getenv('HFA_TOKEN')
 
10
 
11
- org = "huggingface-assignments"
12
- username = whoami(token)["name"]
13
 
14
- target_repo = f"{org}/{username}-submission-0"
15
 
16
- while repo_exists(target_repo, token=hfa):
17
- dst_split = target_repo.split('-')
18
- dst_index = int(dst_split[-1])
19
- dst_split[-1] = str(dst_index + 1)
20
- target_repo = '-'.join(dst_split)
21
 
22
- create_repo(target_repo, token=hfa, private=True)
23
 
24
- with tempfile.TemporaryDirectory() as tmp:
25
- snapshot_download(source_repo, local_dir=tmp, local_dir_use_symlinks=False, token=token)
26
- upload_folder(repo_id=target_repo, folder_path=tmp, token=hfa)
 
 
27
 
28
- return "success"
29
 
30
 
31
  description = "<h3>Submit your Hugging Face assignment.</h3> \nEnter the source repository (that should be private " \
 
1
  import tempfile
2
 
3
  import gradio as gr
4
+ from huggingface_hub import create_repo, whoami, repo_exists, upload_folder, snapshot_download, logging
5
+ from huggingface_hub.utils import disable_progress_bars
6
  import os
7
 
8
 
9
+ disable_progress_bars()
10
+ logging.set_verbosity(51)
11
+
12
+
13
  def submit(source_repo, token):
14
+ try:
15
+ hfa = os.getenv('HFA_TOKEN')
16
 
17
+ org = "huggingface-assignments"
18
+ username = whoami(token)["name"]
19
 
20
+ target_repo = f"{org}/{username}-submission-0"
21
 
22
+ while repo_exists(target_repo, token=hfa):
23
+ dst_split = target_repo.split('-')
24
+ dst_index = int(dst_split[-1])
25
+ dst_split[-1] = str(dst_index + 1)
26
+ target_repo = '-'.join(dst_split)
27
 
28
+ create_repo(target_repo, token=hfa, private=True)
29
 
30
+ with tempfile.TemporaryDirectory() as tmp:
31
+ snapshot_download(source_repo, local_dir=tmp, local_dir_use_symlinks=False, token=token)
32
+ upload_folder(repo_id=target_repo, folder_path=tmp, token=hfa)
33
+ except Exception:
34
+ return "There was an error. Contact lysandre@huggingface.co for help."
35
 
36
+ return "Success! Your submission has been entered."
37
 
38
 
39
  description = "<h3>Submit your Hugging Face assignment.</h3> \nEnter the source repository (that should be private " \