Spaces:
Sleeping

xp3857 commited on
Commit
54f77d8
·
1 Parent(s): f2d7d4b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -4
app.py CHANGED
@@ -22,7 +22,7 @@ types=[
22
  ]
23
 
24
 
25
- def show_f(name,d_app,token):
26
  api = HfApi(token=token)
27
  author=name
28
  s_ist = (api.list_spaces(author=author))
@@ -42,7 +42,30 @@ def show_f(name,d_app,token):
42
  spaces.append(line)
43
  print(f"{line}")
44
  return(gr.Dropdown.update(label="Spaces", choices=[s for s in spaces]))
45
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  def load_space(r_name,s_name,d_app):
47
  uid = uuid.uuid4()
48
  print(f'https://huggingface.co/spaces/{r_name}/{s_name}/raw/main/{d_app}')
@@ -126,7 +149,7 @@ with gr.Blocks() as build:
126
  token = gr.Textbox(label="auth")
127
  with gr.Row():
128
  s_name = gr.Dropdown(label="Spaces", choices=[])
129
- d_app = gr.Textbox(label="File", value="app.py")
130
  with gr.Row():
131
  s_btn = gr.Button("Show")
132
  l_btn = gr.Button("Load")
@@ -144,7 +167,9 @@ with gr.Blocks() as build:
144
  m_t=gr.Textbox(max_lines=100)
145
  uu=gr.Textbox(visible=False)
146
 
147
- s_btn.click(show_f,r_name,s_name)
 
 
148
  l_btn.click(load_space,[r_name,s_name,d_app],[r_t,uu])
149
  r_btn.click(repl,[r_s,r_w,uu], [m_t,files])
150
 
 
22
  ]
23
 
24
 
25
+ def show_s(name,d_app,token):
26
  api = HfApi(token=token)
27
  author=name
28
  s_ist = (api.list_spaces(author=author))
 
42
  spaces.append(line)
43
  print(f"{line}")
44
  return(gr.Dropdown.update(label="Spaces", choices=[s for s in spaces]))
45
+
46
+ def show_f(repo,name,token):
47
+ api = HfApi(token=token)
48
+ f_ist = (api.list_repo_files(f'{repo}/{name}'))
49
+ print (f_ist)
50
+ file_j = open('tmp_f','w')
51
+ file_j.writelines(str(s_ist))
52
+ file_j.close()
53
+ file_b = open('tmp_f','r')
54
+ r_file = file_b.readlines()
55
+ files=[]
56
+ files.append("")
57
+ for line in r_file:
58
+ if "'id':" in line:
59
+ line = line.split(":",1)[1]
60
+ line = line.split("/",1)[1]
61
+ line = line.replace("'","").replace(",","").replace("\n","")
62
+ files.append(line)
63
+ print(f"{line}")
64
+ return(gr.Dropdown.update(label="Spaces", choices=[f for f in files]))
65
+
66
+
67
+
68
+
69
  def load_space(r_name,s_name,d_app):
70
  uid = uuid.uuid4()
71
  print(f'https://huggingface.co/spaces/{r_name}/{s_name}/raw/main/{d_app}')
 
149
  token = gr.Textbox(label="auth")
150
  with gr.Row():
151
  s_name = gr.Dropdown(label="Spaces", choices=[])
152
+ d_app = gr.Dropdown(label="Files", choices=[])
153
  with gr.Row():
154
  s_btn = gr.Button("Show")
155
  l_btn = gr.Button("Load")
 
167
  m_t=gr.Textbox(max_lines=100)
168
  uu=gr.Textbox(visible=False)
169
 
170
+ s_btn.click(show_s,r_name,s_name)
171
+ s_name.change(show_f,[r_name,s_name],d_app)
172
+
173
  l_btn.click(load_space,[r_name,s_name,d_app],[r_t,uu])
174
  r_btn.click(repl,[r_s,r_w,uu], [m_t,files])
175