Spaces:
Runtime error
Runtime error
Efreak
commited on
Commit
·
d71ceca
1
Parent(s):
46a12f2
clean up on failure, too
Browse files
app.py
CHANGED
|
@@ -12,6 +12,7 @@ api=HfApi()
|
|
| 12 |
FILE_TYPES = ["Embedding", "Stable Diffusion Model", "Lora", "Lycoris"]
|
| 13 |
|
| 14 |
def duplicate(source_url, preview_url, model_id, dst_repo, token, repo_type, nsfw, make_pr):
|
|
|
|
| 15 |
try:
|
| 16 |
_ = whoami(token)
|
| 17 |
# ^ this will throw if token is invalid
|
|
@@ -24,7 +25,6 @@ def duplicate(source_url, preview_url, model_id, dst_repo, token, repo_type, nsf
|
|
| 24 |
login(token=token)
|
| 25 |
|
| 26 |
# keep things separate, partly in case people download different files with same name (`download.zip`). Especially, it also allows saving filename to work
|
| 27 |
-
dir="/home/user/apps/downloads/"+str(int(time.time()))+str(random.getrandbits(8))+"/"
|
| 28 |
subprocess.check_call([r"mkdir","-p",dir])
|
| 29 |
subprocess.check_call([r"aria2c","-x16","--split=16",source_url,"--dir="+dir])
|
| 30 |
|
|
@@ -54,11 +54,7 @@ def duplicate(source_url, preview_url, model_id, dst_repo, token, repo_type, nsf
|
|
| 54 |
)
|
| 55 |
|
| 56 |
# now clean up
|
| 57 |
-
|
| 58 |
-
os.remove(dir+files[0])
|
| 59 |
-
os.remove(dir+files[1])
|
| 60 |
-
os.remove(dir+files[2])
|
| 61 |
-
os.rmdir(dir)
|
| 62 |
|
| 63 |
return (
|
| 64 |
f'Find your commit at the top of <a href=\'https://hf.co/spaces/{dst_repo}/commits/main{repopath}\' target="_blank" style="text-decoration:underline">your commits</a>',
|
|
@@ -66,6 +62,7 @@ def duplicate(source_url, preview_url, model_id, dst_repo, token, repo_type, nsf
|
|
| 66 |
)
|
| 67 |
|
| 68 |
except Exception as e:
|
|
|
|
| 69 |
blames=["grandma","my boss","your boss","God","you","you. It's *all* your fault.","the pope"]
|
| 70 |
blameweights=(1,1,1,1,4,2,1)
|
| 71 |
excuses=["I blame it all on "+random.choices(blames,weights=blameweights)[0],"It's my fault, sorry.","I did it on purpose.","That file doesn't want to be downloaded.","You nincompoop!"]
|
|
|
|
| 12 |
FILE_TYPES = ["Embedding", "Stable Diffusion Model", "Lora", "Lycoris"]
|
| 13 |
|
| 14 |
def duplicate(source_url, preview_url, model_id, dst_repo, token, repo_type, nsfw, make_pr):
|
| 15 |
+
dir="/home/user/apps/downloads/"+str(int(time.time()))+str(random.getrandbits(8))
|
| 16 |
try:
|
| 17 |
_ = whoami(token)
|
| 18 |
# ^ this will throw if token is invalid
|
|
|
|
| 25 |
login(token=token)
|
| 26 |
|
| 27 |
# keep things separate, partly in case people download different files with same name (`download.zip`). Especially, it also allows saving filename to work
|
|
|
|
| 28 |
subprocess.check_call([r"mkdir","-p",dir])
|
| 29 |
subprocess.check_call([r"aria2c","-x16","--split=16",source_url,"--dir="+dir])
|
| 30 |
|
|
|
|
| 54 |
)
|
| 55 |
|
| 56 |
# now clean up
|
| 57 |
+
subprocess.check_call([r"rm","-rf",dir])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
return (
|
| 60 |
f'Find your commit at the top of <a href=\'https://hf.co/spaces/{dst_repo}/commits/main{repopath}\' target="_blank" style="text-decoration:underline">your commits</a>',
|
|
|
|
| 62 |
)
|
| 63 |
|
| 64 |
except Exception as e:
|
| 65 |
+
subprocess.check_call([r"rm","-rf",dir])
|
| 66 |
blames=["grandma","my boss","your boss","God","you","you. It's *all* your fault.","the pope"]
|
| 67 |
blameweights=(1,1,1,1,4,2,1)
|
| 68 |
excuses=["I blame it all on "+random.choices(blames,weights=blameweights)[0],"It's my fault, sorry.","I did it on purpose.","That file doesn't want to be downloaded.","You nincompoop!"]
|