xp3857 commited on
Commit
6a7e928
·
1 Parent(s): ba0835f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -25
app.py CHANGED
@@ -4,6 +4,7 @@ import uuid
4
  import gradio as gr
5
  import requests
6
  import json
 
7
  from pathlib import Path
8
  from huggingface_hub import (create_repo,get_full_repo_name,upload_file,CommitOperationAdd,HfApi)
9
  uid = uuid.uuid4()
@@ -73,7 +74,18 @@ def repl(rs,rt,uu):
73
  file.close()
74
  return r_file, f'mod_{uu}'
75
 
76
-
 
 
 
 
 
 
 
 
 
 
 
77
 
78
 
79
  def build_space(token,r_name,s_name,d_app,uu):
@@ -118,38 +130,45 @@ with gr.Blocks() as build:
118
  pass_box=gr.Textbox()
119
  pass_btn=gr.Button()
120
  with gr.Box(visible=False) as yes:
121
- with gr.Row():
122
- gr.Column(scale=1)
123
- with gr.Column(scale=3):
124
- with gr.Box():
125
- with gr.Row():
126
- r_name = gr.Textbox(label="Repo")
127
- token = gr.Textbox(label="auth")
128
- with gr.Row():
129
- s_name = gr.Dropdown(label="Spaces", choices=[])
130
- d_app = gr.Dropdown(label="Files", choices=[])
131
- with gr.Row():
132
- s_btn = gr.Button("Show")
133
- l_btn = gr.Button("Load")
134
- with gr.Box():
135
- r_s = gr.Textbox(label="Replace")
136
- r_w = gr.Textbox(label="with:")
137
- r_btn = gr.Button("Replace")
138
- with gr.Column():
139
- inbut = gr.Button("Update Repo")
140
- output_html = gr.HTML("""""")
141
- gr.Column(scale=1)
 
142
  with gr.Accordion("Files",open=False):
143
- files=gr.File()
 
 
 
 
 
144
  with gr.Row():
145
  r_t=gr.Textbox(max_lines=100)
146
  m_t=gr.Textbox(max_lines=100)
 
147
  uu=gr.Textbox(visible=False)
148
-
149
  def cyc(x):
150
  return x,None
151
 
152
-
153
  r_t.change(cyc,r_t,[m_t,files])
154
 
155
  s_btn.click(show_s,r_name,s_name)
 
4
  import gradio as gr
5
  import requests
6
  import json
7
+ import zipfile
8
  from pathlib import Path
9
  from huggingface_hub import (create_repo,get_full_repo_name,upload_file,CommitOperationAdd,HfApi)
10
  uid = uuid.uuid4()
 
74
  file.close()
75
  return r_file, f'mod_{uu}'
76
 
77
+ def get_f(r_name,spaces,token):
78
+ api = HfApi(token=token)
79
+ spaces_b=[]
80
+ files_b=[]
81
+ for space in spaces:
82
+ f_ist = (api.list_repo_files(repo_id=f'{r_name}/{space}', repo_type="space"))
83
+ print(space)
84
+ for file in f_ist:
85
+ r = requests.get(f'https://huggingface.co/spaces/{r_name}/{space}/raw/main/{file}')
86
+ print(file)
87
+ #with zipfile.ZipFile('new.zip', 'w') as new_zip:
88
+ # new_zip.write('spam.txt', compress_type=zipfile.ZIP_DEFLATED)
89
 
90
 
91
  def build_space(token,r_name,s_name,d_app,uu):
 
130
  pass_box=gr.Textbox()
131
  pass_btn=gr.Button()
132
  with gr.Box(visible=False) as yes:
133
+ with gr.Row():
134
+ gr.Column(scale=1)
135
+ with gr.Column(scale=3):
136
+ with gr.Box():
137
+ with gr.Row():
138
+ r_name = gr.Textbox(label="Repo")
139
+ token = gr.Textbox(label="auth")
140
+
141
+ with gr.Row():
142
+ s_name = gr.Dropdown(label="Spaces", choices=[])
143
+ d_app = gr.Dropdown(label="Files", choices=[])
144
+ with gr.Row():
145
+ s_btn = gr.Button("Show")
146
+ l_btn = gr.Button("Load")
147
+ with gr.Box():
148
+ r_s = gr.Textbox(label="Replace")
149
+ r_w = gr.Textbox(label="with:")
150
+ r_btn = gr.Button("Replace")
151
+ with gr.Column():
152
+ inbut = gr.Button("Update Repo")
153
+ output_html = gr.HTML("""""")
154
+ gr.Column(scale=1)
155
  with gr.Accordion("Files",open=False):
156
+ with gr.Tab("Modify"):
157
+ files=gr.File()
158
+ with gr.Tab("Download"):
159
+ l_btn=gr.Button()
160
+ a_files=gr.File()
161
+
162
  with gr.Row():
163
  r_t=gr.Textbox(max_lines=100)
164
  m_t=gr.Textbox(max_lines=100)
165
+ au=gr.Textbox(visible=False)
166
  uu=gr.Textbox(visible=False)
167
+
168
  def cyc(x):
169
  return x,None
170
 
171
+ l_btn.click(get_f,[r_name,s_name,token],None)
172
  r_t.change(cyc,r_t,[m_t,files])
173
 
174
  s_btn.click(show_s,r_name,s_name)