saemstunes commited on
Commit
09e3762
Β·
verified Β·
1 Parent(s): 3bf0763

Update scripts/deploy_spaces.sh

Browse files
Files changed (1) hide show
  1. scripts/deploy_spaces.sh +225 -18
scripts/deploy_spaces.sh CHANGED
@@ -1,40 +1,54 @@
1
  #!/bin/bash
2
 
 
 
3
  echo "πŸš€ Deploying Saem's Tunes AI to Hugging Face Spaces"
 
4
 
5
  # Configuration
6
  SPACE_NAME="saemstunes/STA-AI"
7
  MODEL_REPO="Thetima4/Phi-3.5-mini-instruct-Q4_K_M-GGUF"
8
  MODEL_FILE="Phi-3.5-mini-instruct-q4_k_m.gguf"
 
9
 
10
  echo "πŸ“¦ Preparing deployment for space: $SPACE_NAME"
 
 
11
 
12
  # Check if required files exist
13
- required_files=("app.py" "requirements.txt" "config/spaces_config.json")
 
14
  for file in "${required_files[@]}"; do
15
- if [ ! -f "$file" ]; then
16
- echo "❌ Missing required file: $file"
17
  exit 1
18
  fi
19
  done
20
 
21
  echo "βœ… All required files present"
22
 
23
- # Create README for the space
 
 
 
 
24
  cat > README.md << 'EOF'
25
  # 🎡 Saem's Tunes AI Assistant
26
 
27
- Production-ready AI assistant for Saem's Tunes music platform.
28
 
29
- ## Features
30
 
31
- - **Smart Music Assistance**: Help with platform features, music discovery, and artist information
32
  - **Fast Responses**: Powered by Microsoft Phi-3.5-mini-instruct (Q4_K_M quantization)
33
- - **Secure**: Input sanitization and rate limiting
 
34
  - **Real-time Monitoring**: Performance metrics and health checks
 
35
 
36
- ## API Usage
37
 
 
38
  ```python
39
  import requests
40
 
@@ -42,16 +56,54 @@ response = requests.post(
42
  "https://saemstunes-sta-ai.hf.space/api/chat",
43
  json={
44
  "message": "How do I create a playlist?",
45
- "user_id": "user_123"
 
46
  }
47
  )
 
 
 
48
 
 
 
 
49
  Environment Variables
50
  SUPABASE_URL: Your Supabase project URL
51
 
52
  SUPABASE_ANON_KEY: Your Supabase anon key
53
 
54
- Model Information
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  Base Model: microsoft/Phi-3.5-mini-instruct
56
 
57
  Quantization: Q4_K_M (optimal quality/speed balance)
@@ -60,23 +112,178 @@ Context Window: 4K tokens
60
 
61
  Response Time: 2-5 seconds
62
 
63
- Built for Saem's Tunes - Your music streaming platform
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
  EOF
65
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  echo "πŸ“‹ Deployment checklist:"
67
  echo " βœ… app.py (main application)"
68
  echo " βœ… requirements.txt (dependencies)"
69
  echo " βœ… README.md (documentation)"
70
- echo " βœ… config/spaces_config.json (configuration)"
 
 
 
71
 
72
  echo ""
73
- echo "🎯 Next steps:"
74
  echo "1. Go to https://huggingface.co/spaces"
75
- echo "2. Push this repository to your space"
76
- echo "3. Set environment variables:"
 
 
77
  echo " - SUPABASE_URL"
78
  echo " - SUPABASE_ANON_KEY"
79
- echo "4. Deploy and test!"
80
-
 
 
 
81
  echo ""
82
  echo "βœ… Deployment preparation completed!"
 
1
  #!/bin/bash
2
 
3
+ set -e # Exit on any error
4
+
5
  echo "πŸš€ Deploying Saem's Tunes AI to Hugging Face Spaces"
6
+ echo "==================================================="
7
 
8
  # Configuration
9
  SPACE_NAME="saemstunes/STA-AI"
10
  MODEL_REPO="Thetima4/Phi-3.5-mini-instruct-Q4_K_M-GGUF"
11
  MODEL_FILE="Phi-3.5-mini-instruct-q4_k_m.gguf"
12
+ VERSION="2.0.0"
13
 
14
  echo "πŸ“¦ Preparing deployment for space: $SPACE_NAME"
15
+ echo "πŸ”– Version: $VERSION"
16
+ echo "πŸ€– Model: $MODEL_REPO"
17
 
18
  # Check if required files exist
19
+ echo "πŸ” Checking required files..."
20
+ required_files=("app.py" "requirements.txt" "config/spaces_config.json" "src/")
21
  for file in "${required_files[@]}"; do
22
+ if [ ! -e "$file" ]; then
23
+ echo "❌ Missing required file/directory: $file"
24
  exit 1
25
  fi
26
  done
27
 
28
  echo "βœ… All required files present"
29
 
30
+ # Create models directory if it doesn't exist
31
+ mkdir -p models
32
+
33
+ # Create comprehensive README for the space
34
+ echo "πŸ“ Creating README.md..."
35
  cat > README.md << 'EOF'
36
  # 🎡 Saem's Tunes AI Assistant
37
 
38
+ Production-ready AI assistant for Saem's Tunes music education and streaming platform.
39
 
40
+ ## πŸš€ Features
41
 
42
+ - **Smart Music Assistance**: Help with platform features, music discovery, and educational content
43
  - **Fast Responses**: Powered by Microsoft Phi-3.5-mini-instruct (Q4_K_M quantization)
44
+ - **Platform Integration**: Full integration with Saem's Tunes existing database
45
+ - **Secure**: Input sanitization, rate limiting, and suspicious activity detection
46
  - **Real-time Monitoring**: Performance metrics and health checks
47
+ - **Dual Deployment**: Hugging Face Spaces (primary) + Railway (backup)
48
 
49
+ ## πŸ“š API Usage
50
 
51
+ ### Chat Endpoint
52
  ```python
