Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,9 @@ import gradio as gr
|
|
2 |
import requests
|
3 |
from bs4 import BeautifulSoup
|
4 |
import re
|
|
|
|
|
|
|
5 |
'''
|
6 |
from selenium import webdriver
|
7 |
from bs4 import BeautifulSoup
|
@@ -192,6 +195,83 @@ def format_t(inp):
|
|
192 |
</html>'''
|
193 |
return out
|
194 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
195 |
load_js = """
|
196 |
func = function(a,b) {
|
197 |
console.log(a);
|
@@ -226,7 +306,7 @@ def prepare_card(url,title,description,img):
|
|
226 |
else:
|
227 |
filename=filename.replace("?","-").replace("=","-")
|
228 |
filename = filename.replace(".","-").replace("/","-").replace("?","-").replace("=","-")
|
229 |
-
filename = f'{filename}.html'
|
230 |
with open("template.html", "r") as f:
|
231 |
app = f.read()
|
232 |
app = app.replace("$space", url)
|
|
|
2 |
import requests
|
3 |
from bs4 import BeautifulSoup
|
4 |
import re
|
5 |
+
import os
|
6 |
+
token_self=os.environ.get("HF_TOKEN")
|
7 |
+
default_repo_name="collection"
|
8 |
'''
|
9 |
from selenium import webdriver
|
10 |
from bs4 import BeautifulSoup
|
|
|
195 |
</html>'''
|
196 |
return out
|
197 |
|
198 |
+
|
199 |
+
def build_space(file_content,file_name,repo_name=None,token=None):
|
200 |
+
|
201 |
+
if repo_name==None or repo_name=="":
|
202 |
+
model_id = default_repo_name
|
203 |
+
else:
|
204 |
+
mdoel_id = repo_name
|
205 |
+
if token==None or token=="":
|
206 |
+
token = token_self
|
207 |
+
else:
|
208 |
+
token = token
|
209 |
+
pass
|
210 |
+
api = HfApi(token=token)
|
211 |
+
repo_name = get_full_repo_name(model_id=model_id, token=token)
|
212 |
+
|
213 |
+
try:
|
214 |
+
repo_url = api.create_repo(
|
215 |
+
repo_id=model_id,
|
216 |
+
repo_type="space",
|
217 |
+
space_sdk="static",
|
218 |
+
exist_ok=True,
|
219 |
+
private=False,
|
220 |
+
)
|
221 |
+
print(f"""Space Built at {repo_name}""")
|
222 |
+
|
223 |
+
except Exception as e:
|
224 |
+
return gr.HTML(f"""{str(e)}""")
|
225 |
+
|
226 |
+
|
227 |
+
try:
|
228 |
+
api_url = f'https://huggingface.co/api/spaces/{model_id}'
|
229 |
+
t_link3= f"https://{repo_name.replace('/','-').replace('_','-')}.static.hf.space/masto.html"
|
230 |
+
t_link2= f"https://{repo_name.replace('/','-').replace('_','-')}.static.hf.space/gab.html"
|
231 |
+
t_link = f"https://{repo_name.replace('/','-').replace('_','-')}.static.hf.space/main.html"
|
232 |
+
|
233 |
+
########## norm
|
234 |
+
|
235 |
+
with open("main.html", "w") as f:
|
236 |
+
f.write(file_content)
|
237 |
+
|
238 |
+
api.upload_file(
|
239 |
+
path_or_fileobj="main.html",
|
240 |
+
path_in_repo="main.html",
|
241 |
+
repo_id=repo_name,
|
242 |
+
token=token,
|
243 |
+
repo_type="space",
|
244 |
+
)
|
245 |
+
|
246 |
+
######## gab
|
247 |
+
|
248 |
+
api.upload_file(
|
249 |
+
path_or_fileobj="main.html",
|
250 |
+
path_in_repo="gab.html",
|
251 |
+
repo_id=repo_name,
|
252 |
+
token=token,
|
253 |
+
repo_type="space",
|
254 |
+
)
|
255 |
+
######## masto
|
256 |
+
|
257 |
+
api.upload_file(
|
258 |
+
path_or_fileobj="main.html",
|
259 |
+
path_in_repo="masto.html",
|
260 |
+
repo_id=repo_name,
|
261 |
+
token=token,
|
262 |
+
repo_type="space",
|
263 |
+
)
|
264 |
+
|
265 |
+
|
266 |
+
return gr.HTML(f'''<center>Your Interactive Twitter Card Embed Link is:<br><a href="{t_link}" target="_blank">{t_link}</a><br>
|
267 |
+
Your Interactive Mastodon Card Embed Link is:<br><a href="{t_link3}" target="_blank">{t_link3}</a><br>
|
268 |
+
Your Interactive Gab Card Embed Link is:<br><a href="{t_link2}" target="_blank">{t_link2}</a><br>
|
269 |
+
<center><br>''')
|
270 |
+
except Exception as e:
|
271 |
+
return gr.HTML(f"""{str(e)}""")
|
272 |
+
|
273 |
+
|
274 |
+
|
275 |
load_js = """
|
276 |
func = function(a,b) {
|
277 |
console.log(a);
|
|
|
306 |
else:
|
307 |
filename=filename.replace("?","-").replace("=","-")
|
308 |
filename = filename.replace(".","-").replace("/","-").replace("?","-").replace("=","-")
|
309 |
+
#filename = f'{filename}.html'
|
310 |
with open("template.html", "r") as f:
|
311 |
app = f.read()
|
312 |
app = app.replace("$space", url)
|