Update app.py
Browse files
app.py
CHANGED
|
@@ -55,21 +55,22 @@ def show_f(repo,name,token):
|
|
| 55 |
def load_space(r_name,s_name,d_app):
|
| 56 |
print(f'https://huggingface.co/spaces/{r_name}/{s_name}/raw/main/{d_app}')
|
| 57 |
r = requests.get(f'https://huggingface.co/spaces/{r_name}/{s_name}/raw/main/{d_app}')
|
| 58 |
-
sf=d_app.split(".",1)[1]
|
| 59 |
-
pf=d_app.split(".",1)[0]
|
| 60 |
-
f_name=f'{pf}.{sf}'
|
| 61 |
-
|
|
|
|
| 62 |
file.writelines(r.text)
|
| 63 |
file.close()
|
| 64 |
return r.text, f_name
|
| 65 |
-
def repl(rs,rt,
|
| 66 |
-
file = open(f'{uid}/{
|
| 67 |
r_file = file.read()
|
| 68 |
r_file = r_file.replace(f'{rs}',f'{rt}')
|
| 69 |
-
o_file = open(f'{uid}/mod_{
|
| 70 |
o_file = o_file.write(r_file)
|
| 71 |
file.close()
|
| 72 |
-
return r_file, f'{uid}/mod_{
|
| 73 |
|
| 74 |
def get_f(r_name,spaces,token):
|
| 75 |
api = HfApi(token=token)
|
|
@@ -98,19 +99,25 @@ def get_f(r_name,spaces,token):
|
|
| 98 |
|
| 99 |
return(files_b,spaces_b)
|
| 100 |
|
| 101 |
-
def build_space(token,r_name,s_name,d_app,
|
| 102 |
if token==None or token=="":
|
| 103 |
token = token_self
|
| 104 |
else:
|
| 105 |
token = token
|
| 106 |
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
api = HfApi(token=token)
|
| 108 |
-
repo_name=f'{
|
| 109 |
print (repo_name)
|
| 110 |
try:
|
| 111 |
api.upload_file(
|
| 112 |
-
path_or_fileobj=f"{uid}/mod_{
|
| 113 |
-
path_in_repo=f"{
|
| 114 |
repo_id=repo_name,
|
| 115 |
token=token,
|
| 116 |
repo_type="space",
|
|
@@ -136,12 +143,14 @@ with gr.Blocks() as build:
|
|
| 136 |
with gr.Column(scale=3):
|
| 137 |
with gr.Box():
|
| 138 |
with gr.Row():
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
|
|
|
|
|
|
| 145 |
with gr.Row():
|
| 146 |
s_btn = gr.Button("Show")
|
| 147 |
l_btn = gr.Button("Load")
|
|
@@ -150,7 +159,9 @@ with gr.Blocks() as build:
|
|
| 150 |
r_w = gr.Textbox(label="with:")
|
| 151 |
r_btn = gr.Button("Replace")
|
| 152 |
with gr.Column():
|
| 153 |
-
|
|
|
|
|
|
|
| 154 |
output_html = gr.HTML("""""")
|
| 155 |
gr.Column(scale=1)
|
| 156 |
with gr.Accordion("Files",open=False):
|
|
@@ -183,5 +194,5 @@ with gr.Blocks() as build:
|
|
| 183 |
r_btn.click(repl,[r_s,r_w,uu], [m_t,files])
|
| 184 |
|
| 185 |
pass_btn.click(checkp,pass_box,[no,yes])
|
| 186 |
-
inbut.click(build_space,[token,r_name,s_name,d_app,
|
| 187 |
build.queue(concurrency_count=10).launch()
|
|
|
|
| 55 |
def load_space(r_name,s_name,d_app):
|
| 56 |
print(f'https://huggingface.co/spaces/{r_name}/{s_name}/raw/main/{d_app}')
|
| 57 |
r = requests.get(f'https://huggingface.co/spaces/{r_name}/{s_name}/raw/main/{d_app}')
|
| 58 |
+
#sf=d_app.split(".",1)[1]
|
| 59 |
+
#pf=d_app.split(".",1)[0]
|
| 60 |
+
#f_name=f'{pf}.{sf}'
|
| 61 |
+
|
| 62 |
+
file = open(f'{uid}/{d_app}','w')
|
| 63 |
file.writelines(r.text)
|
| 64 |
file.close()
|
| 65 |
return r.text, f_name
|
| 66 |
+
def repl(rs,rt,d_app):
|
| 67 |
+
file = open(f'{uid}/{d_app}','r')
|
| 68 |
r_file = file.read()
|
| 69 |
r_file = r_file.replace(f'{rs}',f'{rt}')
|
| 70 |
+
o_file = open(f'{uid}/mod_{d_app}','w')
|
| 71 |
o_file = o_file.write(r_file)
|
| 72 |
file.close()
|
| 73 |
+
return r_file, f'{uid}/mod_{d_app}'
|
| 74 |
|
| 75 |
def get_f(r_name,spaces,token):
|
| 76 |
api = HfApi(token=token)
|
|
|
|
| 99 |
|
| 100 |
return(files_b,spaces_b)
|
| 101 |
|
| 102 |
+
def build_space(token,r_name,s_name,d_app,rd_name,sd_name,dd_app):
|
| 103 |
if token==None or token=="":
|
| 104 |
token = token_self
|
| 105 |
else:
|
| 106 |
token = token
|
| 107 |
pass
|
| 108 |
+
if dd_app=="":
|
| 109 |
+
dd_app=d_app
|
| 110 |
+
if rd_name=="":
|
| 111 |
+
rd_name=r_name
|
| 112 |
+
if sd_name=="":
|
| 113 |
+
sd_name=s_name
|
| 114 |
api = HfApi(token=token)
|
| 115 |
+
repo_name=f'{rd_name}/{sd_name}'
|
| 116 |
print (repo_name)
|
| 117 |
try:
|
| 118 |
api.upload_file(
|
| 119 |
+
path_or_fileobj=f"{uid}/mod_{d_app}",
|
| 120 |
+
path_in_repo=f"{dd_app}",
|
| 121 |
repo_id=repo_name,
|
| 122 |
token=token,
|
| 123 |
repo_type="space",
|
|
|
|
| 143 |
with gr.Column(scale=3):
|
| 144 |
with gr.Box():
|
| 145 |
with gr.Row():
|
| 146 |
+
with gr.Column():
|
| 147 |
+
r_name = gr.Textbox(label="Source Repo")
|
| 148 |
+
s_name = gr.Dropdown(label="Spaces", choices=[])
|
| 149 |
+
d_app = gr.Dropdown(label="Files", choices=[])
|
| 150 |
+
with gr.Column():
|
| 151 |
+
rd_name = gr.Textbox(label="Dest Repo")
|
| 152 |
+
sd_name = gr.Dropdown(label="Spaces", choices=[])
|
| 153 |
+
dd_app = gr.Dropdown(label="Files", choices=[])
|
| 154 |
with gr.Row():
|
| 155 |
s_btn = gr.Button("Show")
|
| 156 |
l_btn = gr.Button("Load")
|
|
|
|
| 159 |
r_w = gr.Textbox(label="with:")
|
| 160 |
r_btn = gr.Button("Replace")
|
| 161 |
with gr.Column():
|
| 162 |
+
with gr.Row():
|
| 163 |
+
token = gr.Textbox(label="auth")
|
| 164 |
+
inbut = gr.Button("Update Repo")
|
| 165 |
output_html = gr.HTML("""""")
|
| 166 |
gr.Column(scale=1)
|
| 167 |
with gr.Accordion("Files",open=False):
|
|
|
|
| 194 |
r_btn.click(repl,[r_s,r_w,uu], [m_t,files])
|
| 195 |
|
| 196 |
pass_btn.click(checkp,pass_box,[no,yes])
|
| 197 |
+
inbut.click(build_space,[token,r_name,s_name,d_app,dd_app],output_html)
|
| 198 |
build.queue(concurrency_count=10).launch()
|