53
  import requests
54
 
 
56
  "https://saemstunes-sta-ai.hf.space/api/chat",
57
  json={
58
  "message": "How do I create a playlist?",
59
+ "user_id": "user_123",
60
+ "conversation_id": "conv_123"
61
  }
62
  )
63
+ Health Check
64
+ python
65
+ import requests
66
 
67
+ response = requests.get("https://saemstunes-sta-ai.hf.space/api/health")
68
+ print(response.json())
69
+ πŸ› οΈ For Developers
70
  Environment Variables
71
  SUPABASE_URL: Your Supabase project URL
72
 
73
  SUPABASE_ANON_KEY: Your Supabase anon key
74
 
75
+ MODEL_NAME: Phi-3.5-mini-instruct (default)
76
+
77
+ LOG_LEVEL: INFO (default)
78
+
79
+ MAX_RESPONSE_LENGTH: 500 (default)
80
+
81
+ Local Development
82
+ bash
83
+ # Install dependencies
84
+ pip install -r requirements.txt
85
+
86
+ # Run locally
87
+ python app.py
88
+
89
+ # Run tests
90
+ pytest tests/
91
+ 🎯 Platform Features Supported
92
+ The AI assistant understands and can help with:
93
+
94
+ Music Streaming: Tracks, artists, playlists, recommendations
95
+
96
+ Education: Courses, lessons, quizzes, learning paths
97
+
98
+ Community: User profiles, favorites, follows, social features
99
+
100
+ Creator Tools: Music upload, artist profiles, analytics
101
+
102
+ E-commerce: Subscriptions, payments, premium content
103
+
104
+ Technical Support: Platform help, troubleshooting
105
+
106
+ πŸ”§ Technical Details
107
  Base Model: microsoft/Phi-3.5-mini-instruct
108
 
109
  Quantization: Q4_K_M (optimal quality/speed balance)
 
112
 
113
  Response Time: 2-5 seconds
114
 
115
+ Security: Rate limiting (60 requests/minute), input sanitization
116
+
117
+ Monitoring: Real-time metrics, health checks, error tracking
118
+
119
+ πŸ“Š Monitoring
120
+ Real-time metrics at /metrics
121
+
122
+ Health checks at /health
123
+
124
+ Performance statistics at /api/stats
125
+
126
+ πŸ†˜ Support
127
+ Documentation: This README and inline code documentation
128
+
129
+ Issues: GitHub issue tracker
130
+
131
+ Contact: development@saemstunes.com
132
+
133
+ Built with ❀️ for Saem's Tunes - Your complete music education and streaming platform
134
+
135
+ Version: 2.0.0
136
+ Last Updated: $(date +%Y-%m-%d)
137
  EOF
138
 
