saemstunes commited on
Commit
498cca6
Β·
verified Β·
1 Parent(s): 09e3762

Update scripts/setup_environment.sh

Browse files
Files changed (1) hide show
  1. scripts/setup_environment.sh +131 -20
scripts/setup_environment.sh CHANGED
@@ -1,45 +1,156 @@
1
 
2
  #!/bin/bash
3
 
 
 
4
  echo "πŸ”§ Setting up Saem's Tunes AI development environment"
 
 
 
 
 
5
 
6
  # Create virtual environment
7
  echo "πŸ“¦ Creating Python virtual environment..."
8
  python -m venv venv
9
  source venv/bin/activate
10
 
 
 
 
 
11
  # Install dependencies
12
  echo "πŸ“₯ Installing dependencies..."
13
- pip install --upgrade pip
14
  pip install -r requirements.txt
15
  pip install -r requirements-dev.txt
16
 
 
 
17
  # Create necessary directories
18
  echo "πŸ“ Creating directory structure..."
19
- mkdir -p models
20
- mkdir -p logs
21
- mkdir -p config
22
 
23
  # Setup pre-commit hooks
24
  echo "πŸ”¨ Setting up pre-commit hooks..."
25
- pre-commit install
26
-
27
- # Create environment template
28
- echo "πŸ“ Creating environment template..."
29
- cat > .env.template << 'EOF'
30
- # Saem's Tunes AI Configuration
31
- SUPABASE_URL=your_supabase_url_here
32
- SUPABASE_ANON_KEY=your_supabase_anon_key_here
33
- MODEL_NAME=microsoft/Phi-3.5-mini-instruct
34
- HF_SPACE=saemstunes/STA-AI
35
- PORT=7860
36
- LOG_LEVEL=INFO
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  EOF
38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  echo "βœ… Environment setup completed!"
40
  echo ""
41
  echo "πŸ“‹ Next steps:"
42
- echo "1. Copy .env.template to .env"
43
- echo "2. Fill in your actual environment variables"
44
- echo "3. Run: source venv/bin/activate"
45
- echo "4. Test with: python app.py"
 
 
 
 
 
 
 
 
 
 
 
1
 
2
  #!/bin/bash
3
 
4
+ set -e # Exit on any error
5
+
6
  echo "πŸ”§ Setting up Saem's Tunes AI development environment"
7
+ echo "===================================================="
8
+
9
+ # Check Python version
10
+ echo "🐍 Checking Python version..."
11
+ python --version || { echo "❌ Python not found"; exit 1; }
12
 
13
  # Create virtual environment
14
  echo "πŸ“¦ Creating Python virtual environment..."
15
  python -m venv venv
16
  source venv/bin/activate
17
 
18
+ # Upgrade pip
19
+ echo "πŸ“₯ Upgrading pip..."
20
+ pip install --upgrade pip
21
+
22
  # Install dependencies
23
  echo "πŸ“₯ Installing dependencies..."
 
24
  pip install -r requirements.txt
25
  pip install -r requirements-dev.txt
26
 
27
+ echo "βœ… Dependencies installed"
28
+
29
  # Create necessary directories
30
  echo "πŸ“ Creating directory structure..."
31
+ mkdir -p models logs config tests/monitoring static
 
 
32
 
33
  # Setup pre-commit hooks
34
  echo "πŸ”¨ Setting up pre-commit hooks..."
35
+ pre-commit install || echo "⚠️ pre-commit not available, skipping"
36
+
37
+ # Create environment template if it doesn't exist
38
+ if [ ! -f .env ]; then
39
+ echo "πŸ“ Creating environment file..."
40
+ cp .env.example .env
41
+ echo "⚠️ Please update .env with your actual values"
42
+ fi
43
+
44
+ # Create test configuration
45
+ echo "πŸ§ͺ Creating test configuration..."
46
+ cat > tests/test_config.py << 'EOF'
47
+ """Test configuration for Saem's Tunes AI"""
48
+
49
+ TEST_CONFIG = {
50
+ "supabase": {
51
+ "url": "https://test.supabase.co",
52
+ "key": "test_key"
53
+ },
54
+ "model": {
55
+ "name": "microsoft/Phi-3.5-mini-instruct",
56
+ "quantization": "Q4_K_M"
57
+ },
58
+ "security": {
59
+ "rate_limit": 60,
60
+ "max_input_length": 10000
61
+ }
62
+ }
63
  EOF
