Update app.py
Browse files
app.py
CHANGED
|
@@ -8,7 +8,10 @@ import zipfile
|
|
| 8 |
from pathlib import Path
|
| 9 |
from huggingface_hub import (create_repo,get_full_repo_name,upload_file,CommitOperationAdd,HfApi)
|
| 10 |
uid = uuid.uuid4()
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
| 12 |
#token_self = os.environ['HF_TOKEN']
|
| 13 |
o=os.environ['P']
|
| 14 |
model_list = [
|
|
@@ -28,10 +31,10 @@ def show_s(name,d_app,token):
|
|
| 28 |
author=name
|
| 29 |
s_ist = (api.list_spaces(author=author))
|
| 30 |
print (s_ist)
|
| 31 |
-
file_j = open('tmp_j','w')
|
| 32 |
file_j.writelines(str(s_ist))
|
| 33 |
file_j.close()
|
| 34 |
-
file_b = open('tmp_j','r')
|
| 35 |
r_file = file_b.readlines()
|
| 36 |
spaces=[]
|
| 37 |
spaces2=[]
|
|
@@ -58,24 +61,23 @@ def show_f(repo,name,token):
|
|
| 58 |
|
| 59 |
|
| 60 |
def load_space(r_name,s_name,d_app):
|
| 61 |
-
uid = uuid.uuid4()
|
| 62 |
print(f'https://huggingface.co/spaces/{r_name}/{s_name}/raw/main/{d_app}')
|
| 63 |
r = requests.get(f'https://huggingface.co/spaces/{r_name}/{s_name}/raw/main/{d_app}')
|
| 64 |
sf=d_app.split(".",1)[1]
|
| 65 |
pf=d_app.split(".",1)[0]
|
| 66 |
-
f_name=f'
|
| 67 |
-
file = open(f'{f_name}','w')
|
| 68 |
file.writelines(r.text)
|
| 69 |
file.close()
|
| 70 |
return r.text, f_name
|
| 71 |
def repl(rs,rt,uu):
|
| 72 |
-
file = open(f'{uu}','r')
|
| 73 |
r_file = file.read()
|
| 74 |
r_file = r_file.replace(f'{rs}',f'{rt}')
|
| 75 |
-
o_file = open(f'mod_{uu}','w')
|
| 76 |
o_file = o_file.write(r_file)
|
| 77 |
file.close()
|
| 78 |
-
return r_file, f'mod_{uu}'
|
| 79 |
|
| 80 |
def get_f(r_name,spaces,token):
|
| 81 |
api = HfApi(token=token)
|
|
|
|
| 8 |
from pathlib import Path
|
| 9 |
from huggingface_hub import (create_repo,get_full_repo_name,upload_file,CommitOperationAdd,HfApi)
|
| 10 |
uid = uuid.uuid4()
|
| 11 |
+
print(uid)
|
| 12 |
+
isExist = os.path.exists(f'{uid}')
|
| 13 |
+
if not isExist:
|
| 14 |
+
os.makedirs(f'{uid}')
|
| 15 |
#token_self = os.environ['HF_TOKEN']
|
| 16 |
o=os.environ['P']
|
| 17 |
model_list = [
|
|
|
|
| 31 |
author=name
|
| 32 |
s_ist = (api.list_spaces(author=author))
|
| 33 |
print (s_ist)
|
| 34 |
+
file_j = open(f'{uid}/tmp_j','w')
|
| 35 |
file_j.writelines(str(s_ist))
|
| 36 |
file_j.close()
|
| 37 |
+
file_b = open(f'{uid}/tmp_j','r')
|
| 38 |
r_file = file_b.readlines()
|
| 39 |
spaces=[]
|
| 40 |
spaces2=[]
|
|
|
|
| 61 |
|
| 62 |
|
| 63 |
def load_space(r_name,s_name,d_app):
|
|
|
|
| 64 |
print(f'https://huggingface.co/spaces/{r_name}/{s_name}/raw/main/{d_app}')
|
| 65 |
r = requests.get(f'https://huggingface.co/spaces/{r_name}/{s_name}/raw/main/{d_app}')
|
| 66 |
sf=d_app.split(".",1)[1]
|
| 67 |
pf=d_app.split(".",1)[0]
|
| 68 |
+
f_name=f'{pf}.{sf}'
|
| 69 |
+
file = open(f'{uid}/{f_name}','w')
|
| 70 |
file.writelines(r.text)
|
| 71 |
file.close()
|
| 72 |
return r.text, f_name
|
| 73 |
def repl(rs,rt,uu):
|
| 74 |
+
file = open(f'{uid}/{uu}','r')
|
| 75 |
r_file = file.read()
|
| 76 |
r_file = r_file.replace(f'{rs}',f'{rt}')
|
| 77 |
+
o_file = open(f'{uid}/mod_{uu}','w')
|
| 78 |
o_file = o_file.write(r_file)
|
| 79 |
file.close()
|
| 80 |
+
return r_file, f'{uid}/mod_{uu}'
|
| 81 |
|
| 82 |
def get_f(r_name,spaces,token):
|
| 83 |
api = HfApi(token=token)
|