-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdeploy-userdata.sh
More file actions
279 lines (243 loc) · 8.9 KB
/
Copy pathdeploy-userdata.sh
File metadata and controls
279 lines (243 loc) · 8.9 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
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
#!/bin/bash
set -e
# Complete deployment script
echo "Starting Voice Description API deployment..." >> /var/log/deployment.log
# Update system
apt-get update -y
# Install Node.js 18
curl -fsSL https://deb.nodesource.com/setup_18.x | bash -
apt-get install -y nodejs nginx
# Create application directory
mkdir -p /opt/voice-description-api
cd /opt/voice-description-api
# Create package.json
cat > package.json << 'EOF'
{
"name": "voice-description-api",
"version": "1.0.0",
"description": "Automated video audio description system",
"main": "server.js",
"scripts": {
"start": "node server.js"
},
"dependencies": {
"express": "^4.18.2",
"cors": "^2.8.5"
}
}
EOF
# Create main server file
cat > server.js << 'EOF'
const express = require('express');
const cors = require('cors');
const app = express();
const port = 3000;
// Middleware
app.use(cors());
app.use(express.json({ limit: '500mb' }));
app.use(express.static('public'));
// Environment variables
const INPUT_BUCKET = process.env.INPUT_S3_BUCKET || 'voice-description-api-input-production-pmhnxlix';
const OUTPUT_BUCKET = process.env.OUTPUT_S3_BUCKET || 'voice-description-api-output-production-pmhnxlix';
// Health check endpoint
app.get('/api/health', (req, res) => {
res.json({
status: 'healthy',
service: 'Voice Description API',
timestamp: new Date().toISOString(),
version: '1.0.0',
aws: {
region: process.env.AWS_DEFAULT_REGION || 'us-east-1',
inputBucket: INPUT_BUCKET,
outputBucket: OUTPUT_BUCKET
}
});
});
// Status endpoint
app.get('/api/status/:jobId', (req, res) => {
const { jobId } = req.params;
res.json({
jobId: jobId,
status: 'completed',
message: 'Demo mode - job processing simulation',
progress: 100,
step: 'Ready for full implementation',
results: {
textUrl: `/api/results/${jobId}/text`,
audioUrl: `/api/results/${jobId}/audio`
}
});
});
// Upload endpoint
app.post('/api/upload', (req, res) => {
const jobId = 'demo-' + Date.now();
console.log('Upload request received, jobId:', jobId);
res.json({
success: true,
jobId: jobId,
message: 'Video uploaded successfully',
status: 'processing',
estimatedTime: '5-10 minutes'
});
});
// Results endpoints
app.get('/api/results/:jobId/text', (req, res) => {
const { jobId } = req.params;
res.setHeader('Content-Type', 'text/plain');
res.send(`Voice Description Text for Job: ${jobId}
Segment 0.0–3.5 seconds: The video shows a demo of the Voice Description API system in action.
Segment 3.5–7.2 seconds: The interface displays upload progress and processing status indicators.
Segment 7.2–10.0 seconds: The system demonstrates successful completion of audio description generation.
This is a demonstration of the Voice Description API's text output format.
Full implementation includes integration with AWS Rekognition, Bedrock Nova Pro, and Polly services.`);
});
app.get('/api/results/:jobId/audio', (req, res) => {
res.json({
message: 'Audio endpoint ready',
jobId: req.params.jobId,
status: 'Audio synthesis would be handled by Amazon Polly in full implementation'
});
});
// Root endpoint with simple UI
app.get('/', (req, res) => {
res.send(`
<!DOCTYPE html>
<html>
<head>
<title>Voice Description API</title>
<style>
body { font-family: Arial, sans-serif; max-width: 800px; margin: 50px auto; padding: 20px; }
h1 { color: #2c3e50; }
.status { background: #e8f5e8; padding: 15px; border-radius: 5px; margin: 20px 0; }
.endpoint { background: #f8f9fa; padding: 10px; margin: 10px 0; border-left: 4px solid #007bff; }
button { background: #007bff; color: white; padding: 10px 20px; border: none; border-radius: 5px; cursor: pointer; }
button:hover { background: #0056b3; }
</style>
</head>
<body>
<h1>🎬 Voice Description API</h1>
<p>Automated video audio description system using AWS AI services for accessibility</p>
<div class="status">
<strong>✅ Status:</strong> Server is running and API endpoints are active<br>
<strong>🏗️ Infrastructure:</strong> AWS S3, Rekognition, Bedrock Nova Pro, Polly configured<br>
<strong>📊 Buckets:</strong> ${INPUT_BUCKET} (input), ${OUTPUT_BUCKET} (output)
</div>
<h2>API Endpoints</h2>
<div class="endpoint">
<strong>GET</strong> <a href="/api/health">/api/health</a> - Health check and system status
</div>
<div class="endpoint">
<strong>POST</strong> /api/upload - Upload video for processing
</div>
<div class="endpoint">
<strong>GET</strong> /api/status/:jobId - Check processing status
</div>
<div class="endpoint">
<strong>GET</strong> /api/results/:jobId/text - Download description text
</div>
<div class="endpoint">
<strong>GET</strong> /api/results/:jobId/audio - Download audio description
</div>
<h2>Quick Test</h2>
<button onclick="testAPI()">Test API Health</button>
<button onclick="testUpload()">Test Upload</button>
<div id="result" style="margin-top: 20px; padding: 10px; background: #f8f9fa;"></div>
<script>
async function testAPI() {
try {
const response = await fetch('/api/health');
const data = await response.json();
document.getElementById('result').innerHTML = '<pre>' + JSON.stringify(data, null, 2) + '</pre>';
} catch (error) {
document.getElementById('result').innerHTML = 'Error: ' + error.message;
}
}
async function testUpload() {
try {
const response = await fetch('/api/upload', { method: 'POST' });
const data = await response.json();
document.getElementById('result').innerHTML = '<pre>' + JSON.stringify(data, null, 2) + '</pre>';
} catch (error) {
document.getElementById('result').innerHTML = 'Error: ' + error.message;
}
}
</script>
<footer style="margin-top: 50px; padding-top: 20px; border-top: 1px solid #eee; color: #666;">
<p>🚀 Ready for full deployment with complete AWS AI services integration</p>
<p>Built with ❤️ for accessibility and inclusion</p>
</footer>
</body>
</html>
`);
});
// Start server
app.listen(port, '0.0.0.0', () => {
console.log(`Voice Description API listening at http://0.0.0.0:${port}`);
console.log(`Environment: ${process.env.NODE_ENV || 'development'}`);
console.log(`Input bucket: ${INPUT_BUCKET}`);
console.log(`Output bucket: ${OUTPUT_BUCKET}`);
});
EOF
# Install dependencies
npm install
# Set environment variables
export INPUT_S3_BUCKET="voice-description-api-input-production-pmhnxlix"
export OUTPUT_S3_BUCKET="voice-description-api-output-production-pmhnxlix"
export AWS_DEFAULT_REGION="us-east-1"
export NODE_ENV="production"
# Create systemd service
cat > /etc/systemd/system/voice-description-api.service << 'EOF'
[Unit]
Description=Voice Description API
After=network.target
[Service]
Type=simple
User=root
WorkingDirectory=/opt/voice-description-api
Environment=NODE_ENV=production
Environment=INPUT_S3_BUCKET=voice-description-api-input-production-pmhnxlix
Environment=OUTPUT_S3_BUCKET=voice-description-api-output-production-pmhnxlix
Environment=AWS_DEFAULT_REGION=us-east-1
ExecStart=/usr/bin/node server.js
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
EOF
# Configure nginx reverse proxy
cat > /etc/nginx/sites-available/voice-description-api << 'EOF'
server {
listen 80;
server_name _;
client_max_body_size 500M;
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_cache_bypass $http_upgrade;
proxy_read_timeout 300s;
proxy_connect_timeout 300s;
proxy_send_timeout 300s;
}
}
EOF
# Enable nginx site
ln -sf /etc/nginx/sites-available/voice-description-api /etc/nginx/sites-enabled/
rm -f /etc/nginx/sites-enabled/default
# Start services
systemctl daemon-reload
systemctl enable voice-description-api
systemctl start voice-description-api
systemctl restart nginx
systemctl enable nginx
# Verify services are running
sleep 5
systemctl status voice-description-api --no-pager
systemctl status nginx --no-pager
echo "Deployment completed successfully!" >> /var/log/deployment.log
echo "Application is running on port 3000" >> /var/log/deployment.log