Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
9d72863
Add custom model deployment solution for HuggingFace Hub integration
cursoragent Aug 10, 2025
3915103
Update model search path to use designated models directory
cursoragent Aug 10, 2025
4bed501
Add models directory README with .gitignore exception
cursoragent Aug 10, 2025
6723b0c
Check deployed models and upload local model
deepsource-autofix[bot] Aug 10, 2025
295fa3d
Complete HuggingFace deployment solution with multiple strategies
cursoragent Aug 10, 2025
1a8bcc8
Apply HuggingFace deployment best practices and recommendations
cursoragent Aug 10, 2025
b113ab5
Make model deployment script portable across different environments
cursoragent Aug 10, 2025
ac82923
Add test script for portable model path detection
cursoragent Aug 10, 2025
63e5eeb
Fix unused variable linting issue (PYL-W0612)
cursoragent Aug 10, 2025
8bbb12d
Fix unused argument linting issue (PYL-W0613)
cursoragent Aug 10, 2025
ac11c40
Add validation test for model_info usage fix
cursoragent Aug 10, 2025
c0c054b
Comprehensive improvements to upload script robustness and portability
cursoragent Aug 10, 2025
180034e
Add comprehensive improvements summary documentation
cursoragent Aug 10, 2025
412c33a
Resolve merge conflict by keeping improved version
cursoragent Aug 10, 2025
ab0c59a
Check deployed models and upload local model
deepsource-autofix[bot] Aug 10, 2025
fbbb590
Address all code review comments with comprehensive fixes
cursoragent Aug 10, 2025
682cbee
Add comprehensive code review response documentation
cursoragent Aug 10, 2025
ee4748b
Resolve merge conflict - keep all code review fixes and improvements
cursoragent Aug 10, 2025
3f5bd11
Fix unguarded next() calls to resolve PTC-W0063 critical linting issue
cursoragent Aug 10, 2025
2f495c1
Add comprehensive documentation for PTC-W0063 fix
cursoragent Aug 10, 2025
4aa644d
Fix critical security vulnerability BAN-B104: Unsafe binding to all i…
cursoragent Aug 10, 2025
5326521
Add comprehensive documentation for BAN-B104 security fix
cursoragent Aug 10, 2025
ca54ab6
Address all code review comments with comprehensive fixes
cursoragent Aug 10, 2025
7a9436b
SECURITY: Resolve remaining BAN-B104 hardcoded binding string issues
cursoragent Aug 10, 2025
b21a34c
CODE QUALITY: Fix PYL-W0612 unused variable issues using Python best …
cursoragent Aug 10, 2025
521d569
Check deployed models and upload local model
deepsource-autofix[bot] Aug 10, 2025
554d451
Check deployed models and upload local model
deepsource-autofix[bot] Aug 10, 2025
11f320f
Checkpoint before follow-up message
cursoragent Aug 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ data/raw/*
!data/raw/sample_*
deployment/model/
deployment/models/
!deployment/models/README.md
Desktop.ini
develop-eggs/
dist
Expand Down
45 changes: 45 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,4 +281,49 @@ All notable changes to this project will be documented in this file.

---

## [Unreleased] - 2025-08-07

### Added
- **Custom Model Deployment Solution** - Complete pipeline to upload custom-trained models to HuggingFace Hub for production deployment
- Created `scripts/deployment/upload_model_to_huggingface.py` - Comprehensive script to find, prepare, and upload custom trained models
- Added `deployment/CUSTOM_MODEL_DEPLOYMENT_GUIDE.md` - Complete guide for deploying custom models with multiple deployment strategies
- Added `deployment/flexible_api_server.py` - Flexible API server supporting serverless, endpoints, and self-hosted deployments
- **Portable Configuration**: Environment variable support (`SAMO_DL_BASE_DIR` or `MODEL_BASE_DIR`) with automatic project root detection
- Added `deployment/models/` directory with README for organized model storage
- Created `.env.model_config.example` template for easy environment configuration
- **HuggingFace Deployment Strategies**:
- 🆓 Serverless Inference API (free tier with rate limits)
- 🚀 Inference Endpoints (paid, production-grade with consistent latency)
- 🏠 Self-hosted (maximum control with local transformers)
- **Automated Features**:
- Model format conversion (PyTorch .pth to HuggingFace format)
- Git LFS setup for large model files
- Environment configuration templates (.env.serverless, .env.endpoints, .env.selfhosted)
- Deployment configuration updates
- Model card generation with proper metadata and usage examples
- Cold start handling and retry logic for API calls

### Fixed
- **Model-as-a-Service Configuration Issue** - Resolved deployment using untrained base models instead of custom trained models
- Deployment was falling back to base `distilroberta-base` and `bert-base-uncased` models
- Custom models trained in Colab were not accessible to deployment infrastructure
- Now properly uploads custom models to HuggingFace Hub for production access

### Changed
- Deployment infrastructure now supports custom models from HuggingFace Hub instead of local files only
- Updated model loading configuration to use custom emotion labels (12 classes) instead of generic ones

### Technical Details
- **Model Architecture**: DistilRoBERTa/BERT fine-tuned on custom journal entries
- **Emotion Classes**: 12 specialized emotions (anxious, calm, content, excited, frustrated, grateful, happy, hopeful, overwhelmed, proud, sad, tired)
- **Performance**: Expected ~85% accuracy vs ~60% with base models
- **Deployment Options**:
- Serverless API: Free tier, 30s timeout, automatic retry and cold start handling
- Inference Endpoints: Paid service, 10s timeout, no cold starts, consistent latency
- Self-hosted: Local transformers, full control, configurable device (CPU/GPU)
- **Storage**: Uses HuggingFace Hub as model repository with Git LFS for large files
- **Cost Structure**: Public repos free, private repos with quotas, bandwidth tracking

---
Comment on lines +284 to +327

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Avoid duplicate “Unreleased” sections; consolidate or cut a release entry

There is already an “Unreleased - 2025-08-07” earlier (Line 5). Create one Unreleased section, or turn this new block into a dated release to maintain Keep a Changelog structure.

Option A (recommended): merge bullets into the top Unreleased section and remove this header.

Option B: cut a release. Example diff (adjust version as appropriate):

-## [Unreleased] - 2025-08-07
+## [1.2.0] - 2025-08-07

Minor wording nit (optional):

-  - Custom models trained in Colab were not accessible to deployment infrastructure
+  - Custom models trained in Colab were inaccessible to the deployment infrastructure

🏁 Script executed:

#!/bin/bash
# Search for Unreleased sections in CHANGELOG.md
rg -n "## \\[Unreleased" CHANGELOG.md
# Search for exact “Unreleased - 2025-08-07” occurrences
rg -n "Unreleased - 2025-08-07" CHANGELOG.md

Length of output: 149


Consolidate duplicate “Unreleased” sections in CHANGELOG.md

There are two ## [Unreleased] - 2025-08-07 headers (lines 5 and 284). Per Keep a Changelog, only one Unreleased section is allowed. Please choose one of the following fixes:

  • Merge the bullets under the second header (line 284) into the first Unreleased section (line 5) and remove the duplicate header.
  • Or convert the second Unreleased header into a proper release entry. For example:
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -284,7 +284,7 @@
-## [Unreleased] - 2025-08-07
+## [1.2.0] - 2025-08-07

Minor wording nit (optional):

-  - Custom models trained in Colab were not accessible to deployment infrastructure
+  - Custom models trained in Colab were inaccessible to the deployment infrastructure
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
## [Unreleased] - 2025-08-07
### Added
- **Custom Model Deployment Solution** - Complete pipeline to upload custom-trained models to HuggingFace Hub for production deployment
- Created `scripts/deployment/upload_model_to_huggingface.py` - Comprehensive script to find, prepare, and upload custom trained models
- Added `deployment/CUSTOM_MODEL_DEPLOYMENT_GUIDE.md` - Complete guide for deploying custom models with multiple deployment strategies
- Added `deployment/flexible_api_server.py` - Flexible API server supporting serverless, endpoints, and self-hosted deployments
- **Portable Configuration**: Environment variable support (`SAMO_DL_BASE_DIR` or `MODEL_BASE_DIR`) with automatic project root detection
- Added `deployment/models/` directory with README for organized model storage
- Created `.env.model_config.example` template for easy environment configuration
- **HuggingFace Deployment Strategies**:
- 🆓 Serverless Inference API (free tier with rate limits)
- 🚀 Inference Endpoints (paid, production-grade with consistent latency)
- 🏠 Self-hosted (maximum control with local transformers)
- **Automated Features**:
- Model format conversion (PyTorch .pth to HuggingFace format)
- Git LFS setup for large model files
- Environment configuration templates (.env.serverless, .env.endpoints, .env.selfhosted)
- Deployment configuration updates
- Model card generation with proper metadata and usage examples
- Cold start handling and retry logic for API calls
### Fixed
- **Model-as-a-Service Configuration Issue** - Resolved deployment using untrained base models instead of custom trained models
- Deployment was falling back to base `distilroberta-base` and `bert-base-uncased` models
- Custom models trained in Colab were not accessible to deployment infrastructure
- Now properly uploads custom models to HuggingFace Hub for production access
### Changed
- Deployment infrastructure now supports custom models from HuggingFace Hub instead of local files only
- Updated model loading configuration to use custom emotion labels (12 classes) instead of generic ones
### Technical Details
- **Model Architecture**: DistilRoBERTa/BERT fine-tuned on custom journal entries
- **Emotion Classes**: 12 specialized emotions (anxious, calm, content, excited, frustrated, grateful, happy, hopeful, overwhelmed, proud, sad, tired)
- **Performance**: Expected ~85% accuracy vs ~60% with base models
- **Deployment Options**:
- Serverless API: Free tier, 30s timeout, automatic retry and cold start handling
- Inference Endpoints: Paid service, 10s timeout, no cold starts, consistent latency
- Self-hosted: Local transformers, full control, configurable device (CPU/GPU)
- **Storage**: Uses HuggingFace Hub as model repository with Git LFS for large files
- **Cost Structure**: Public repos free, private repos with quotas, bandwidth tracking
---
## [1.2.0] - 2025-08-07
### Added
- **Custom Model Deployment Solution** - Complete pipeline to upload custom-trained models to HuggingFace Hub for production deployment
- Created `scripts/deployment/upload_model_to_huggingface.py` - Comprehensive script to find, prepare, and upload custom trained models
- Added `deployment/CUSTOM_MODEL_DEPLOYMENT_GUIDE.md` - Complete guide for deploying custom models with multiple deployment strategies
- Added `deployment/flexible_api_server.py` - Flexible API server supporting serverless, endpoints, and self-hosted deployments
- **Portable Configuration**: Environment variable support (`SAMO_DL_BASE_DIR` or `MODEL_BASE_DIR`) with automatic project root detection
- Added `deployment/models/` directory with README for organized model storage
- Created `.env.model_config.example` template for easy environment configuration
- **HuggingFace Deployment Strategies**:
- 🆓 Serverless Inference API (free tier with rate limits)
- 🚀 Inference Endpoints (paid, production-grade with consistent latency)
- 🏠 Self-hosted (maximum control with local transformers)
- **Automated Features**:
- Model format conversion (PyTorch .pth to HuggingFace format)
- Git LFS setup for large model files
- Environment configuration templates (.env.serverless, .env.endpoints, .env.selfhosted)
- Deployment configuration updates
- Model card generation with proper metadata and usage examples
- Cold start handling and retry logic for API calls
### Fixed
- **Model-as-a-Service Configuration Issue** - Resolved deployment using untrained base models instead of custom trained models
- Deployment was falling back to base `distilroberta-base` and `bert-base-uncased` models
- Custom models trained in Colab were inaccessible to the deployment infrastructure
- Now properly uploads custom models to HuggingFace Hub for production access
### Changed
- Deployment infrastructure now supports custom models from HuggingFace Hub instead of local files only
- Updated model loading configuration to use custom emotion labels (12 classes) instead of generic ones
### Technical Details
- **Model Architecture**: DistilRoBERTa/BERT fine-tuned on custom journal entries
- **Emotion Classes**: 12 specialized emotions (anxious, calm, content, excited, frustrated, grateful, happy, hopeful, overwhelmed, proud, sad, tired)
- **Performance**: Expected ~85% accuracy vs ~60% with base models
- **Deployment Options**:
- Serverless API: Free tier, 30s timeout, automatic retry and cold start handling
- Inference Endpoints: Paid service, 10s timeout, no cold starts, consistent latency
- Self-hosted: Local transformers, full control, configurable device (CPU/GPU)
- **Storage**: Uses HuggingFace Hub as model repository with Git LFS for large files
- **Cost Structure**: Public repos free, private repos with quotas, bandwidth tracking
---
🧰 Tools
🪛 LanguageTool

[style] ~309-~309: Consider using “inaccessible” to avoid wordiness.
Context: ... - Custom models trained in Colab were not accessible to deployment infrastructure - Now pr...

(NOT_ABLE_PREMIUM)

🤖 Prompt for AI Agents
In CHANGELOG.md around lines 284 to 327, there is a duplicate "## [Unreleased] -
2025-08-07" header which violates the Keep a Changelog format. To fix this,
merge all the bullet points and content under the second Unreleased header into
the first Unreleased section near line 5, then remove the duplicate header and
its line. Alternatively, convert the second Unreleased header into a proper
release entry with a version number and date. Ensure only one Unreleased section
remains in the file.


*This changelog follows the [Keep a Changelog](https://keepachangelog.com/) format and adheres to [Semantic Versioning](https://semver.org/).*
119 changes: 119 additions & 0 deletions deployment/.env.flask.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# Flask Security Configuration Template
# Copy this to .env and customize for your deployment environment

# =============================================================================
# 🔒 SECURITY CONFIGURATION
# =============================================================================

# Flask Host Binding (SECURITY CRITICAL!)
#
# DEVELOPMENT (RECOMMENDED):
FLASK_HOST=127.0.0.1
# ✅ SECURE: Only accepts connections from localhost
# ✅ SAFE: Cannot be accessed from external networks
# ✅ IDEAL: For development, testing, and local deployment
#
# PRODUCTION (USE WITH CAUTION):
# FLASK_HOST=0.0.0.0
# ⚠️ EXPOSED: Accepts connections from all interfaces
# ⚠️ RISK: Can be accessed from external networks
# ⚠️ REQUIRES: Proper firewall, reverse proxy, and security measures
#
# CUSTOM (ADVANCED):
# FLASK_HOST=192.168.1.100
# 🔧 SPECIFIC: Binds to a specific network interface
# 🔧 USE CASE: When you need access from specific networks only

# Flask Port
FLASK_PORT=5000
# Default: 5000
# Change if port conflicts or you need a different port

# Flask Debug Mode (SECURITY CRITICAL!)
FLASK_DEBUG=False
# ✅ SECURE: Debug disabled (production default)
# ⚠️ DANGER: Never set to True in production!
# Debug mode exposes sensitive information and allows code execution

# =============================================================================
# 🚀 DEPLOYMENT ENVIRONMENT EXAMPLES
# =============================================================================

# LOCAL DEVELOPMENT (Most Common):
# FLASK_HOST=127.0.0.1
# FLASK_PORT=5000
# FLASK_DEBUG=False

# DOCKER CONTAINER (For external access):
# FLASK_HOST=0.0.0.0 # Required for Docker port mapping
# FLASK_PORT=5000
# FLASK_DEBUG=False
# Note: Container should be behind reverse proxy/load balancer

# PRODUCTION CLOUD (Behind Load Balancer):
# FLASK_HOST=0.0.0.0 # Load balancer handles security
# FLASK_PORT=8080 # Non-standard port
# FLASK_DEBUG=False # Never True in production!

# KUBERNETES DEPLOYMENT:
# FLASK_HOST=0.0.0.0 # Pod networking requires this
# FLASK_PORT=5000
# FLASK_DEBUG=False
# Note: Use NetworkPolicies and Ingress for security

# =============================================================================
# 🛡️ SECURITY BEST PRACTICES
# =============================================================================

# 1. DEVELOPMENT:
# - Always use 127.0.0.1 (default)
# - Keep debug=False unless actively debugging
# - Test with realistic data, not production data

# 2. STAGING/TESTING:
# - Use 127.0.0.1 or specific internal IPs
# - Never expose staging to public internet
# - Use VPN or internal networks for access

# 3. PRODUCTION:
# - Use 0.0.0.0 ONLY behind reverse proxy (nginx, Apache, etc.)
# - Always debug=False
# - Implement proper authentication and authorization
# - Use HTTPS with valid certificates
# - Set up monitoring and alerting
# - Regular security audits

# 4. CONTAINERIZATION:
# - Container: FLASK_HOST=0.0.0.0 (for port mapping)
# - Host: Bind only to localhost or internal networks
# - Use container orchestration security features
# - Network segmentation and policies

# =============================================================================
# 🔍 SECURITY CHECKLIST
# =============================================================================
# □ Reviewed host binding setting
# □ Confirmed debug mode is disabled for production
# □ Implemented proper authentication if exposing externally
# □ Set up reverse proxy/load balancer for external access
# □ Configured firewall rules
# □ Enabled HTTPS/TLS encryption
# □ Set up monitoring and logging
# □ Tested security configuration
# □ Documented deployment security model

# =============================================================================
# 📊 MODEL DEPLOYMENT CONFIGURATION (Optional)
# =============================================================================

# HuggingFace Deployment Strategy
DEPLOYMENT_TYPE=local
# Options: serverless, endpoint, local

# Model Configuration
MODEL_NAME=your-username/samo-dl-emotion-model
HF_TOKEN=your_hf_token_here

# Model Processing Settings
MAX_LENGTH=128
BATCH_SIZE=32
Loading