Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -35,72 +35,64 @@ def show_s(name,token):
|
|
35 |
return(gr.update(label="Spaces", choices=[s for s in spaces]))
|
36 |
#gr.update(choices=[s for s in spaces],interactive=True))
|
37 |
|
38 |
-
def show_f(repo,name,token):
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
else:
|
65 |
-
|
66 |
-
|
67 |
-
#f_name=f'{dir_1}/{pf}.{sf}'
|
68 |
-
f_name=f'{dir_1}/{rem_1}'
|
69 |
-
print(f_name)
|
70 |
-
|
71 |
-
else:
|
72 |
|
73 |
-
|
74 |
-
|
75 |
-
#
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
gr.update(choices=[f for f in f_ist],interactive=True),
|
102 |
-
api.get_space_runtime(f'{repo}/{name}'))
|
103 |
-
|
104 |
def show_f_cont(repo,name,file,token):
|
105 |
html_text = '<html>\n<body>\n<div>\n'
|
106 |
images=[".png" , ".jpg" , ".gif" , ".webm" , ".mp4"]
|
@@ -142,6 +134,7 @@ with gr.Blocks(css=css) as build:
|
|
142 |
token = gr.Textbox(label="auth")
|
143 |
s_btn = gr.Button("Show Spaces")
|
144 |
with gr.Column(scale=1):
|
|
|
145 |
files=gr.File(file_count="directory")
|
146 |
with gr.Tab("View 1"):
|
147 |
with gr.Row():
|
@@ -201,6 +194,6 @@ with gr.Blocks(css=css) as build:
|
|
201 |
|
202 |
move_btn.click(move,[r_name,space_radio,dest,token]).then(show_s,[r_name,token],[space_radio])
|
203 |
s_btn.click(show_s,[r_name,token],[space_radio])
|
204 |
-
space_radio.change(show_f,[r_name,space_radio,token],[files,file_radio,space_info_json])
|
205 |
file_radio.change(show_f_cont,[r_name,space_radio,file_radio,token],[file_contents])
|
206 |
build.queue(default_concurrency_limit=10).launch(show_api=False)
|
|
|
35 |
return(gr.update(label="Spaces", choices=[s for s in spaces]))
|
36 |
#gr.update(choices=[s for s in spaces],interactive=True))
|
37 |
|
38 |
+
def show_f(repo,name,token,tog):
|
39 |
+
if tog:
|
40 |
+
api = HfApi(token=token)
|
41 |
+
f_ist = (api.list_repo_files(repo_id=f'{repo}/{name}', repo_type="space"))
|
42 |
+
print (f_ist)
|
43 |
+
file_list = []
|
44 |
+
#file_out = []
|
45 |
+
|
46 |
+
if not os.path.exists(name):
|
47 |
+
os.makedirs(name)
|
48 |
+
for d_app in f_ist:
|
49 |
+
if "/" in d_app:
|
50 |
+
dir_1=d_app.split("/",1)[0]
|
51 |
+
rem_1=d_app.split("/",1)[1]
|
52 |
+
if not os.path.exists(f'{name}/{dir_1}'):
|
53 |
+
os.makedirs(f'{name}/{dir_1}')
|
54 |
+
if "/" in rem_1:
|
55 |
+
dir_2=rem_1.split("/",1)[0]
|
56 |
+
rem_2=rem_1.split("/",1)[1]
|
57 |
+
if not os.path.exists(f'{name}/{dir_1}/{dir_2}'):
|
58 |
+
os.makedirs(f'{name}/{dir_1}/{dir_2}')
|
59 |
+
f_name=f'{dir_1}/{dir2}/{rem_2}'
|
60 |
+
|
61 |
+
else:
|
62 |
+
f_name=f'{dir_1}/{rem_1}'
|
63 |
+
print(f_name)
|
64 |
else:
|
65 |
+
f_name=f'{d_app}'
|
66 |
+
pass
|
|
|
|
|
|
|
|
|
|
|
67 |
|
68 |
+
r = requests.get(f'https://huggingface.co/spaces/{repo}/{name}/raw/main/{d_app}')
|
69 |
+
print(d_app)
|
70 |
+
#print (r.text)
|
71 |
+
uid = uuid.uuid4()
|
72 |
+
file = open(f'{name}/{f_name}','wb')
|
73 |
+
#file = open(f'{name}/{f_name}','wb')
|
74 |
+
file.write(r.content)
|
75 |
+
file.close()
|
76 |
+
file_list.append(f'{name}/{f_name}')
|
77 |
+
|
78 |
+
with ZipFile(f"{name}.zip", "w") as zipObj:
|
79 |
+
for idx, file in enumerate(f_ist):
|
80 |
+
zipObj.write(f'{name}/{file}')
|
81 |
+
file_list.append(f'{name}.zip')
|
82 |
+
|
83 |
+
s_info=api.space_info(f'{repo}/{name}',files_metadata=True)
|
84 |
+
'''
|
85 |
+
with open(f'{uid}-tmp.json','w') as f:
|
86 |
+
json.dump(s_info,f,indent=4)
|
87 |
+
f.close()
|
88 |
+
'''
|
89 |
+
return(file_list,
|
90 |
+
gr.update(choices=[f for f in f_ist],interactive=True),
|
91 |
+
api.get_space_runtime(f'{repo}/{name}'))
|
92 |
+
else:
|
93 |
+
return(None,
|
94 |
+
None,
|
95 |
+
api.get_space_runtime(f'{repo}/{name}'))
|
|
|
|
|
|
|
96 |
def show_f_cont(repo,name,file,token):
|
97 |
html_text = '<html>\n<body>\n<div>\n'
|
98 |
images=[".png" , ".jpg" , ".gif" , ".webm" , ".mp4"]
|
|
|
134 |
token = gr.Textbox(label="auth")
|
135 |
s_btn = gr.Button("Show Spaces")
|
136 |
with gr.Column(scale=1):
|
137 |
+
tog=gr.Checkbox(label="Show Files",value=True)
|
138 |
files=gr.File(file_count="directory")
|
139 |
with gr.Tab("View 1"):
|
140 |
with gr.Row():
|
|
|
194 |
|
195 |
move_btn.click(move,[r_name,space_radio,dest,token]).then(show_s,[r_name,token],[space_radio])
|
196 |
s_btn.click(show_s,[r_name,token],[space_radio])
|
197 |
+
space_radio.change(show_f,[r_name,space_radio,token,tog],[files,file_radio,space_info_json])
|
198 |
file_radio.change(show_f_cont,[r_name,space_radio,file_radio,token],[file_contents])
|
199 |
build.queue(default_concurrency_limit=10).launch(show_api=False)
|