139
+ echo "βœ… README.md created"
140
+
141
+ Create .env.example for environment variables
142
+ echo "πŸ”§ Creating environment template..."
143
+ cat > .env.example << 'EOF'
144
+
145
+ Saem's Tunes AI Configuration
146
+ Copy this file to .env and fill in your actual values
147
+ Supabase Configuration
148
+ SUPABASE_URL=your_supabase_project_url_here
149
+ SUPABASE_ANON_KEY=your_supabase_anon_key_here
150
+
151
+ Model Configuration
152
+ MODEL_NAME=microsoft/Phi-3.5-mini-instruct
153
+ HF_SPACE=saemstunes/STA-AI
154
+
155
+ Server Configuration
156
+ PORT=7860
157
+ LOG_LEVEL=INFO
158
+ MAX_RESPONSE_LENGTH=500
159
+
160
+ Monitoring
161
+ ENABLE_MONITORING=true
162
+ EOF
163
+
164
+ echo "βœ… Environment template created"
165
+
166
+ Create deployment info file
167
+ echo "πŸ“‹ Creating deployment info..."
168
+ cat > deployment-info.md << EOF
169
+
170
+ Deployment Information
171
+ Space Details
172
+ Name: $SPACE_NAME
173
+
174
+ Version: $VERSION
175
+
176
+ Model: $MODEL_REPO
177
+
178
+ Deployment Date: $(date)
179
+
180
+ Required Setup
181
+ Set the following environment variables in your Space settings:
182
+
183
+ SUPABASE_URL
184
+
185
+ SUPABASE_ANON_KEY
186
+
187
+ File Structure
188
+ ```
189
+ $(find . -type f -name ".py" -o -name ".json" -o -name ".md" -o -name ".txt" -o -name "*.yml" | head -20 | sed 's|^./||' | sort)
190
+ ```
191
+
192
+ API Endpoints
193
+ `/api/chat` - Main chat endpoint
194
+
195
+ `/api/health` - Health check
196
+
197
+ `/api/models` - Model information
198
+
199
+ `/api/stats` - System statistics
200
+
201
+ `/api/feedback` - User feedback
202
+
203
+ Monitoring
204
+ Health checks run every 30 seconds
205
+
206
+ Metrics available at `/metrics`
207
+
208
+ Logs are stored in `saems_ai.log`
209
+ EOF
210
+
211
+ echo "βœ… Deployment info created"
212
+
213
+ Create verification script
214
+ echo "πŸ” Creating verification script..."
215
+ cat > verify_deployment.py << 'EOF'
216
+ #!/usr/bin/env python3
217
+
218
+ import os
219
+ import sys
220
+
221
+ def check_file_exists(filepath):
222
+ """Check if file exists"""
223
+ if os.path.exists(filepath):
224
+ print(f"βœ… {filepath}")
225
+ return True
226
+ else:
227
+ print(f"❌ {filepath}")
228
+ return False
229
+
230
+ def main():
231
+ print("πŸ” Verifying deployment setup...")
232
+
233
+ text
234
+ required_files = [
235
+ "app.py",
236
+ "requirements.txt",
237
+ "README.md",
238
+ "config/spaces_config.json",
239
+ "src/__init__.py",
240
+ "src/ai_system.py",
241
+ "src/supabase_integration.py",
242
+ "src/security_system.py",
243
+ "src/monitoring_system.py",
244
+ "src/utils.py"
245
+ ]
246
+
247
+ all_exists = True
248
+ for filepath in required_files:
249
+ if not check_file_exists(filepath):
250
+ all_exists = False
251
+
252
+ if all_exists:
253
+ print("\nπŸŽ‰ All required files are present!")
254
+ print("πŸ“¦ Deployment package is ready for Hugging Face Spaces")
255
+ else:
256
+ print("\n❌ Some required files are missing!")
257
+ sys.exit(1)
258
+ if name == "main":
259
+ main()
260
+ EOF
261
+
262
+ python verify_deployment.py
263
+
264
+ echo ""
265
  echo "πŸ“‹ Deployment checklist:"
266
  echo " βœ… app.py (main application)"
267
  echo " βœ… requirements.txt (dependencies)"
268
  echo " βœ… README.md (documentation)"
269
+ echo " βœ… config/ (configuration files)"
270
+ echo " βœ… src/ (source code)"
271
+ echo " βœ… scripts/ (utility scripts)"
272
+ echo " βœ… .env.example (environment template)"
273
 
274
  echo ""
275
+ echo "🎯 Deployment Instructions:"
276
  echo "1. Go to https://huggingface.co/spaces"
277
+ echo "2. Create new Space or update existing: $SPACE_NAME"
278
+ echo "3. Set SDK to Gradio"
279
+ echo "4. Upload all files from this directory"
280
+ echo "5. Set environment variables:"
281
  echo " - SUPABASE_URL"
282
  echo " - SUPABASE_ANON_KEY"
283
+ echo "6. Deploy and wait for build to complete"
284
+ echo "7. Test the API endpoints"
285
+ echo ""
286
+ echo "πŸ”— Your Space will be available at:"
287
+ echo " https://huggingface.co/spaces/$SPACE_NAME"
288
  echo ""
289
  echo "βœ… Deployment preparation completed!"