Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Remove logs
Browse files
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 |
-
|
|
|
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
|
| 14 |
-
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
|
| 22 |
-
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
| 27 |
|
| 28 |
-
return "
|
| 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 " \
|