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

fix: usar raw api para subir archivos

Browse files
Files changed (1) hide show
  1. main.py +9 -20
main.py CHANGED
@@ -226,26 +226,15 @@ demo.launch()
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
- "commit_message": "TubeBot init",
234
- "summary": "TubeBot init",
235
- "operations": [
236
- {"operation": "addOrUpdate", "path": "main.py", "content": b64(main_code)},
237
- {"operation": "addOrUpdate", "path": "requirements.txt", "content": b64(req)}
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 = {