Update app.py
Browse files
app.py
CHANGED
|
@@ -39,6 +39,7 @@ types=[
|
|
| 39 |
"C",
|
| 40 |
"D",
|
| 41 |
"R1",
|
|
|
|
| 42 |
]
|
| 43 |
|
| 44 |
def build_space(token,t_name,s_type,m_type=None,r_type=None,d_app=None,d_css=None):
|
|
@@ -49,6 +50,8 @@ def build_space(token,t_name,s_type,m_type=None,r_type=None,d_app=None,d_css=Non
|
|
| 49 |
else:
|
| 50 |
token = token
|
| 51 |
pass
|
|
|
|
|
|
|
| 52 |
api = HfApi(token=token)
|
| 53 |
repo_name = get_full_repo_name(model_id=model_id, token=token)
|
| 54 |
try:
|
|
@@ -174,7 +177,47 @@ def build_space(token,t_name,s_type,m_type=None,r_type=None,d_app=None,d_css=Non
|
|
| 174 |
)
|
| 175 |
os.remove(f"{uid}read.txt")
|
| 176 |
|
| 177 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
|
| 179 |
elif s_type == "R1":
|
| 180 |
with open("r1.py", "r") as f:
|
|
|
|
| 39 |
"C",
|
| 40 |
"D",
|
| 41 |
"R1",
|
| 42 |
+
"Auto Image Space"
|
| 43 |
]
|
| 44 |
|
| 45 |
def build_space(token,t_name,s_type,m_type=None,r_type=None,d_app=None,d_css=None):
|
|
|
|
| 50 |
else:
|
| 51 |
token = token
|
| 52 |
pass
|
| 53 |
+
if r_type != "" or r_type != None:
|
| 54 |
+
m_type=r_type
|
| 55 |
api = HfApi(token=token)
|
| 56 |
repo_name = get_full_repo_name(model_id=model_id, token=token)
|
| 57 |
try:
|
|
|
|
| 177 |
)
|
| 178 |
os.remove(f"{uid}read.txt")
|
| 179 |
|
| 180 |
+
elif s_type == "Auto Image Space":
|
| 181 |
+
with open("auto-image-space.py", "r") as f:
|
| 182 |
+
app = f.read()
|
| 183 |
+
app = app.replace("$name2", m_type)
|
| 184 |
+
app = app.replace("$app2", d_app)
|
| 185 |
+
app = app.replace("$css2", d_css)
|
| 186 |
+
with open(f"{uid}ct.py", "w") as f:
|
| 187 |
+
f.write(app)
|
| 188 |
+
api.upload_file(
|
| 189 |
+
path_or_fileobj=f"{uid}ct.py",
|
| 190 |
+
path_in_repo="app.py",
|
| 191 |
+
repo_id=repo_name,
|
| 192 |
+
token=token,
|
| 193 |
+
repo_type="space",
|
| 194 |
+
)
|
| 195 |
+
os.remove(f"{uid}ct.py")
|
| 196 |
+
with open("css.css", "r") as f:
|
| 197 |
+
app = f.read()
|
| 198 |
+
app.replace("Gray","Yellow")
|
| 199 |
+
with open(f"{uid}css.css", "w") as f:
|
| 200 |
+
f.write(app)
|
| 201 |
+
api.upload_file(
|
| 202 |
+
path_or_fileobj=f"{uid}css.css",
|
| 203 |
+
path_in_repo="css.css",
|
| 204 |
+
repo_id=repo_name,
|
| 205 |
+
token=token,
|
| 206 |
+
repo_type="space",
|
| 207 |
+
)
|
| 208 |
+
os.remove(f"{uid}css.css")
|
| 209 |
+
with open("readme.bac", "r") as f:
|
| 210 |
+
app = f.read()
|
| 211 |
+
with open(f"{uid}read.txt", "w") as f:
|
| 212 |
+
f.write(app)
|
| 213 |
+
api.upload_file(
|
| 214 |
+
path_or_fileobj=f"{uid}read.txt",
|
| 215 |
+
path_in_repo="README.md",
|
| 216 |
+
repo_id=repo_name,
|
| 217 |
+
token=token,
|
| 218 |
+
repo_type="space",
|
| 219 |
+
)
|
| 220 |
+
os.remove(f"{uid}read.txt")
|
| 221 |
|
| 222 |
elif s_type == "R1":
|
| 223 |
with open("r1.py", "r") as f:
|