xp3857 commited on
Commit
c7763ca
·
1 Parent(s): 2359485

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -27
app.py CHANGED
@@ -76,7 +76,7 @@ def repl(rs,rt,uu):
76
 
77
 
78
 
79
- def build_space(token,t_name,s_type,m_type=None,r_type=None,d_app=None,d_css=None):
80
  model_id=t_name
81
  if token==None or token=="":
82
  token = token_self
@@ -84,35 +84,27 @@ def build_space(token,t_name,s_type,m_type=None,r_type=None,d_app=None,d_css=Non
84
  token = token
85
  pass
86
  api = HfApi(token=token)
87
- repo_name = get_full_repo_name(model_id=model_id, token=token)
 
88
  print (repo_name)
89
- repo_name=repo_name.split("/",1)[1]
90
- print(repo_name)
91
  try:
92
- api_url = f'https://huggingface.co/api/spaces/{model_id}'
93
- if s_type == "A":
94
-
95
-
96
- with open(f'tmp_file{uid}.txt', "r") as f:
97
- app = f.read()
98
- app = app.replace("gr.Blocks", "edited")
99
- #app = app.replace("$app2", d_app)
100
- #app = app.replace("$css2", d_css)
101
-
102
- with open(f"{uid}at.py", "w") as f:
103
- f.write(app)
104
 
105
- api.upload_file(
106
- path_or_fileobj=f"{uid}at.py",
107
- path_in_repo="app.py",
108
- repo_id=repo_name,
109
- token=token,
110
- repo_type="space",
111
- )
112
- os.remove(f"{uid}at.py")
113
 
114
-
115
- return gr.HTML.update(f'''<center>Link to space <a href="https://huggingface.co/spaces/{repo_name}" target="_blank">https://huggingface.co/spaces/{repo_name}</a><center><br>''')
116
  except Exception as e:
117
  return gr.HTML.update(f"""{str(e)}""")
118
 
@@ -167,5 +159,5 @@ with gr.Blocks() as build:
167
  r_btn.click(repl,[r_s,r_w,uu], [m_t,files])
168
 
169
  pass_btn.click(checkp,pass_box,[no,yes])
170
- #inbut.click(build_space,[token,t_name,s_type,m_type,r_type,d_app,d_css],output_html)
171
  build.queue(concurrency_count=10).launch()
 
76
 
77
 
78
 
79
+ def build_space(token,r_name,s_name,d_app,uu):
80
  model_id=t_name
81
  if token==None or token=="":
82
  token = token_self
 
84
  token = token
85
  pass
86
  api = HfApi(token=token)
87
+ repo_name=f'{r_name}/{s_name}'
88
+ #repo_name = get_full_repo_name(model_id=model_id, token=token)
89
  print (repo_name)
90
+ #repo_name=repo_name.split("/",1)[1]
91
+ #print(repo_name)
92
  try:
93
+ #api_url = f'https://huggingface.co/api/spaces/{model_id}'
94
+ #if s_type == "A":
95
+
96
+
97
+ api.upload_file(
98
+ path_or_fileobj=f"{uu}",
99
+ path_in_repo=f"{d_app}",
100
+ repo_id=repo_name,
101
+ token=token,
102
+ repo_type="space",
103
+ )
104
+ #os.remove(f"{uid}at.py")
105
 
 
 
 
 
 
 
 
 
106
 
107
+ return gr.HTML.update(f'''<center>Link to space <a href="https://huggingface.co/spaces/{repo_name}" target="_blank">https://huggingface.co/spaces/{repo_name}</a><center><br>''')
 
108
  except Exception as e:
109
  return gr.HTML.update(f"""{str(e)}""")
110
 
 
159
  r_btn.click(repl,[r_s,r_w,uu], [m_t,files])
160
 
161
  pass_btn.click(checkp,pass_box,[no,yes])
162
+ inbut.click(build_space,[token,r_name,s_name,d_app,uu],output_html)
163
  build.queue(concurrency_count=10).launch()