|
|
|
|
|
"""
|
|
|
Simple upload script for ISNet model to Hugging Face Hub
|
|
|
"""
|
|
|
import os
|
|
|
from huggingface_hub import HfApi, login
|
|
|
|
|
|
def upload_to_huggingface(repo_name, upload_dir):
|
|
|
"""Upload the model to Hugging Face Hub"""
|
|
|
|
|
|
|
|
|
print("Please enter your Hugging Face token:")
|
|
|
token = input().strip()
|
|
|
login(token)
|
|
|
|
|
|
api = HfApi()
|
|
|
|
|
|
|
|
|
print(f"Creating repository: {repo_name}")
|
|
|
api.create_repo(repo_name, exist_ok=True)
|
|
|
|
|
|
|
|
|
print("Uploading model files...")
|
|
|
for root, dirs, files in os.walk(upload_dir):
|
|
|
for file in files:
|
|
|
file_path = os.path.join(root, file)
|
|
|
relative_path = os.path.relpath(file_path, upload_dir)
|
|
|
|
|
|
with open(file_path, "rb") as f:
|
|
|
api.upload_file(
|
|
|
path_or_fileobj=f,
|
|
|
path_in_repo=relative_path,
|
|
|
repo_id=repo_name
|
|
|
)
|
|
|
print(f"β
Uploaded: {relative_path}")
|
|
|
|
|
|
print(f"π Model successfully uploaded to: https://huggingface.co/{repo_name}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
print("π Uploading ISNet model to Hugging Face...")
|
|
|
|
|
|
|
|
|
upload_dir = "model_for_upload"
|
|
|
if not os.path.exists(upload_dir):
|
|
|
print(f"β Upload directory {upload_dir} not found!")
|
|
|
exit(1)
|
|
|
|
|
|
|
|
|
print(f"π Files to upload from {upload_dir}:")
|
|
|
for root, dirs, files in os.walk(upload_dir):
|
|
|
for file in files:
|
|
|
file_path = os.path.join(root, file)
|
|
|
relative_path = os.path.relpath(file_path, upload_dir)
|
|
|
print(f" - {relative_path}")
|
|
|
|
|
|
|
|
|
print("\nEnter your Hugging Face username:")
|
|
|
username = input().strip()
|
|
|
repo_name = f"{username}/isnet-background-remover"
|
|
|
|
|
|
|
|
|
upload_to_huggingface(repo_name, upload_dir)
|
|
|
|
|
|
print(f"\nπ― After upload, users can download your model with:")
|
|
|
print(f"from transformers import AutoModelForImageSegmentation")
|
|
|
print(f"model = AutoModelForImageSegmentation.from_pretrained('{repo_name}', trust_remote_code=True)") |