-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
251 lines (192 loc) Β· 6.87 KB
/
setup.py
File metadata and controls
251 lines (192 loc) Β· 6.87 KB
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
#!/usr/bin/env python3
"""
Setup script for Vessel Maintenance AI System
Handles installation, configuration, and initial setup
"""
import os
import sys
import subprocess
import platform
from pathlib import Path
def print_banner():
"""Print application banner"""
print("""
π ========================================== π
VESSEL MAINTENANCE AI SYSTEM - SETUP
π ========================================== π
AI-powered document processing for maritime operations
Automatically classifies maintenance records, sensor alerts,
and incident reports for rapid response and risk mitigation.
""")
def check_python_version():
"""Check if Python version is compatible"""
print("π Checking Python version...")
major, minor = sys.version_info[:2]
if major < 3 or (major == 3 and minor < 8):
print("β Error: Python 3.8 or higher is required")
print(f" Current version: {major}.{minor}")
sys.exit(1)
print(f"β
Python {major}.{minor} is compatible")
def install_dependencies():
"""Install required Python packages"""
print("\nπ¦ Installing Python dependencies...")
try:
subprocess.run([
sys.executable, "-m", "pip", "install", "-r", "requirements.txt"
], check=True, capture_output=True)
print("β
Dependencies installed successfully")
except subprocess.CalledProcessError as e:
print(f"β Error installing dependencies: {e}")
print(" Please run: pip install -r requirements.txt")
return False
return True
def setup_spacy_model():
"""Download spaCy language model"""
print("\nπ§ Setting up NLP language model...")
try:
subprocess.run([
sys.executable, "-m", "spacy", "download", "en_core_web_sm"
], check=True, capture_output=True)
print("β
spaCy English model downloaded")
except subprocess.CalledProcessError:
print("β οΈ Warning: spaCy model download failed")
print(" The system will use basic NLP processing")
print(" To install manually: python -m spacy download en_core_web_sm")
def create_directories():
"""Create necessary directories"""
print("\nπ Creating application directories...")
directories = ["data", "logs", "static"]
for directory in directories:
Path(directory).mkdir(exist_ok=True)
print(f"β
Created directory: {directory}")
def setup_database():
"""Initialize the database"""
print("\nποΈ Initializing database...")
try:
from src.database import DatabaseManager
db_manager = DatabaseManager()
print("β
Database initialized successfully")
except Exception as e:
print(f"β Error initializing database: {e}")
return False
return True
def test_installation():
"""Test the installation"""
print("\nπ§ͺ Testing installation...")
try:
# Test imports
from src.ai_processor import VesselMaintenanceAI
from src.models import ProcessingRequest
from src.database import DatabaseManager
# Test AI processor initialization
ai_processor = VesselMaintenanceAI()
print("β
AI processor initialized")
# Test database connection
db_manager = DatabaseManager()
print("β
Database connection successful")
print("β
Installation test completed successfully")
return True
except Exception as e:
print(f"β Installation test failed: {e}")
return False
def create_startup_script():
"""Create startup script for the application"""
print("\nπ Creating startup script...")
script_content = """#!/bin/bash
# Vessel Maintenance AI System - Startup Script
echo "π’ Starting Vessel Maintenance AI System..."
# Check if virtual environment should be activated
if [ -d "venv" ]; then
echo "π§ Activating virtual environment..."
source venv/bin/activate
fi
# Start the application
echo "π Launching application on http://localhost:8000"
python app.py
"""
with open("start.sh", "w") as f:
f.write(script_content)
# Make script executable on Unix systems
if platform.system() != "Windows":
os.chmod("start.sh", 0o755)
print("β
Created start.sh script")
def create_sample_config():
"""Create sample configuration file"""
print("\nβοΈ Creating sample configuration...")
config_content = """# Vessel Maintenance AI System Configuration
# Database settings
DATABASE_PATH=data/vessel_maintenance.db
# Server settings
HOST=0.0.0.0
PORT=8000
# Logging settings
LOG_LEVEL=INFO
LOG_FILE=logs/application.log
# AI Processing settings
MAX_TEXT_LENGTH=10000
CONFIDENCE_THRESHOLD=0.3
# Cache settings
ANALYTICS_CACHE_MINUTES=30
"""
with open(".env.example", "w") as f:
f.write(config_content)
print("β
Created .env.example configuration file")
def print_next_steps():
"""Print next steps for the user"""
print("""
π =======================================
INSTALLATION COMPLETED SUCCESSFULLY!
π =======================================
π NEXT STEPS:
1. Start the application:
./start.sh
OR
python app.py
2. Open your browser to:
http://localhost:8000
3. Load sample data (optional):
python sample_data.py
4. Generate real-time demo alerts:
python sample_data.py --realtime
π DOCUMENTATION:
- Read README.md for detailed usage instructions
- Check logs/ directory for application logs
- Modify .env.example for custom configuration
π§ SUPPORT:
- Create issues on GitHub for bug reports
- Review troubleshooting section in README.md
β‘ QUICK TEST:
Try pasting this text in the web interface:
"Engine room fire alarm activated. Emergency shutdown initiated."
Happy maritime AI processing! πβ
""")
def main():
"""Main setup function"""
print_banner()
# Check requirements
check_python_version()
# Confirm installation
response = input("π Proceed with installation? (y/N): ").lower().strip()
if response not in ['y', 'yes']:
print("β Installation cancelled")
sys.exit(0)
# Perform installation steps
steps = [
("Installing dependencies", install_dependencies),
("Creating directories", create_directories),
("Setting up database", setup_database),
("Testing installation", test_installation),
("Creating startup script", create_startup_script),
("Creating sample config", create_sample_config),
]
for step_name, step_func in steps:
print(f"\nπ {step_name}...")
if not step_func():
print(f"β Setup failed at: {step_name}")
sys.exit(1)
# Optional spaCy model (non-critical)
setup_spacy_model()
# Show completion message
print_next_steps()
if __name__ == "__main__":
main()