Tu Nombre commited on
Commit
ef4173d
·
1 Parent(s): 65b5f03

fix: commit api formato correcto

Browse files
Files changed (1) hide show
  1. main.py +16 -9
main.py CHANGED
@@ -226,15 +226,22 @@ demo.launch()
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 = {
 
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("utf-8")).decode("utf-8")
232
+ commit_payload = {
233
+ "summary": "TubeBot init",
234
+ "files": [
235
+ {"path": "main.py", "content": b64(main_code), "encoding": "base64"},
236
+ {"path": "requirements.txt", "content": b64(req), "encoding": "base64"}
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[:200]}")
245
 
246
  # Agregar secretos al Space del cliente
247
  secretos = {