64
 
65
+ # Create development startup script
66
+ echo "πŸš€ Creating development startup script..."
67
+ cat > run_dev.sh << 'EOF'
68
+ #!/bin/bash
69
+
70
+ source venv/bin/activate
71
+ export LOG_LEVEL=DEBUG
72
+ export ENVIRONMENT=development
73
+ python app.py
74
+ EOF
75
+
76
+ chmod +x run_dev.sh
77
+
78
+ # Create production startup script
79
+ echo "🏭 Creating production startup script..."
80
+ cat > run_prod.sh << 'EOF'
81
+ #!/bin/bash
82
+
83
+ source venv/bin/activate
84
+ export LOG_LEVEL=INFO
85
+ export ENVIRONMENT=production
86
+ python railway_app.py
87
+ EOF
88
+
89
+ chmod +x run_prod.sh
90
+
91
+ # Download model script
92
+ echo "πŸ“₯ Creating model download script..."
93
+ cat > download_model.py << 'EOF'
94
+ #!/usr/bin/env python3
95
+
96
+ import os
97
+ from huggingface_hub import hf_hub_download
98
+ import argparse
99
+
100
+ def main():
101
+ parser = argparse.ArgumentParser(description="Download Phi-3.5-mini-instruct model")
102
+ parser.add_argument("--repo", default="Thetima4/Phi-3.5-mini-instruct-Q4_K_M-GGUF",
103
+ help="Hugging Face repository ID")
104
+ parser.add_argument("--file", default="Phi-3.5-mini-instruct-q4_k_m.gguf",
105
+ help="Model filename")
106
+ parser.add_argument("--dir", default="./models",
107
+ help="Local directory to save the model")
108
+
109
+ args = parser.parse_args()
110
+
111
+ print(f"πŸ“₯ Downloading model from {args.repo}")
112
+ print(f"πŸ“„ Model file: {args.file}")
113
+ print(f"πŸ’Ύ Local directory: {args.dir}")
114
+
115
+ # Create local directory if it doesn't exist
116
+ os.makedirs(args.dir, exist_ok=True)
117
+
118
+ try:
119
+ # Download the model
120
+ model_path = hf_hub_download(
121
+ repo_id=args.repo,
122
+ filename=args.file,
123
+ local_dir=args.dir,
124
+ local_dir_use_symlinks=False
125
+ )
126
+
127
+ print(f"βœ… Model downloaded successfully: {model_path}")
128
+ return model_path
129
+
130
+ except Exception as e:
131
+ print(f"❌ Error downloading model: {e}")
132
+ return None
133
+
134
+ if __name__ == "__main__":
135
+ main()
136
+ EOF
137
+
138
+ chmod +x download_model.py
139
+
140
  echo "βœ… Environment setup completed!"
141
  echo ""
142
  echo "πŸ“‹ Next steps:"
143
+ echo "1. Update .env with your actual environment variables"
144
+ echo "2. Run: source venv/bin/activate"
145
+ echo "3. Download model: python download_model.py"
146
+ echo "4. Test the system: python app.py"
147
+ echo "5. Run tests: pytest tests/"
148
+ echo ""
149
+ echo "🎯 Development commands:"
150
+ echo " ./run_dev.sh # Start development server"
151
+ echo " ./run_prod.sh # Start production server"
152
+ echo " pytest tests/ # Run test suite"
153
+ echo " black src/ # Format code"
154
+ echo " flake8 src/ # Lint code"
155
+ echo ""
156
+ echo "πŸš€ Happy coding!"