Spaces:
Sleeping
Sleeping
| import os | |
| from pathlib import Path | |
| from huggingface_hub import HfApi, create_repo | |
| from huggingface_hub.utils import RepositoryNotFoundError | |
| def deploy_to_huggingface_space(): | |
| SPACE_NAME = "Predictive-Maintenance" | |
| REPO_ID = f"shashidj/{SPACE_NAME}" | |
| print("π Starting deployment to HuggingFace Spaces...") | |
| print(f"π¦ Target Space: {REPO_ID}") | |
| api = HfApi(token=os.getenv("HF_TOKEN")) | |
| try: | |
| api.repo_info(repo_id=REPO_ID, repo_type="space") | |
| print(f"π Space '{REPO_ID}' already exists") | |
| except RepositoryNotFoundError: | |
| print(f"π Creating new space '{REPO_ID}'...") | |
| create_repo(repo_id=REPO_ID, repo_type="space", space_sdk="docker", private=False) | |
| print("β Space created successfully") | |
| deployment_dir = Path("predictive_maintenance_mlops/deployment") | |
| required_files = ["Dockerfile", "app.py", "requirements.txt"] | |
| print("\nπ Verifying deployment files...") | |
| for file_name in required_files: | |
| if (deployment_dir / file_name).exists(): | |
| print(f"β {file_name} found") | |
| else: | |
| print(f"β {file_name} missing") | |
| return False | |
| readme_content = """--- | |
| title: Predictive Maintenance | |
| emoji: π§ | |
| colorFrom: red | |
| colorTo: gray | |
| sdk: docker | |
| app_port: 7860 | |
| app_file: app.py | |
| pinned: false | |
| license: mit | |
| --- | |
| # Predictive Maintenance β Engine Health Monitor π§ | |
| An intelligent ML-powered system that monitors engine sensor data and predicts failure risk in real time. | |
| ## Features | |
| - **Real-time Predictions**: Instant engine health scoring | |
| - **Interactive Interface**: User-friendly Streamlit web application | |
| - **Multiple Algorithms**: Best model selected from 6 different algorithms | |
| - **MLOps Integration**: Complete pipeline with experiment tracking | |
| ## Technical Stack | |
| - **Backend**: Python, Scikit-learn, XGBoost | |
| - **Frontend**: Streamlit | |
| - **ML Tracking**: MLflow | |
| - **Deployment**: Docker, HuggingFace Spaces | |
| """ | |
| (deployment_dir / "README.md").write_text(readme_content) | |
| print("β README.md created") | |
| print("\nπ€ Uploading files to HuggingFace Space...") | |
| api.upload_folder( | |
| folder_path=str(deployment_dir), | |
| repo_id=REPO_ID, | |
| repo_type="space", | |
| commit_message="Deploy Predictive Maintenance application" | |
| ) | |
| print(f"\nπ Deployment completed!") | |
| print(f"π https://huggingface.co/spaces/{REPO_ID}") | |
| return True | |
| if __name__ == "__main__": | |
| if not os.getenv("HF_TOKEN"): | |
| print("β HF_TOKEN environment variable not set!") | |
| else: | |
| deploy_to_huggingface_space() | |