Rename model name...
Browse files
deploy_to_hf.py
DELETED
|
@@ -1,123 +0,0 @@
|
|
| 1 |
-
#!/usr/bin/env python3
|
| 2 |
-
"""
|
| 3 |
-
Deploy docling-models-onnx to HuggingFace Hub
|
| 4 |
-
"""
|
| 5 |
-
|
| 6 |
-
import os
|
| 7 |
-
import subprocess
|
| 8 |
-
import sys
|
| 9 |
-
from huggingface_hub import HfApi, Repository
|
| 10 |
-
|
| 11 |
-
def run_command(cmd, description):
|
| 12 |
-
"""Run a shell command and return success status"""
|
| 13 |
-
print(f"Running: {description}")
|
| 14 |
-
print(f"Command: {cmd}")
|
| 15 |
-
|
| 16 |
-
try:
|
| 17 |
-
result = subprocess.run(cmd, shell=True, capture_output=True, text=True, cwd=os.getcwd())
|
| 18 |
-
if result.returncode == 0:
|
| 19 |
-
print(f"β Success: {description}")
|
| 20 |
-
if result.stdout:
|
| 21 |
-
print(f"Output: {result.stdout}")
|
| 22 |
-
return True
|
| 23 |
-
else:
|
| 24 |
-
print(f"β Failed: {description}")
|
| 25 |
-
print(f"Error: {result.stderr}")
|
| 26 |
-
return False
|
| 27 |
-
except Exception as e:
|
| 28 |
-
print(f"β Exception in {description}: {e}")
|
| 29 |
-
return False
|
| 30 |
-
|
| 31 |
-
def main():
|
| 32 |
-
# Repository details
|
| 33 |
-
repo_id = "asmud/docling-models-onnx"
|
| 34 |
-
repo_url = f"https://huggingface.co/{repo_id}"
|
| 35 |
-
|
| 36 |
-
print("=" * 60)
|
| 37 |
-
print(f"Deploying to HuggingFace Hub: {repo_id}")
|
| 38 |
-
print("=" * 60)
|
| 39 |
-
|
| 40 |
-
# Step 1: Create repository
|
| 41 |
-
print("\n1. Creating HuggingFace repository...")
|
| 42 |
-
try:
|
| 43 |
-
api = HfApi()
|
| 44 |
-
repo_info = api.create_repo(
|
| 45 |
-
repo_id,
|
| 46 |
-
repo_type="model",
|
| 47 |
-
private=False,
|
| 48 |
-
exist_ok=True
|
| 49 |
-
)
|
| 50 |
-
print(f"β Repository ready: {repo_info.repo_id}")
|
| 51 |
-
print(f" URL: https://huggingface.co/{repo_info.repo_id}")
|
| 52 |
-
except Exception as e:
|
| 53 |
-
print(f"Repository creation result: {e}")
|
| 54 |
-
# Continue anyway - repo might already exist
|
| 55 |
-
|
| 56 |
-
# Step 2: Initialize git repository
|
| 57 |
-
print("\n2. Initializing git repository...")
|
| 58 |
-
if not os.path.exists(".git"):
|
| 59 |
-
run_command("git init", "Initialize git repository")
|
| 60 |
-
else:
|
| 61 |
-
print("β Git repository already initialized")
|
| 62 |
-
|
| 63 |
-
# Step 3: Configure git user
|
| 64 |
-
print("\n3. Configuring git user...")
|
| 65 |
-
run_command('git config user.name "Asep Muhamad"', "Set git user name")
|
| 66 |
-
run_command('git config user.email "asepmuhamad@gmail.com"', "Set git user email")
|
| 67 |
-
|
| 68 |
-
# Step 4: Add remote
|
| 69 |
-
print("\n4. Adding remote...")
|
| 70 |
-
run_command(f"git remote remove origin", "Remove existing origin (if any)") # Ignore errors
|
| 71 |
-
run_command(f"git remote add origin {repo_url}", "Add HuggingFace origin")
|
| 72 |
-
|
| 73 |
-
# Step 5: Setup Git LFS
|
| 74 |
-
print("\n5. Setting up Git LFS...")
|
| 75 |
-
run_command("git lfs track '*.onnx'", "Track ONNX files with LFS")
|
| 76 |
-
|
| 77 |
-
# Step 6: Add all files
|
| 78 |
-
print("\n6. Adding files...")
|
| 79 |
-
run_command("git add .", "Add all files")
|
| 80 |
-
|
| 81 |
-
# Step 7: Commit
|
| 82 |
-
print("\n7. Creating commit...")
|
| 83 |
-
commit_message = '''Initial release: Docling TableFormer ONNX models with JPQD quantization
|
| 84 |
-
|
| 85 |
-
- Add TableFormer Accurate model (~1MB) for high-precision table structure recognition
|
| 86 |
-
- Add TableFormer Fast model (~1MB) for real-time table structure recognition
|
| 87 |
-
- Include comprehensive documentation and usage examples
|
| 88 |
-
- JPQD quantization applied for efficient CPU inference
|
| 89 |
-
- Complete Python implementation with CLI interface
|
| 90 |
-
- Achieves 93.6 TEDS score on table structure recognition benchmarks
|
| 91 |
-
- HuggingFace Hub compatible with proper metadata'''
|
| 92 |
-
|
| 93 |
-
run_command(f'git commit -m "{commit_message}"', "Create initial commit")
|
| 94 |
-
|
| 95 |
-
# Step 8: Push to HuggingFace
|
| 96 |
-
print("\n8. Pushing to HuggingFace Hub...")
|
| 97 |
-
success = run_command("git push -u origin main", "Push to HuggingFace Hub")
|
| 98 |
-
|
| 99 |
-
if success:
|
| 100 |
-
print("\nπ Successfully deployed to HuggingFace Hub!")
|
| 101 |
-
print(f"Repository URL: https://huggingface.co/{repo_id}")
|
| 102 |
-
else:
|
| 103 |
-
print("\nβ οΈ Push failed. Trying to pull and merge...")
|
| 104 |
-
run_command("git pull origin main --allow-unrelated-histories --no-rebase", "Pull remote changes")
|
| 105 |
-
run_command("git push origin main", "Push after merge")
|
| 106 |
-
|
| 107 |
-
print("\nβ
Deployment completed!")
|
| 108 |
-
return True
|
| 109 |
-
|
| 110 |
-
if __name__ == "__main__":
|
| 111 |
-
# Change to script directory
|
| 112 |
-
script_dir = os.path.dirname(os.path.abspath(__file__))
|
| 113 |
-
os.chdir(script_dir)
|
| 114 |
-
print(f"Working directory: {os.getcwd()}")
|
| 115 |
-
|
| 116 |
-
try:
|
| 117 |
-
main()
|
| 118 |
-
except KeyboardInterrupt:
|
| 119 |
-
print("\nβ Deployment cancelled by user")
|
| 120 |
-
sys.exit(1)
|
| 121 |
-
except Exception as e:
|
| 122 |
-
print(f"\nβ Deployment failed: {e}")
|
| 123 |
-
sys.exit(1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
example.py
CHANGED
|
@@ -192,8 +192,8 @@ def main():
|
|
| 192 |
|
| 193 |
# Model paths
|
| 194 |
model_files = {
|
| 195 |
-
"accurate": "
|
| 196 |
-
"fast": "
|
| 197 |
}
|
| 198 |
|
| 199 |
model_path = model_files[args.model]
|
|
|
|
| 192 |
|
| 193 |
# Model paths
|
| 194 |
model_files = {
|
| 195 |
+
"accurate": "tableformer_accurate.onnx",
|
| 196 |
+
"fast": "tableformer_fast.onnx"
|
| 197 |
}
|
| 198 |
|
| 199 |
model_path = model_files[args.model]
|
ds4sd_docling_models_tableformer_accurate_jpqd.onnx β tableformer_accurate.onnx
RENAMED
|
File without changes
|
ds4sd_docling_models_tableformer_fast_jpqd.onnx β tableformer_fast.onnx
RENAMED
|
File without changes
|