File size: 6,825 Bytes
3a6fd08
 
09e3762
 
3a6fd08
09e3762
3a6fd08
 
 
 
 
09e3762
3a6fd08
 
09e3762
 
3a6fd08
 
09e3762
 
3a6fd08
09e3762
 
3a6fd08
 
 
 
 
 
09e3762
 
 
 
 
3a6fd08
 
 
09e3762
3a6fd08
09e3762
3a6fd08
09e3762
3a6fd08
09e3762
 
3a6fd08
09e3762
3a6fd08
09e3762
3a6fd08
09e3762
3a6fd08
 
 
 
 
 
 
09e3762
 
3a6fd08
 
09e3762
 
 
3a6fd08
09e3762
 
 
3a6fd08
 
 
 
 
09e3762
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3a6fd08
 
 
 
 
 
 
 
09e3762
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3a6fd08
 
09e3762
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3a6fd08
 
 
 
09e3762
 
 
 
3a6fd08
 
09e3762
3a6fd08
09e3762
 
 
 
3a6fd08
 
09e3762
 
 
 
 
3a6fd08
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
#!/bin/bash

set -e  # Exit on any error

echo "πŸš€ Deploying Saem's Tunes AI to Hugging Face Spaces"
echo "==================================================="

# Configuration
SPACE_NAME="saemstunes/STA-AI"
MODEL_REPO="Thetima4/Phi-3.5-mini-instruct-Q4_K_M-GGUF"
MODEL_FILE="Phi-3.5-mini-instruct-q4_k_m.gguf"
VERSION="2.0.0"

echo "πŸ“¦ Preparing deployment for space: $SPACE_NAME"
echo "πŸ”– Version: $VERSION"
echo "πŸ€– Model: $MODEL_REPO"

# Check if required files exist
echo "πŸ” Checking required files..."
required_files=("app.py" "requirements.txt" "config/spaces_config.json" "src/")
for file in "${required_files[@]}"; do
    if [ ! -e "$file" ]; then
        echo "❌ Missing required file/directory: $file"
        exit 1
    fi
done

echo "βœ… All required files present"

# Create models directory if it doesn't exist
mkdir -p models

# Create comprehensive README for the space
echo "πŸ“ Creating README.md..."
cat > README.md << 'EOF'
# 🎡 Saem's Tunes AI Assistant

Production-ready AI assistant for Saem's Tunes music education and streaming platform.

## πŸš€ Features

- **Smart Music Assistance**: Help with platform features, music discovery, and educational content
- **Fast Responses**: Powered by Microsoft Phi-3.5-mini-instruct (Q4_K_M quantization)
- **Platform Integration**: Full integration with Saem's Tunes existing database
- **Secure**: Input sanitization, rate limiting, and suspicious activity detection
- **Real-time Monitoring**: Performance metrics and health checks
- **Dual Deployment**: Hugging Face Spaces (primary) + Railway (backup)

## πŸ“š API Usage

