Spaces:
Running
Running
Tu Nombre commited on
Commit ·
898104f
1
Parent(s): 1718337
subir archivos cliente uno a uno
Browse files
main.py
CHANGED
|
@@ -167,22 +167,14 @@ RUN pip install -r requirements.txt
|
|
| 167 |
COPY main.py .
|
| 168 |
EXPOSE 7860
|
| 169 |
CMD [\"uvicorn\", \"main:app\", \"--host\", \"0.0.0.0\", \"--port\", \"7860\"]"""
|
| 170 |
-
files_lista = [
|
| 171 |
-
{"path": "main.py", "content": b64(main_code), "encoding": "base64"},
|
| 172 |
-
{"path": "requirements.txt", "content": b64(req), "encoding": "base64"},
|
| 173 |
-
{"path": "README.md", "content": b64(readme), "encoding": "base64"},
|
| 174 |
-
{"path": "Dockerfile", "content": b64(dockerfile), "encoding": "base64"}
|
| 175 |
-
]
|
| 176 |
-
# Añadir archivos del cliente si los subió
|
| 177 |
-
if archivos_subidos:
|
| 178 |
-
for i, arc in enumerate(archivos_subidos[:20]):
|
| 179 |
-
nombre = arc.get("nombre", f"media_{i}.jpg").replace("/","_").replace("\\","_")
|
| 180 |
-
contenido = arc.get("contenido", "")
|
| 181 |
-
if contenido:
|
| 182 |
-
files_lista.append({"path": f"media_cliente/{nombre}", "content": contenido, "encoding": "base64"})
|
| 183 |
commit_payload = {
|
| 184 |
"summary": "TubeBot init",
|
| 185 |
-
"files":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 186 |
}
|
| 187 |
r2 = await client.post(
|
| 188 |
f"https://huggingface.co/api/spaces/{repo_name}/commit/main",
|
|
@@ -190,6 +182,22 @@ CMD [\"uvicorn\", \"main:app\", \"--host\", \"0.0.0.0\", \"--port\", \"7860\"]""
|
|
| 190 |
content=_json.dumps(commit_payload).encode()
|
| 191 |
)
|
| 192 |
print(f"Commit: {r2.status_code} {r2.text[:200]}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 193 |
|
| 194 |
# Agregar secretos al Space del cliente
|
| 195 |
secretos = {
|
|
|
|
| 167 |
COPY main.py .
|
| 168 |
EXPOSE 7860
|
| 169 |
CMD [\"uvicorn\", \"main:app\", \"--host\", \"0.0.0.0\", \"--port\", \"7860\"]"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 170 |
commit_payload = {
|
| 171 |
"summary": "TubeBot init",
|
| 172 |
+
"files": [
|
| 173 |
+
{"path": "main.py", "content": b64(main_code), "encoding": "base64"},
|
| 174 |
+
{"path": "requirements.txt", "content": b64(req), "encoding": "base64"},
|
| 175 |
+
{"path": "README.md", "content": b64(readme), "encoding": "base64"},
|
| 176 |
+
{"path": "Dockerfile", "content": b64(dockerfile), "encoding": "base64"}
|
| 177 |
+
]
|
| 178 |
}
|
| 179 |
r2 = await client.post(
|
| 180 |
f"https://huggingface.co/api/spaces/{repo_name}/commit/main",
|
|
|
|
| 182 |
content=_json.dumps(commit_payload).encode()
|
| 183 |
)
|
| 184 |
print(f"Commit: {r2.status_code} {r2.text[:200]}")
|
| 185 |
+
# Subir archivos del cliente uno a uno (evita problema de binarios)
|
| 186 |
+
if archivos_subidos:
|
| 187 |
+
for i, arc in enumerate(archivos_subidos[:20]):
|
| 188 |
+
try:
|
| 189 |
+
nombre = arc.get("nombre", f"media_{i}.jpg").replace("/","_").replace("\\","_")
|
| 190 |
+
contenido_b64 = arc.get("contenido", "")
|
| 191 |
+
if not contenido_b64: continue
|
| 192 |
+
binario = base64.b64decode(contenido_b64)
|
| 193 |
+
r_up = await client.put(
|
| 194 |
+
f"https://huggingface.co/api/repos/{repo_name}/upload/main/media_cliente/{nombre}",
|
| 195 |
+
headers={"Authorization": f"Bearer {token_actual}", "Content-Type": "application/octet-stream"},
|
| 196 |
+
content=binario
|
| 197 |
+
)
|
| 198 |
+
print(f"Upload {nombre}: {r_up.status_code}", flush=True)
|
| 199 |
+
except Exception as e:
|
| 200 |
+
print(f"Error upload {arc.get('nombre','?')}: {e}", flush=True)
|
| 201 |
|
| 202 |
# Agregar secretos al Space del cliente
|
| 203 |
secretos = {
|