Update app.py
Browse files
app.py
CHANGED
|
@@ -4,7 +4,7 @@ import uuid
|
|
| 4 |
import gradio as gr
|
| 5 |
import requests
|
| 6 |
import json
|
| 7 |
-
import
|
| 8 |
from pathlib import Path
|
| 9 |
from huggingface_hub import (create_repo,get_full_repo_name,upload_file,CommitOperationAdd,HfApi)
|
| 10 |
uid = uuid.uuid4()
|
|
@@ -94,7 +94,7 @@ def get_f(r_name,spaces,token):
|
|
| 94 |
f_ist = (api.list_repo_files(repo_id=f'{r_name}/{space}', repo_type="space"))
|
| 95 |
for file in f_ist:
|
| 96 |
t_file=open(f'{uid}/{space}-{file}','w')
|
| 97 |
-
zz_file=open(f'{
|
| 98 |
r = requests.get(f'https://huggingface.co/spaces/{r_name}/{space}/raw/main/{file}')
|
| 99 |
t_file.write(r.text)
|
| 100 |
t_file.close()
|
|
@@ -104,8 +104,8 @@ def get_f(r_name,spaces,token):
|
|
| 104 |
#files_c.append(f'{uid}/{file}')
|
| 105 |
|
| 106 |
print(file)
|
| 107 |
-
|
| 108 |
-
|
| 109 |
spaces_b.append(f'{space}.zip')
|
| 110 |
|
| 111 |
return(files_b,spaces_b)
|
|
|
|
| 4 |
import gradio as gr
|
| 5 |
import requests
|
| 6 |
import json
|
| 7 |
+
import tarfile
|
| 8 |
from pathlib import Path
|
| 9 |
from huggingface_hub import (create_repo,get_full_repo_name,upload_file,CommitOperationAdd,HfApi)
|
| 10 |
uid = uuid.uuid4()
|
|
|
|
| 94 |
f_ist = (api.list_repo_files(repo_id=f'{r_name}/{space}', repo_type="space"))
|
| 95 |
for file in f_ist:
|
| 96 |
t_file=open(f'{uid}/{space}-{file}','w')
|
| 97 |
+
zz_file=open(f'{space}/{file}','w')
|
| 98 |
r = requests.get(f'https://huggingface.co/spaces/{r_name}/{space}/raw/main/{file}')
|
| 99 |
t_file.write(r.text)
|
| 100 |
t_file.close()
|
|
|
|
| 104 |
#files_c.append(f'{uid}/{file}')
|
| 105 |
|
| 106 |
print(file)
|
| 107 |
+
with zipfile.ZipFile(f'{space}.zip', 'w') as new_zip:
|
| 108 |
+
new_zip.write(f'{space}/', compress_type=zipfile.ZIP_DEFLATED)
|
| 109 |
spaces_b.append(f'{space}.zip')
|
| 110 |
|
| 111 |
return(files_b,spaces_b)
|