### Chat Endpoint
```python
import requests

response = requests.post(
    "https://saemstunes-sta-ai.hf.space/api/chat",
    json={
        "message": "How do I create a playlist?",
        "user_id": "user_123",
        "conversation_id": "conv_123"
    }
)
Health Check
python
import requests

response = requests.get("https://saemstunes-sta-ai.hf.space/api/health")
print(response.json())
πŸ› οΈ For Developers
Environment Variables
SUPABASE_URL: Your Supabase project URL

SUPABASE_ANON_KEY: Your Supabase anon key

MODEL_NAME: Phi-3.5-mini-instruct (default)

LOG_LEVEL: INFO (default)

MAX_RESPONSE_LENGTH: 500 (default)

Local Development
bash
# Install dependencies
pip install -r requirements.txt

# Run locally
python app.py

# Run tests
pytest tests/
🎯 Platform Features Supported
The AI assistant understands and can help with:

Music Streaming: Tracks, artists, playlists, recommendations

Education: Courses, lessons, quizzes, learning paths

Community: User profiles, favorites, follows, social features

Creator Tools: Music upload, artist profiles, analytics

E-commerce: Subscriptions, payments, premium content

Technical Support: Platform help, troubleshooting

πŸ”§ Technical Details
Base Model: microsoft/Phi-3.5-mini-instruct

Quantization: Q4_K_M (optimal quality/speed balance)

Context Window: 4K tokens

Response Time: 2-5 seconds

Security: Rate limiting (60 requests/minute), input sanitization

Monitoring: Real-time metrics, health checks, error tracking

πŸ“Š Monitoring
Real-time metrics at /metrics

Health checks at /health

Performance statistics at /api/stats

πŸ†˜ Support
Documentation: This README and inline code documentation

Issues: GitHub issue tracker

Contact: development@saemstunes.com

Built with ❀️ for Saem's Tunes - Your complete music education and streaming platform

Version: 2.0.0
Last Updated: $(date +%Y-%m-%d)
EOF

echo "βœ… README.md created"

Create .env.example for environment variables
echo "πŸ”§ Creating environment template..."
cat > .env.example << 'EOF'

Saem's Tunes AI Configuration
Copy this file to .env and fill in your actual values
Supabase Configuration
SUPABASE_URL=your_supabase_project_url_here
SUPABASE_ANON_KEY=your_supabase_anon_key_here

Model Configuration
MODEL_NAME=microsoft/Phi-3.5-mini-instruct
HF_SPACE=saemstunes/STA-AI

Server Configuration
PORT=7860
LOG_LEVEL=INFO
MAX_RESPONSE_LENGTH=500

Monitoring
ENABLE_MONITORING=true
EOF

echo "βœ… Environment template created"

Create deployment info file
echo "πŸ“‹ Creating deployment info..."
cat > deployment-info.md << EOF

Deployment Information
Space Details
Name: $SPACE_NAME

Version: $VERSION

Model: $MODEL_REPO

Deployment Date: $(date)

Required Setup
Set the following environment variables in your Space settings:

SUPABASE_URL

SUPABASE_ANON_KEY

File Structure
```
$(find . -type f -name ".py" -o -name ".json" -o -name ".md" -o -name ".txt" -o -name "*.yml" | head -20 | sed 's|^./||' | sort)
```

API Endpoints
`/api/chat` - Main chat endpoint

`/api/health` - Health check

`/api/models` - Model information

`/api/stats` - System statistics

`/api/feedback` - User feedback

Monitoring
Health checks run every 30 seconds

Metrics available at `/metrics`

Logs are stored in `saems_ai.log`
EOF

echo "βœ… Deployment info created"

Create verification script
echo "πŸ” Creating verification script..."
cat > verify_deployment.py << 'EOF'
#!/usr/bin/env python3

import os
import sys

def check_file_exists(filepath):
"""Check if file exists"""
if os.path.exists(filepath):
print(f"βœ… {filepath}")
return True
else:
print(f"❌ {filepath}")
return False

def main():
print("πŸ” Verifying deployment setup...")

text
required_files = [
    "app.py",
    "requirements.txt",
    "README.md",
    "config/spaces_config.json",
    "src/__init__.py",
    "src/ai_system.py",
    "src/supabase_integration.py",
    "src/security_system.py",
    "src/monitoring_system.py",
    "src/utils.py"
]

all_exists = True
for filepath in required_files:
    if not check_file_exists(filepath):
        all_exists = False

if all_exists:
    print("\nπŸŽ‰ All required files are present!")
    print("πŸ“¦ Deployment package is ready for Hugging Face Spaces")
else:
    print("\n❌ Some required files are missing!")
    sys.exit(1)
if name == "main":
main()
EOF

python verify_deployment.py

echo ""
echo "πŸ“‹ Deployment checklist:"
echo " βœ… app.py (main application)"
echo " βœ… requirements.txt (dependencies)"
echo " βœ… README.md (documentation)"
echo " βœ… config/ (configuration files)"
echo " βœ… src/ (source code)"
echo " βœ… scripts/ (utility scripts)"
echo " βœ… .env.example (environment template)"

echo ""
echo "🎯 Deployment Instructions:"
echo "1. Go to https://huggingface.co/spaces"
echo "2. Create new Space or update existing: $SPACE_NAME"
echo "3. Set SDK to Gradio"
echo "4. Upload all files from this directory"
echo "5. Set environment variables:"
echo " - SUPABASE_URL"
echo " - SUPABASE_ANON_KEY"
echo "6. Deploy and wait for build to complete"
echo "7. Test the API endpoints"
echo ""
echo "πŸ”— Your Space will be available at:"
echo " https://huggingface.co/spaces/$SPACE_NAME"
echo ""
echo "βœ… Deployment preparation completed!"