Tu Nombre commited on
Commit
462f225
·
1 Parent(s): 8df3a7c

fix: commit api para subir archivos

Browse files
Files changed (1) hide show
  1. main.py +16 -11
main.py CHANGED
@@ -226,17 +226,22 @@ demo.launch()
226
  print(f"Error repo: {r.text}")
227
  return None
228
 
229
- # Subir main.py
230
- await client.put(
231
- f"https://huggingface.co/api/spaces/{repo_id}/upload/main/main.py",
232
- headers={"Authorization": f"Bearer {HF_TOKEN}"},
233
- content=main_code.encode())
234
-
235
- # Subir requirements.txt
236
- await client.put(
237
- f"https://huggingface.co/api/spaces/{repo_id}/upload/main/requirements.txt",
238
- headers={"Authorization": f"Bearer {HF_TOKEN}"},
239
- content=req.encode())
 
 
 
 
 
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 = {