Update app.py
Browse files
app.py
CHANGED
|
@@ -22,9 +22,9 @@ types=[
|
|
| 22 |
]
|
| 23 |
|
| 24 |
|
| 25 |
-
def show_f(
|
| 26 |
api = HfApi(token=token)
|
| 27 |
-
author=
|
| 28 |
s_ist = (api.list_spaces(author=author))
|
| 29 |
print (s_ist)
|
| 30 |
file_j = open('tmp_j','w')
|
|
@@ -33,18 +33,19 @@ def show_f(model_id,d_app,token):
|
|
| 33 |
file_b = open('tmp_j','r')
|
| 34 |
r_file = file_b.readlines()
|
| 35 |
spaces=[]
|
|
|
|
| 36 |
for line in r_file:
|
| 37 |
if "'id':" in line:
|
| 38 |
line = line.split(":",1)[1]
|
| 39 |
line = line.split("/",1)[1]
|
| 40 |
line = line.replace("'","").replace(",","")
|
| 41 |
spaces.append(line)
|
| 42 |
-
print(f"
|
| 43 |
-
return(spaces)
|
| 44 |
|
| 45 |
-
def load_space(
|
| 46 |
uid = uuid.uuid4()
|
| 47 |
-
r = requests.get(f'https://huggingface.co/spaces/{
|
| 48 |
sf=d_app.split(".",1)[1]
|
| 49 |
pf=d_app.split(".",1)[0]
|
| 50 |
f_name=f'pf_{uid}.{sf}'
|
|
@@ -119,11 +120,14 @@ with gr.Blocks() as build:
|
|
| 119 |
gr.Column(scale=1)
|
| 120 |
with gr.Column(scale=3):
|
| 121 |
with gr.Box():
|
| 122 |
-
|
| 123 |
-
|
|
|
|
|
|
|
|
|
|
| 124 |
d_app = gr.Textbox(label="File", value="app.py")
|
| 125 |
with gr.Row():
|
| 126 |
-
s_btn = gr.Button("
|
| 127 |
l_btn = gr.Button("Load")
|
| 128 |
with gr.Box():
|
| 129 |
r_s = gr.Textbox(label="Replace")
|
|
@@ -139,8 +143,8 @@ with gr.Blocks() as build:
|
|
| 139 |
m_t=gr.Textbox(max_lines=100)
|
| 140 |
uu=gr.Textbox(visible=False)
|
| 141 |
|
| 142 |
-
s_btn.click(show_f,t_name,
|
| 143 |
-
l_btn.click(load_space,[
|
| 144 |
r_btn.click(repl,[r_s,r_w,uu], [m_t,files])
|
| 145 |
|
| 146 |
pass_btn.click(checkp,pass_box,[no,yes])
|
|
|
|
| 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))
|
| 29 |
print (s_ist)
|
| 30 |
file_j = open('tmp_j','w')
|
|
|
|
| 33 |
file_b = open('tmp_j','r')
|
| 34 |
r_file = file_b.readlines()
|
| 35 |
spaces=[]
|
| 36 |
+
spaces.append("")
|
| 37 |
for line in r_file:
|
| 38 |
if "'id':" in line:
|
| 39 |
line = line.split(":",1)[1]
|
| 40 |
line = line.split("/",1)[1]
|
| 41 |
line = line.replace("'","").replace(",","")
|
| 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 |
+
r = requests.get(f'https://huggingface.co/spaces/{r_name}/{s_name}/raw/main/{d_app}')
|
| 49 |
sf=d_app.split(".",1)[1]
|
| 50 |
pf=d_app.split(".",1)[0]
|
| 51 |
f_name=f'pf_{uid}.{sf}'
|
|
|
|
| 120 |
gr.Column(scale=1)
|
| 121 |
with gr.Column(scale=3):
|
| 122 |
with gr.Box():
|
| 123 |
+
with gr.Row():
|
| 124 |
+
r_name = gr.Textbox(label="Repo")
|
| 125 |
+
token = gr.Textbox(label="auth")
|
| 126 |
+
with gr.Row():
|
| 127 |
+
s_name = gr.Dropdown(label="Spaces", choices=[])
|
| 128 |
d_app = gr.Textbox(label="File", value="app.py")
|
| 129 |
with gr.Row():
|
| 130 |
+
s_btn = gr.Button("Show")
|
| 131 |
l_btn = gr.Button("Load")
|
| 132 |
with gr.Box():
|
| 133 |
r_s = gr.Textbox(label="Replace")
|
|
|
|
| 143 |
m_t=gr.Textbox(max_lines=100)
|
| 144 |
uu=gr.Textbox(visible=False)
|
| 145 |
|
| 146 |
+
s_btn.click(show_f,t_name,s_name)
|
| 147 |
+
l_btn.click(load_space,[r_name,s_name,d_app],[r_t,uu])
|
| 148 |
r_btn.click(repl,[r_s,r_w,uu], [m_t,files])
|
| 149 |
|
| 150 |
pass_btn.click(checkp,pass_box,[no,yes])
|