Spaces:
Running
Running
Tu Nombre commited on
Commit ·
462f225
1
Parent(s): 8df3a7c
fix: commit api para subir archivos
Browse files
main.py
CHANGED
|
@@ -226,17 +226,22 @@ demo.launch()
|
|
| 226 |
print(f"Error repo: {r.text}")
|
| 227 |
return None
|
| 228 |
|
| 229 |
-
# Subir
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 240 |
|
| 241 |
# Agregar secretos al Space del cliente
|
| 242 |
secretos = {
|
|
|
|
| 226 |
print(f"Error repo: {r.text}")
|
| 227 |
return None
|
| 228 |
|
| 229 |
+
# Subir archivos via commit API
|
| 230 |
+
import base64, json as _json
|
| 231 |
+
def b64(s): return base64.b64encode(s.encode()).decode()
|
| 232 |
+
commit_payload = {
|
| 233 |
+
"commit_message": "TubeBot init",
|
| 234 |
+
"operations": [
|
| 235 |
+
{"operation": "addOrUpdate", "path": "main.py", "content": b64(main_code)},
|
| 236 |
+
{"operation": "addOrUpdate", "path": "requirements.txt", "content": b64(req)}
|
| 237 |
+
]
|
| 238 |
+
}
|
| 239 |
+
r2 = await client.post(
|
| 240 |
+
f"https://huggingface.co/api/spaces/{repo_id}/commit/main",
|
| 241 |
+
headers={"Authorization": f"Bearer {HF_TOKEN}", "Content-Type": "application/json"},
|
| 242 |
+
content=_json.dumps(commit_payload).encode()
|
| 243 |
+
)
|
| 244 |
+
print(f"Commit: {r2.status_code} {r2.text[:100]}")
|
| 245 |
|
| 246 |
# Agregar secretos al Space del cliente
|
| 247 |
secretos = {
|