Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -57,7 +57,7 @@ def get_all_files(owner, repo, path="", is_hf=False):
|
|
57 |
except Exception as e:
|
58 |
return None
|
59 |
|
60 |
-
def get_hf_files(repo,name):
|
61 |
api = HfApi()
|
62 |
f_ist = (api.list_repo_files(repo_id=f'{repo}/{name}', repo_type="space"))
|
63 |
print (f_ist)
|
@@ -69,6 +69,8 @@ def get_hf_files(repo,name):
|
|
69 |
for d_app in f_ist:
|
70 |
if "/" in d_app:
|
71 |
dir_1=d_app.split("/",1)[0]
|
|
|
|
|
72 |
rem_1=d_app.split("/",1)[1]
|
73 |
if not os.path.exists(f'{name}/{dir_1}'):
|
74 |
os.makedirs(f'{name}/{dir_1}')
|
@@ -87,14 +89,14 @@ def get_hf_files(repo,name):
|
|
87 |
pf=rem_1.split(".",1)[0]
|
88 |
f_name=f'{dir_1}/{pf}.{sf}'
|
89 |
print(f_name)
|
90 |
-
|
91 |
else:
|
92 |
|
93 |
sf=d_app.split(".",1)[1]
|
94 |
pf=d_app.split(".",1)[0]
|
95 |
f_name=f'{pf}.{sf}'
|
96 |
pass
|
97 |
-
|
98 |
r = requests.get(f'https://huggingface.co/spaces/{repo}/{name}/raw/main/{d_app}')
|
99 |
print(d_app)
|
100 |
#print (r.text)
|
@@ -102,7 +104,13 @@ def get_hf_files(repo,name):
|
|
102 |
file = open(f'{name}/{f_name}','wb')
|
103 |
file.write(r.content)
|
104 |
file.close()
|
105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
print(file_list)
|
107 |
return file_list
|
108 |
|
|
|
57 |
except Exception as e:
|
58 |
return None
|
59 |
|
60 |
+
def get_hf_files(repo,name,path=""):
|
61 |
api = HfApi()
|
62 |
f_ist = (api.list_repo_files(repo_id=f'{repo}/{name}', repo_type="space"))
|
63 |
print (f_ist)
|
|
|
69 |
for d_app in f_ist:
|
70 |
if "/" in d_app:
|
71 |
dir_1=d_app.split("/",1)[0]
|
72 |
+
file_list.extend(get_hf_files(repo,name,dir_1))
|
73 |
+
'''
|
74 |
rem_1=d_app.split("/",1)[1]
|
75 |
if not os.path.exists(f'{name}/{dir_1}'):
|
76 |
os.makedirs(f'{name}/{dir_1}')
|
|
|
89 |
pf=rem_1.split(".",1)[0]
|
90 |
f_name=f'{dir_1}/{pf}.{sf}'
|
91 |
print(f_name)
|
92 |
+
'''
|
93 |
else:
|
94 |
|
95 |
sf=d_app.split(".",1)[1]
|
96 |
pf=d_app.split(".",1)[0]
|
97 |
f_name=f'{pf}.{sf}'
|
98 |
pass
|
99 |
+
|
100 |
r = requests.get(f'https://huggingface.co/spaces/{repo}/{name}/raw/main/{d_app}')
|
101 |
print(d_app)
|
102 |
#print (r.text)
|
|
|
104 |
file = open(f'{name}/{f_name}','wb')
|
105 |
file.write(r.content)
|
106 |
file.close()
|
107 |
+
if item['type'] == 'file':
|
108 |
+
files.append(item)
|
109 |
+
elif item['type'] == 'dir':
|
110 |
+
files.extend(get_all_files(owner, repo, item['path'], is_hf))
|
111 |
+
|
112 |
+
|
113 |
+
file_list.append({"path":f'{d_app}'})
|
114 |
print(file_list)
|
115 |
return file_list
|
116 |
|