-
Notifications
You must be signed in to change notification settings - Fork 0
feat/dl: Add comprehensive demo page with DeBERTa v3 Large integration #168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
20d6f6d
1303b33
fbb89c8
e942bf6
171986a
3703f4b
e6e4825
baa5406
f621bab
18fb267
21d2984
dc93823
c4e5a68
3c269b4
6b205f5
93a4e06
9abddde
0eeb1f9
42ea6d6
2f49c70
32338e5
81229a8
b3e3e6e
c718b1f
849b13d
2657288
5743646
cd9a5f3
f3b58cf
6c37cba
fd2d3c6
8a34e72
4ae6eb9
984c6c9
e2f5e09
be8326d
da760dd
809b901
1968710
a7077aa
339a34e
c15f85c
a8001c7
05de63d
c57fa6b
3773e2f
e15de5f
1d4a225
f3ee9c5
c8a3c2f
02e89ce
ded3ea9
a2f62f2
bd9cbd6
ff05988
a8e6e2a
caa5bf7
4a3a248
e01aaad
0ba3b73
a1aeda3
53ec401
7864363
de5f4f2
b5f8044
2b0a2f6
2c6163a
664dc45
612b393
dc68dff
3d03957
91dbed7
ef2a886
5a104c6
fc3b75c
dce40b9
7e456c6
107e2d9
9de3588
eb75e4c
12bf5ec
24d9497
7abdd29
5d0506a
96481fe
e3a2a05
c50d954
e3b8a18
bd6713f
d2c458e
8e178ef
3a9e65c
92ff992
554f045
9c2de7b
2e5eedd
7e35427
7a3e875
4218522
b82df58
6e67873
5a4a985
0f9fe28
34e7da5
3399bf0
a1d7d0a
5bc79cf
916c78f
785ed7c
ecdbb6a
b6c7f5b
d2b622d
7944219
3d2691c
7f196f8
881bb77
8002d3c
9a300c0
4388ebb
04f4f83
ea122be
9f38d8c
f0055a0
8512c8e
cfd4103
e4f8122
a740293
78cc67a
201f6be
a9e1564
e71d910
f46f808
29ad9a0
fcae542
8c03934
9175338
bba8175
17b3e44
dfbe893
2f13ccd
21d226d
9365c66
5a1a8d6
33dd9a6
d981f3f
dd7dffe
75450cc
25243b4
c0522fe
5c3e061
0f0cd33
4a9e2b0
f4f1951
adf4444
db1fde0
d527322
beee347
6a7912d
6a0af80
59ef917
d6cabdf
9264ab3
9d0eabc
891b8df
7be6210
ce32587
6056026
492510b
e34818d
40b1e34
df8a290
f025519
9b96ce1
8721af0
7fc453e
d936cf9
07fcfe1
3f04300
bd2ab3f
48450ab
f9065ab
d02b182
4aed379
e93d291
a57efb0
1161047
09e0a2f
9ebf5bc
0d8c148
e3a92cf
7ce546f
857d634
82d972d
5644e17
c841454
2cd2e63
f08e0ca
b2ef471
ebb18f1
bd45d25
497436f
4e00ed6
885f56b
b0a4666
d519857
6cdab5b
2db7506
3591f81
5bd2f5d
ce9240d
48e655c
f023043
d27c662
4d2e920
dcf89d4
15c4e7f
34c233f
fb9971d
892c3ee
7185fe1
1b1513a
dcf9a33
28b1b7e
2333930
f24203c
8f99b61
eafef94
e713e13
e72490c
3409b66
9d888d2
61eba6d
4712f76
1051eaf
777f1a4
c7cd2c1
575ede9
0c18393
9e68d76
5cafad6
a5c87eb
39f947f
c2b5315
f6718dd
f74ece0
d7fe79e
a7338fb
f5a7eec
9cc5d37
f57d299
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,34 @@ | ||
| # Reduce Docker build context | ||
| .git | ||
| .github | ||
| .circleci | ||
| docs/ | ||
| *.md | ||
| LICENSE | ||
| **/__pycache__/ | ||
| **/*.pyc | ||
| .logs | ||
| .tmp | ||
| dist | ||
| build | ||
| artifacts | ||
| notebooks | ||
| tests/ | ||
| .venv/ | ||
| node_modules/ | ||
| .env | ||
| *.pem | ||
| .key | ||
| id_* | ||
| __pycache__/ | ||
| *.pyc | ||
| *.pyo | ||
| *.pyd | ||
| .Python | ||
| env/ | ||
| venv/ | ||
| ENV/ | ||
| env.bak/ | ||
| venv.bak/ | ||
| .pytest_cache/ | ||
| .coverage | ||
| htmlcov/ | ||
| .tox/ | ||
| .cache | ||
| nosetests.xml | ||
| coverage.xml | ||
| *.cover | ||
| .hypothesis/ | ||
| .DS_Store | ||
| *.log | ||
| logs/ | ||
| artifacts/ | ||
| build/ | ||
| dist/ | ||
| *.egg-info/ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| # Optimized Dockerfile for Cloud Run with pre-downloaded models | ||
| FROM python:3.11-slim | ||
|
|
||
| # Install system dependencies | ||
| RUN apt-get update && apt-get install -y --no-install-recommends \ | ||
| curl=7.74.0-1.3+deb11u7 \ | ||
| git=1:2.30.2-1+deb11u2 \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| # Set environment variables for model caching | ||
| ENV HF_HOME=/app/models | ||
| ENV TRANSFORMERS_CACHE=/app/models | ||
| ENV PYTHONPATH=/app | ||
| ENV PYTHONUNBUFFERED=1 | ||
|
|
||
| # Copy requirements and install dependencies | ||
| COPY dependencies/requirements-api.txt . | ||
| RUN pip install --no-cache-dir -r requirements-api.txt | ||
|
|
||
| # Create models directory | ||
| RUN mkdir -p /app/models | ||
|
|
||
| # Copy the pre-download script | ||
| COPY scripts/pre_download_models.py . | ||
|
|
||
| # Pre-download models during build (this will take time but ensures fast startup) | ||
| RUN python pre_download_models.py | ||
|
|
||
| # Validate models were downloaded correctly (critical for Cloud Run success) | ||
| RUN echo "🔍 Validating model cache..." && \ | ||
| ls -la /app/models/ && \ | ||
| echo "📊 Checking model sizes..." && \ | ||
| du -sh /app/models/* && \ | ||
| echo "✅ Model validation completed successfully" | ||
|
|
||
| # Create validation script | ||
| RUN echo '#!/usr/bin/env python3\n\ | ||
| import os\n\ | ||
| import sys\n\ | ||
| print("🧪 Testing model accessibility...")\n\ | ||
| \n\ | ||
| # Test transformers cache\n\ | ||
| try:\n\ | ||
| from transformers import AutoTokenizer\n\ | ||
| tokenizer = AutoTokenizer.from_pretrained("duelker/samo-goemotions-deberta-v3-large", cache_dir="/app/models", local_files_only=True)\n\ | ||
| print("✅ DeBERTa tokenizer loads successfully")\n\ | ||
| except Exception as e:\n\ | ||
| print(f"❌ DeBERTa tokenizer failed: {e}")\n\ | ||
| sys.exit(1)\n\ | ||
| \n\ | ||
| try:\n\ | ||
| from transformers import T5Tokenizer\n\ | ||
| t5_tokenizer = T5Tokenizer.from_pretrained("t5-small", cache_dir="/app/models", local_files_only=True)\n\ | ||
| print("✅ T5 tokenizer loads successfully")\n\ | ||
| except Exception as e:\n\ | ||
| print(f"❌ T5 tokenizer failed: {e}")\n\ | ||
| sys.exit(1)\n\ | ||
| \n\ | ||
| # Test Whisper model file exists\n\ | ||
| whisper_path = "/app/models/base.pt"\n\ | ||
| if os.path.exists(whisper_path):\n\ | ||
| print(f"✅ Whisper model file exists at {whisper_path}")\n\ | ||
| else:\n\ | ||
| print(f"❌ Whisper model file missing at {whisper_path}")\n\ | ||
| sys.exit(1)\n\ | ||
| \n\ | ||
| print("🎉 All model validation tests passed!")\n\ | ||
| ' > validate_models.py && chmod +x validate_models.py | ||
|
|
||
| # Run model validation | ||
| RUN python validate_models.py | ||
|
|
||
| # Copy source code | ||
| COPY src/ ./src/ | ||
| COPY *.py ./ | ||
|
|
||
| # Expose port | ||
| EXPOSE 8080 | ||
|
|
||
| # Run the optimized API | ||
| CMD ["python", "src/startup_api.py"] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| # 🔒 Security Notice - Token Management | ||
|
|
||
| ## ⚠️ CRITICAL: JWT Token Handling | ||
|
|
||
| **Date:** September 15, 2025 | ||
| **Issue:** Test reports contained actual JWT tokens from API testing | ||
|
|
||
| ### Actions Taken ✅ | ||
|
|
||
| 1. **Sanitized test report:** `test_reports/comprehensive_api_test_1757950799.json` | ||
| - Replaced real JWT tokens with `[REDACTED_JWT_ACCESS_TOKEN]` | ||
| - Replaced refresh tokens with `[REDACTED_JWT_REFRESH_TOKEN]` | ||
|
|
||
| 2. **Updated documentation examples:** | ||
| - Replaced example JWT fragments with placeholder text | ||
| - Used generic `JWT_ACCESS_TOKEN_HERE` in all docs | ||
|
|
||
| ### Security Best Practices 🛡️ | ||
|
|
||
| #### For Test Scripts | ||
| - **Never log actual JWT tokens** in test outputs | ||
| - Use placeholder tokens in test reports | ||
| - Sanitize sensitive data before saving results | ||
|
|
||
| #### For Documentation | ||
| - Use placeholder tokens like `JWT_ACCESS_TOKEN_HERE` | ||
| - Never include real API keys, tokens, or secrets | ||
| - Use `[REDACTED]` or `[PLACEHOLDER]` for sensitive fields | ||
|
|
||
| #### For Development | ||
| - Actual tokens are temporary (30min expiry) and test-only | ||
| - Never commit `.env` files with real credentials | ||
| - Use environment variables for production secrets | ||
|
|
||
| ### Token Security Context 🔍 | ||
|
|
||
| **The exposed tokens were:** | ||
| - ✅ **Temporary test tokens** (30-minute expiry) | ||
| - ✅ **Generated for testing purposes only** | ||
| - ✅ **Not production credentials** | ||
| - ✅ **Already expired** | ||
| - ✅ **From test user account** (`test_user_*@example.com`) | ||
|
|
||
| **Risk Assessment: LOW** | ||
| - Tokens were short-lived test credentials | ||
| - No production systems affected | ||
| - No real user data exposed | ||
|
|
||
| ### Prevention Measures 🚨 | ||
|
|
||
| 1. **Updated test scripts** to sanitize tokens before logging | ||
| 2. **Added security checks** to documentation process | ||
| 3. **Created this security notice** for future reference | ||
|
|
||
| ### Review Checklist ✅ | ||
|
|
||
| Before committing any files, ensure: | ||
| - [ ] No real JWT tokens in any files | ||
| - [ ] No API keys or secrets in clear text | ||
| - [ ] Test reports use `[REDACTED]` for sensitive data | ||
| - [ ] Documentation uses placeholder tokens only | ||
|
|
||
| --- | ||
|
|
||
| **Security Status: RESOLVED** ✅ | ||
| **Future Risk: MITIGATED** 🛡️ |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,60 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Cloud Build configuration for optimized SAMO Unified API | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| steps: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Build the optimized Docker image with pre-downloaded models | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - name: 'gcr.io/cloud-builders/docker' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| args: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - 'build' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - '-f' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - 'Dockerfile.optimized' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - '--platform' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - 'linux/amd64' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - '-t' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - 'us-central1-docker.pkg.dev/${PROJECT_ID}/samo-dl/samo-unified-api-optimized:${COMMIT_SHA}' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - '-t' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - 'us-central1-docker.pkg.dev/${PROJECT_ID}/samo-dl/samo-unified-api-optimized:latest' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - '.' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| timeout: '1200s' # 20 minutes for model downloads | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Push the image to Artifact Registry | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - name: 'gcr.io/cloud-builders/docker' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| args: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - 'push' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - 'us-central1-docker.pkg.dev/${PROJECT_ID}/samo-dl/samo-unified-api-optimized:${COMMIT_SHA}' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - name: 'gcr.io/cloud-builders/docker' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| args: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - 'push' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - 'us-central1-docker.pkg.dev/${PROJECT_ID}/samo-dl/samo-unified-api-optimized:latest' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+18
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add vulnerability scanning and fail the build on HIGH/CRITICAL. Apply: - name: 'gcr.io/cloud-builders/docker'
args:
- 'push'
- 'us-central1-docker.pkg.dev/${PROJECT_ID}/samo-dl/samo-unified-api-optimized:latest'
+ - name: 'gcr.io/cloud-builders/gcloud'
+ args:
+ - 'artifacts','docker','images','scan'
+ - 'us-central1-docker.pkg.dev/${PROJECT_ID}/samo-dl/samo-unified-api-optimized:${COMMIT_SHA}'
+
+ - name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
+ entrypoint: 'bash'
+ args:
+ - -c
+ - |
+ set -euo pipefail
+ if gcloud artifacts docker images list-vulnerabilities \
+ us-central1-docker.pkg.dev/${PROJECT_ID}/samo-dl/samo-unified-api-optimized:${COMMIT_SHA} \
+ --format='get(vulnerability.effectiveSeverity)' | grep -Eq 'CRITICAL|HIGH'; then
+ echo 'Found HIGH/CRITICAL vulnerabilities'; exit 1;
+ else
+ echo 'No HIGH/CRITICAL vulnerabilities';
+ fi
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Deploy to Cloud Run with bulletproof optimized settings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - name: 'gcr.io/google.com/cloudsdktool/cloud-sdk' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| entrypoint: 'gcloud' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| args: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - 'run' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - 'deploy' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - 'samo-unified-api-optimized' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - '--image=us-central1-docker.pkg.dev/${PROJECT_ID}/samo-dl/samo-unified-api-optimized:${COMMIT_SHA}' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - '--platform=managed' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - '--region=us-central1' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - '--allow-unauthenticated' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - '--port=8080' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - '--timeout=1200' # Extended timeout for model loading (20 minutes) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - '--cpu=2' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - '--memory=6Gi' # Increased memory for safe model loading | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - '--max-instances=10' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - '--min-instances=0' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - '--concurrency=80' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - '--startup-cpu-boost' # Faster cold starts | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - '--timeout=3600' # Request timeout (1 hour) - using supported flag | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - '--set-env-vars=PYTHONUNBUFFERED=1' # Ensure logging works | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+33
to
+50
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inject required secret into the service. Apply: - '--startup-cpu-boost' # Faster cold starts
- - '--timeout=3600' # Request timeout (1 hour) - using supported flag
- - '--set-env-vars=PYTHONUNBUFFERED=1' # Ensure logging works
+ - '--timeout=3600' # Request timeout (1 hour)
+ - '--set-env-vars=PYTHONUNBUFFERED=1'
+ - '--set-secrets=SAMO_EMOTION_API_KEY=SAMO_EMOTION_API_KEY:latest'📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Build options | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| options: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| machineType: 'E2_HIGHCPU_8' # Use high-CPU machine for faster builds | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| diskSizeGb: 100 # Larger disk for model downloads | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| logging: CLOUD_LOGGING_ONLY | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Substitution variables are provided by Cloud Build automatically | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Build timeout | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| timeout: '1800s' # 30 minutes total | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix secrets patterns: “.key” is a bug; broaden .env variants and narrow SSH key globs.
Apply:
📝 Committable suggestion
🤖 Prompt for AI Agents