Update app.py
Browse files
app.py
CHANGED
|
@@ -4,7 +4,6 @@ import uuid
|
|
| 4 |
import gradio as gr
|
| 5 |
import requests
|
| 6 |
import json
|
| 7 |
-
import zipfile
|
| 8 |
import tarfile
|
| 9 |
from pathlib import Path
|
| 10 |
from huggingface_hub import (create_repo,get_full_repo_name,upload_file,CommitOperationAdd,HfApi)
|
|
@@ -44,9 +43,6 @@ def show_s(name,d_app,token):
|
|
| 44 |
line = line.split(":",1)[1]
|
| 45 |
line = line.split("/",1)[1]
|
| 46 |
line2 = line.replace("'","").replace(",","").replace("\n","")
|
| 47 |
-
#line3 = line.replace("'","").replace(",","")
|
| 48 |
-
|
| 49 |
-
#spaces2.append(line3)
|
| 50 |
spaces.append(line2)
|
| 51 |
print(f"{line2}")
|
| 52 |
return(gr.update(label="Spaces", choices=[s for s in spaces]),gr.update(label="Spaces", choices=[s for s in spaces]))
|
|
@@ -54,13 +50,8 @@ def show_s(name,d_app,token):
|
|
| 54 |
def show_f(repo,name,token):
|
| 55 |
api = HfApi(token=token)
|
| 56 |
f_ist = (api.list_repo_files(repo_id=f'{repo}/{name}', repo_type="space"))
|
| 57 |
-
print (f_ist)
|
| 58 |
-
|
| 59 |
return(gr.Dropdown.update(label="Files", choices=[f for f in f_ist]))
|
| 60 |
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
def load_space(r_name,s_name,d_app):
|
| 65 |
print(f'https://huggingface.co/spaces/{r_name}/{s_name}/raw/main/{d_app}')
|
| 66 |
r = requests.get(f'https://huggingface.co/spaces/{r_name}/{s_name}/raw/main/{d_app}')
|
|
@@ -85,18 +76,11 @@ def get_f(r_name,spaces,token):
|
|
| 85 |
spaces_b=[]
|
| 86 |
files_b=[]
|
| 87 |
files_c=[]
|
| 88 |
-
#spaces=spaces.replace("[","").replace("]","").replace("'","").replace(" ","")
|
| 89 |
-
#spaces=spaces.split(",")
|
| 90 |
-
print (spaces)
|
| 91 |
|
| 92 |
for space in spaces:
|
| 93 |
isExist = os.path.exists(f'{space}')
|
| 94 |
if not isExist:
|
| 95 |
os.makedirs(f'{space}')
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
print(space)
|
| 99 |
-
print("###############")
|
| 100 |
f_ist = (api.list_repo_files(repo_id=f'{r_name}/{space}', repo_type="space"))
|
| 101 |
for file in f_ist:
|
| 102 |
t_file=open(f'{uid}/{space}-{file}','w')
|
|
@@ -107,14 +91,9 @@ def get_f(r_name,spaces,token):
|
|
| 107 |
zz_file.write(r.text)
|
| 108 |
zz_file.close()
|
| 109 |
files_b.append(f'{uid}/{space}-{file}')
|
| 110 |
-
#files_c.append(f'{uid}/{file}')
|
| 111 |
-
|
| 112 |
-
print(file)
|
| 113 |
with tarfile.open(f'{space}.tar.gz','w:gz') as tar:
|
| 114 |
tar.add(f"./{space}",arcname=os.path.basename(f"./{space}"))
|
| 115 |
-
|
| 116 |
-
#with zipfile.ZipFile(f'{space}.zip', 'w') as new_zip:
|
| 117 |
-
# new_zip.write(f'{space}/', compress_type=zipfile.ZIP_DEFLATED)
|
| 118 |
spaces_b.append(f'{space}.tar.gz')
|
| 119 |
|
| 120 |
return(files_b,spaces_b)
|
|
@@ -127,15 +106,8 @@ def build_space(token,r_name,s_name,d_app,uu):
|
|
| 127 |
pass
|
| 128 |
api = HfApi(token=token)
|
| 129 |
repo_name=f'{r_name}/{s_name}'
|
| 130 |
-
#repo_name = get_full_repo_name(model_id=model_id, token=token)
|
| 131 |
print (repo_name)
|
| 132 |
-
#repo_name=repo_name.split("/",1)[1]
|
| 133 |
-
#print(repo_name)
|
| 134 |
try:
|
| 135 |
-
#api_url = f'https://huggingface.co/api/spaces/{model_id}'
|
| 136 |
-
#if s_type == "A":
|
| 137 |
-
|
| 138 |
-
|
| 139 |
api.upload_file(
|
| 140 |
path_or_fileobj=f"mod_{uu}",
|
| 141 |
path_in_repo=f"{d_app}",
|
|
@@ -144,8 +116,6 @@ def build_space(token,r_name,s_name,d_app,uu):
|
|
| 144 |
repo_type="space",
|
| 145 |
)
|
| 146 |
#os.remove(f"{uid}at.py")
|
| 147 |
-
|
| 148 |
-
|
| 149 |
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>''')
|
| 150 |
except Exception as e:
|
| 151 |
return gr.HTML.update(f"""{str(e)}""")
|
|
|
|
| 4 |
import gradio as gr
|
| 5 |
import requests
|
| 6 |
import json
|
|
|
|
| 7 |
import tarfile
|
| 8 |
from pathlib import Path
|
| 9 |
from huggingface_hub import (create_repo,get_full_repo_name,upload_file,CommitOperationAdd,HfApi)
|
|
|
|
| 43 |
line = line.split(":",1)[1]
|
| 44 |
line = line.split("/",1)[1]
|
| 45 |
line2 = line.replace("'","").replace(",","").replace("\n","")
|
|
|
|
|
|
|
|
|
|
| 46 |
spaces.append(line2)
|
| 47 |
print(f"{line2}")
|
| 48 |
return(gr.update(label="Spaces", choices=[s for s in spaces]),gr.update(label="Spaces", choices=[s for s in spaces]))
|
|
|
|
| 50 |
def show_f(repo,name,token):
|
| 51 |
api = HfApi(token=token)
|
| 52 |
f_ist = (api.list_repo_files(repo_id=f'{repo}/{name}', repo_type="space"))
|
|
|
|
|
|
|
| 53 |
return(gr.Dropdown.update(label="Files", choices=[f for f in f_ist]))
|
| 54 |
|
|
|
|
|
|
|
|
|
|
| 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}')
|
|
|
|
| 76 |
spaces_b=[]
|
| 77 |
files_b=[]
|
| 78 |
files_c=[]
|
|
|
|
|
|
|
|
|
|
| 79 |
|
| 80 |
for space in spaces:
|
| 81 |
isExist = os.path.exists(f'{space}')
|
| 82 |
if not isExist:
|
| 83 |
os.makedirs(f'{space}')
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
f_ist = (api.list_repo_files(repo_id=f'{r_name}/{space}', repo_type="space"))
|
| 85 |
for file in f_ist:
|
| 86 |
t_file=open(f'{uid}/{space}-{file}','w')
|
|
|
|
| 91 |
zz_file.write(r.text)
|
| 92 |
zz_file.close()
|
| 93 |
files_b.append(f'{uid}/{space}-{file}')
|
|
|
|
|
|
|
|
|
|
| 94 |
with tarfile.open(f'{space}.tar.gz','w:gz') as tar:
|
| 95 |
tar.add(f"./{space}",arcname=os.path.basename(f"./{space}"))
|
| 96 |
+
|
|
|
|
|
|
|
| 97 |
spaces_b.append(f'{space}.tar.gz')
|
| 98 |
|
| 99 |
return(files_b,spaces_b)
|
|
|
|
| 106 |
pass
|
| 107 |
api = HfApi(token=token)
|
| 108 |
repo_name=f'{r_name}/{s_name}'
|
|
|
|
| 109 |
print (repo_name)
|
|
|
|
|
|
|
| 110 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
api.upload_file(
|
| 112 |
path_or_fileobj=f"mod_{uu}",
|
| 113 |
path_in_repo=f"{d_app}",
|
|
|
|
| 116 |
repo_type="space",
|
| 117 |
)
|
| 118 |
#os.remove(f"{uid}at.py")
|
|
|
|
|
|
|
| 119 |
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>''')
|
| 120 |
except Exception as e:
|
| 121 |
return gr.HTML.update(f"""{str(e)}""")
|