Spaces:
Running
Running
Update dl.py
Browse files
dl.py
CHANGED
@@ -223,6 +223,33 @@ def show_all_z(author,token):
|
|
223 |
file_list.append(f'{author}.zip')
|
224 |
yield file_list
|
225 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
226 |
|
227 |
|
228 |
def checkp(p):
|
@@ -274,12 +301,14 @@ with gr.Blocks(css=css) as build:
|
|
274 |
with gr.Row():
|
275 |
with gr.Column(scale=1):
|
276 |
with gr.Group():
|
277 |
-
|
278 |
with gr.Column(scale=1):
|
279 |
-
|
280 |
with gr.Column(scale=2):
|
281 |
-
|
282 |
|
|
|
|
|
283 |
show_all_btn1.click(show_all,[r_name,token],files)
|
284 |
show_all_btn2.click(show_all_z,[r_name,token],files)
|
285 |
|
|
|
223 |
file_list.append(f'{author}.zip')
|
224 |
yield file_list
|
225 |
|
226 |
+
def dl_checked_fn(author,checklist,token):
|
227 |
+
spaces=[]
|
228 |
+
api = HfApi(token=token)
|
229 |
+
#author=name
|
230 |
+
s_ist = checklist
|
231 |
+
file_list = []
|
232 |
+
file_list_ea=[]
|
233 |
+
for i,space in enumerate(s_ist):
|
234 |
+
space_ea = space.id.split("/",1)[1]
|
235 |
+
spaces.append(space_ea)
|
236 |
+
#print (space_ea)
|
237 |
+
f_ist = (api.list_repo_files(repo_id=f'{author}/{space_ea}', repo_type="space"))
|
238 |
+
#print (f_ist)
|
239 |
+
if not os.path.exists(space_ea):
|
240 |
+
os.makedirs(space_ea)
|
241 |
+
file= snapshot_download(repo_id=f'{author}/{space_ea}', repo_type="space")
|
242 |
+
shutil.make_archive(f"{space_ea}", 'zip', file)
|
243 |
+
file_list.append(f'{space_ea}.zip')
|
244 |
+
yield file_list
|
245 |
+
with ZipFile(f"{author}.zip", "w") as zipObj:
|
246 |
+
for idx, file in enumerate(file_list):
|
247 |
+
try:
|
248 |
+
zipObj.write(f'{file}')
|
249 |
+
except Exception:
|
250 |
+
pass
|
251 |
+
file_list.append(f'{author}.zip')
|
252 |
+
yield file_list
|
253 |
|
254 |
|
255 |
def checkp(p):
|
|
|
301 |
with gr.Row():
|
302 |
with gr.Column(scale=1):
|
303 |
with gr.Group():
|
304 |
+
space_check=gr.Checkbox(label="Spaces",choices=[])
|
305 |
with gr.Column(scale=1):
|
306 |
+
dl_checked_btn=gr.Button("Download Checked")
|
307 |
with gr.Column(scale=2):
|
308 |
+
file_contents_2=gr.HTML()
|
309 |
|
310 |
+
dl_checked_btn.click(dl_checked_fn,[r_name,space_check,token],files)
|
311 |
+
|
312 |
show_all_btn1.click(show_all,[r_name,token],files)
|
313 |
show_all_btn2.click(show_all_z,[r_name,token],files)
|
314 |
|