Spaces:
Sleeping
Sleeping
| import os | |
| import shutil | |
| from huggingface_hub import HfApi, Repository | |
| import joblib | |
| # Script to upload your models to HuggingFace Model Hub | |
| def upload_sbert_model(): | |
| """Upload your fine-tuned SBERT model to HuggingFace""" | |
| # Your local model path | |
| local_model_path = "C:\\Users\\TUF_F15\\Downloads\\ANS-master (1)\\ANS-master\\server\\models\\fine_tuned_sbert" | |
| # HuggingFace model repository name (change to your username) | |
| repo_name = "your-username/po-validator-sbert" | |
| # Initialize HuggingFace API | |
| api = HfApi() | |
| # Create repository | |
| try: | |
| api.create_repo(repo_name, exist_ok=True) | |
| print(f"Repository {repo_name} created/exists") | |
| except Exception as e: | |
| print(f"Error creating repository: {e}") | |
| return | |
| # Upload model files | |
| try: | |
| api.upload_folder( | |
| folder_path=local_model_path, | |
| repo_id=repo_name, | |
| commit_message="Upload fine-tuned SBERT model for PO validation" | |
| ) | |
| print(f"SBERT model uploaded successfully to {repo_name}") | |
| except Exception as e: | |
| print(f"Error uploading SBERT model: {e}") | |
| def upload_xgboost_model(): | |
| """Upload your XGBoost model to HuggingFace""" | |
| # Your local model path | |
| local_model_path = "C:\\Users\\TUF_F15\\Downloads\\ANS-master (1)\\ANS-master\\server\\models\\po_risk_xgb_model.pkl" | |
| # HuggingFace model repository name | |
| repo_name = "your-username/po-validator-xgboost" | |
| # Initialize HuggingFace API | |
| api = HfApi() | |
| # Create repository | |
| try: | |
| api.create_repo(repo_name, exist_ok=True) | |
| print(f"Repository {repo_name} created/exists") | |
| except Exception as e: | |
| print(f"Error creating repository: {e}") | |
| return | |
| # Upload model file | |
| try: | |
| api.upload_file( | |
| path_or_fileobj=local_model_path, | |
| path_in_repo="po_risk_xgb_model.pkl", | |
| repo_id=repo_name, | |
| commit_message="Upload XGBoost model for PO risk prediction" | |
| ) | |
| print(f"XGBoost model uploaded successfully to {repo_name}") | |
| except Exception as e: | |
| print(f"Error uploading XGBoost model: {e}") | |
| def create_model_card(): | |
| """Create a model card for your models""" | |
| model_card_content = """--- | |
| language: en | |
| license: mit | |
| tags: | |
| - sentence-transformers | |
| - sentence-similarity | |
| - feature-extraction | |
| - purchase-order | |
| - risk-assessment | |
| pipeline_tag: sentence-similarity | |
| --- | |
| # PO Validator SBERT Model | |
| This is a fine-tuned Sentence-BERT model for Purchase Order validation and risk assessment. | |
| ## Model Description | |
| The model is trained to understand product descriptions and match them with SKU databases for purchase order validation. It's part of a larger system that includes XGBoost for risk prediction. | |
| ## Usage | |
| ```python | |
| from sentence_transformers import SentenceTransformer | |
| model = SentenceTransformer('your-username/po-validator-sbert') | |
| embeddings = model.encode(['Product description here']) | |
| ``` | |
| ## Training Data | |
| The model was fine-tuned on purchase order data containing product descriptions and their corresponding SKU mappings. | |
| ## Performance | |
| The model achieves high accuracy in semantic matching of product descriptions to SKU codes, enabling automated purchase order validation. | |
| """ | |
| with open("model_card.md", "w") as f: | |
| f.write(model_card_content) | |
| print("Model card created: model_card.md") | |
| if __name__ == "__main__": | |
| print("HuggingFace Model Upload Script") | |
| print("Make sure you have huggingface_hub installed and are logged in") | |
| print("Run: pip install huggingface_hub") | |
| print("Run: huggingface-cli login") | |
| # Uncomment the functions you want to run: | |
| # upload_sbert_model() | |
| # upload_xgboost_model() | |
| create_model_card() | |