bentosmau commited on
Commit ·
3b28ac9
1
Parent(s): 09c56c4
Add functionality to create and upload model files to Hugging Face
Browse filesUpdate `publicar_hf.py` to include `create_repo` and `upload_folder` with `create_pr=True` for handling potential permission issues when uploading to Hugging Face model repositories.
Replit-Commit-Author: Agent
Replit-Commit-Session-Id: e3ff2484-bbd8-4aba-bea0-1940769b874a
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Event-Id: 3746c07e-9b50-4074-9269-f0d57c0f754c
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1739408b-93a5-479b-a658-30f2493b0467/e3ff2484-bbd8-4aba-bea0-1940769b874a/17Q9XjF
Replit-Helium-Checkpoint-Created: true
- chat-app/publicar_hf.py +39 -13
chat-app/publicar_hf.py
CHANGED
|
@@ -1,19 +1,45 @@
|
|
| 1 |
import os
|
| 2 |
-
from huggingface_hub import login, upload_folder
|
| 3 |
|
| 4 |
HF_TOKEN = os.environ.get("HF_TOKEN")
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
else:
|
| 9 |
-
login()
|
| 10 |
|
| 11 |
-
|
| 12 |
-
folder_path=".",
|
| 13 |
-
repo_id="mauriminuano125-a11y/mdfjbots-neo-1",
|
| 14 |
-
repo_type="model",
|
| 15 |
-
ignore_patterns=["*.pyc", "__pycache__", ".env"],
|
| 16 |
-
)
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
+
from huggingface_hub import login, upload_folder, create_repo, HfApi
|
| 3 |
|
| 4 |
HF_TOKEN = os.environ.get("HF_TOKEN")
|
| 5 |
|
| 6 |
+
print("🔐 Iniciando sesión en Hugging Face...")
|
| 7 |
+
login(token=HF_TOKEN)
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
api = HfApi()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
+
REPO_ID = "mauriminuano125-a11y/mdfjbots-neo-1"
|
| 12 |
+
|
| 13 |
+
print(f"📦 Creando/verificando repositorio: {REPO_ID}")
|
| 14 |
+
try:
|
| 15 |
+
create_repo(
|
| 16 |
+
repo_id=REPO_ID,
|
| 17 |
+
repo_type="model",
|
| 18 |
+
exist_ok=True,
|
| 19 |
+
token=HF_TOKEN,
|
| 20 |
+
private=False,
|
| 21 |
+
)
|
| 22 |
+
print("✅ Repositorio listo.")
|
| 23 |
+
except Exception as e:
|
| 24 |
+
print(f"⚠️ Aviso: {e}")
|
| 25 |
+
|
| 26 |
+
print("⬆️ Subiendo archivos (vía Pull Request)...")
|
| 27 |
+
try:
|
| 28 |
+
url = upload_folder(
|
| 29 |
+
folder_path=".",
|
| 30 |
+
repo_id=REPO_ID,
|
| 31 |
+
repo_type="model",
|
| 32 |
+
token=HF_TOKEN,
|
| 33 |
+
ignore_patterns=["*.pyc", "__pycache__", ".env", "publicar_hf.py"],
|
| 34 |
+
create_pr=True,
|
| 35 |
+
)
|
| 36 |
+
print("")
|
| 37 |
+
print("✅ ¡Archivos subidos exitosamente como Pull Request!")
|
| 38 |
+
print(f"🔗 Revisa tu repositorio: https://huggingface.co/{REPO_ID}")
|
| 39 |
+
print(f"🔗 URL del PR: {url}")
|
| 40 |
+
except Exception as e:
|
| 41 |
+
print(f"❌ Error: {e}")
|
| 42 |
+
print("")
|
| 43 |
+
print("💡 Asegúrate de que tu token tenga permiso 'write'.")
|
| 44 |
+
print(" Ve a: https://huggingface.co/settings/tokens")
|
| 45 |
+
print(" Crea un nuevo token con tipo 'Write'")
|