Omnibus commited on
Commit
6307d40
1 Parent(s): 3f6fad2

Update dl.py

Browse files
Files changed (1) hide show
  1. dl.py +34 -1
dl.py CHANGED
@@ -58,7 +58,40 @@ def show_f(repo,name,token):
58
 
59
  return(gr.Dropdown.update(label="Files", choices=[f for f in f_ist],interactive=True), file_list)
60
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
 
 
 
 
 
 
 
 
 
62
  def show_f_cont(repo,name,file,token):
63
  r = requests.get(f'https://huggingface.co/spaces/{repo}/{name}/raw/main/{file}')
64
  return(r.text)
@@ -183,7 +216,7 @@ with gr.Blocks() as build:
183
  s_btn.click(show_s,[r_name,token],s_name)
184
  f_name.change(show_f_cont,[r_name,s_name,f_name],r_t)
185
  #s_name.change(show_f,[r_name,s_name,token],[d_app,files])
186
- l_btn.click(show_f,[r_name,s_name,token], [f_name, files])
187
 
188
  pass_btn.click(checkp,pass_box,[no,yes])
189
  #inbut.click(build_space,[token,t_name,s_type,m_type,r_type,d_app,d_css],output_html)
 
58
 
59
  return(gr.Dropdown.update(label="Files", choices=[f for f in f_ist],interactive=True), file_list)
60
 
61
+ def show_f2(repo,name,token):
62
+ api = HfApi(token=token)
63
+ f_ist = snapshot_download(repo_id=f'{repo}/{name}', repo_type="space")
64
+
65
+ #f_ist = (api.list_repo_files(repo_id=f'{repo}/{name}', repo_type="space"))
66
+ print (f_ist)
67
+ file_list = []
68
+ file_out = []
69
+ if not os.path.exists(name):
70
+ os.makedirs(name)
71
+
72
+ for d_app in f_ist:
73
+
74
+ r = requests.get(f'https://huggingface.co/spaces/{repo}/{name}/raw/main/{d_app}')
75
+ #print (r.text)
76
+ uid = uuid.uuid4()
77
+
78
+ sf=d_app.split(".",1)[1]
79
+ pf=d_app.split(".",1)[0]
80
+ f_name=f'{pf}.{sf}'
81
+ file = open(f'{name}/{f_name}','w')
82
+ file.writelines(r.text)
83
+ file.close()
84
+ file_list.append(Path(f'{name}/{f_name}'))
85
+ file_out.append(d_app)
86
 
87
+ with ZipFile(f"{name}.zip", "w") as zipObj:
88
+ for idx, file in enumerate(f_ist):
89
+ zipObj.write(f'{name}/{file}')
90
+ file_list.append(f'{name}.zip')
91
+
92
+ return(gr.Dropdown.update(label="Files", choices=[f for f in f_ist],interactive=True), file_list)
93
+
94
+
95
  def show_f_cont(repo,name,file,token):
96
  r = requests.get(f'https://huggingface.co/spaces/{repo}/{name}/raw/main/{file}')
97
  return(r.text)
 
216
  s_btn.click(show_s,[r_name,token],s_name)
217
  f_name.change(show_f_cont,[r_name,s_name,f_name],r_t)
218
  #s_name.change(show_f,[r_name,s_name,token],[d_app,files])
219
+ l_btn.click(show_f2,[r_name,s_name,token], [f_name, files])
220
 
221
  pass_btn.click(checkp,pass_box,[no,yes])
222
  #inbut.click(build_space,[token,t_name,s_type,m_type,r_type,d_app,d_css],output_html)