Spaces:
Running
Running
Tu Nombre commited on
Commit ·
65b5f03
1
Parent(s): 8e92d08
fix: usar raw api para subir archivos
Browse files
main.py
CHANGED
|
@@ -226,26 +226,15 @@ demo.launch()
|
|
| 226 |
print(f"Error repo: {r.text}")
|
| 227 |
return None
|
| 228 |
|
| 229 |
-
# Subir archivos via
|
| 230 |
-
import base64
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
]
|
| 239 |
-
}
|
| 240 |
-
r2 = await client.post(
|
| 241 |
-
f"https://huggingface.co/api/spaces/{repo_id}/commit/main",
|
| 242 |
-
headers={"Authorization": f"Bearer {HF_TOKEN}", "Content-Type": "application/json"},
|
| 243 |
-
content=_json.dumps(commit_payload).encode()
|
| 244 |
-
)
|
| 245 |
-
print(f"Commit: {r2.status_code} {r2.text[:300]}")
|
| 246 |
-
if r2.status_code != 200:
|
| 247 |
-
print(f"Payload keys: {list(commit_payload.keys())}")
|
| 248 |
-
print(f"main_code len: {len(main_code)}")
|
| 249 |
|
| 250 |
# Agregar secretos al Space del cliente
|
| 251 |
secretos = {
|
|
|
|
| 226 |
print(f"Error repo: {r.text}")
|
| 227 |
return None
|
| 228 |
|
| 229 |
+
# Subir archivos via upload API
|
| 230 |
+
import base64
|
| 231 |
+
for fname, fcontent in [("main.py", main_code), ("requirements.txt", req)]:
|
| 232 |
+
r2 = await client.put(
|
| 233 |
+
f"https://huggingface.co/api/spaces/{repo_id}/raw/main/{fname}",
|
| 234 |
+
headers={"Authorization": f"Bearer {HF_TOKEN}", "Content-Type": "text/plain; charset=utf-8"},
|
| 235 |
+
content=fcontent.encode("utf-8")
|
| 236 |
+
)
|
| 237 |
+
print(f"Upload {fname}: {r2.status_code} {r2.text[:100]}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 238 |
|
| 239 |
# Agregar secretos al Space del cliente
|
| 240 |
secretos = {
|