|
112 | 112 | "Required variables:\n", |
113 | 113 | "- `ELEVENLABS_API_KEY`: Your ElevenLabs API key\n", |
114 | 114 | "- `NVIDIA_API_KEY`: Your NVIDIA API key\n", |
115 | | - "- `MAX_CONCURRENT_REQUESTS`: Number of concurrent requests allowed (recommended: 1 for local development)\n", |
| 115 | + "- `MAX_CONCURRENT_REQUESTS` = Number of concurrent requests allowed (recommended: 1 for local development)\n", |
116 | 116 | "\n", |
117 | 117 | "> **Note**: While production environments use the NVIDIA Eleven Labs API key which supports concurrent requests, for local development we recommend setting `MAX_CONCURRENT_REQUESTS=1` to avoid rate limiting issues. You can obtain a free testing API key from [ElevenLabs](https://elevenlabs.io).\n", |
118 | 118 | "\n", |
119 | | - "Run the code cell below to create your `.env` file. Make sure to replace the placeholder values with your actual API keys." |
| 119 | + "Run the code cell below to create your `.env` file. Make sure to update variables `ELEVENLABS_API_KEY` and `NVIDIA_API_KEY`. " |
120 | 120 | ] |
121 | 121 | }, |
122 | 122 | { |
|
126 | 126 | "metadata": {}, |
127 | 127 | "outputs": [], |
128 | 128 | "source": [ |
129 | | - "%%bash\n", |
| 129 | + "%%bash \n", |
130 | 130 | "\n", |
131 | 131 | "cd pdf-to-podcast/\n", |
132 | 132 | "\n", |
|
138 | 138 | "\n", |
139 | 139 | "# Create new .env file\n", |
140 | 140 | "cat > .env << EOL\n", |
141 | | - "ELEVENLABS_API_KEY=<ENTER-KEY>\n", |
142 | | - "NVIDIA_API_KEY=<ENTER_KEY>\n", |
| 141 | + "ELEVENLABS_API_KEY=$ELEVENLABS_API_KEY\n", |
| 142 | + "NVIDIA_API_KEY=$NVIDIA_API_KEY\n", |
143 | 143 | "MAX_CONCURRENT_REQUESTS=1\n", |
144 | 144 | "EOL\n", |
145 | 145 | "\n", |
146 | 146 | "echo \"Created .env file. Please edit it with your actual API keys.\"\n", |
147 | | - "echo -e \"\\nCurrent .env contents:\"\n", |
148 | | - "echo \"----------------------------------------\"\n", |
149 | | - "cat .env" |
| 147 | + "echo \"----------------------------------------\"" |
150 | 148 | ] |
151 | 149 | }, |
152 | 150 | { |
|
171 | 169 | "%%bash\n", |
172 | 170 | "\n", |
173 | 171 | "cd pdf-to-podcast/\n", |
174 | | - "\n", |
175 | 172 | "make uv" |
176 | 173 | ] |
177 | 174 | }, |
|
188 | 185 | "```\n", |
189 | 186 | "cd pdf-to-podcast/\n", |
190 | 187 | "make all-services\n", |
191 | | - "```" |
| 188 | + "```\n", |
| 189 | + "Or Run below command for starting services in detach mode" |
| 190 | + ] |
| 191 | + }, |
| 192 | + { |
| 193 | + "cell_type": "code", |
| 194 | + "execution_count": null, |
| 195 | + "id": "44fb2da5", |
| 196 | + "metadata": {}, |
| 197 | + "outputs": [], |
| 198 | + "source": [ |
| 199 | + "%%bash\n", |
| 200 | + "\n", |
| 201 | + "cd pdf-to-podcast/\n", |
| 202 | + "make all-services DETACH=1\n", |
| 203 | + "\n", |
| 204 | + "wait_for_services() {\n", |
| 205 | + " local max_wait_time=$1 # Max wait time in seconds\n", |
| 206 | + " local check_interval=$2 # Interval to check in seconds\n", |
| 207 | + "\n", |
| 208 | + " local elapsed_time=0\n", |
| 209 | + "\n", |
| 210 | + " while [ $elapsed_time -lt $max_wait_time ]; do\n", |
| 211 | + " # Check if any containers are up\n", |
| 212 | + " if docker-compose ps | grep -q \"Up\"; then\n", |
| 213 | + " echo \"Services are up and running!\"\n", |
| 214 | + " return 0 # Return success if services are up\n", |
| 215 | + " fi\n", |
| 216 | + " # Wait for the next check interval\n", |
| 217 | + " sleep $check_interval\n", |
| 218 | + " elapsed_time=$((elapsed_time + check_interval))\n", |
| 219 | + " echo \"Waiting for services to come up... $((elapsed_time / 60)) min elapsed\"\n", |
| 220 | + " done\n", |
| 221 | + "\n", |
| 222 | + " # If max wait time is reached and services are not up, print a timeout message\n", |
| 223 | + " echo \"Timeout reached. Services did not come up in $((max_wait_time / 60)) minutes.\"\n", |
| 224 | + " return 1 # Return failure if services did not come up in time\n", |
| 225 | + "}\n", |
| 226 | + "\n", |
| 227 | + "# Maximum wait time in seconds (15 minutes)\n", |
| 228 | + "MAX_WAIT_TIME=900 # 15 minutes\n", |
| 229 | + "CHECK_INTERVAL=10 # Check every 10 seconds\n", |
| 230 | + "\n", |
| 231 | + "# Call the function\n", |
| 232 | + "wait_for_services $MAX_WAIT_TIME $CHECK_INTERVAL" |
192 | 233 | ] |
193 | 234 | }, |
194 | 235 | { |
|
198 | 239 | "metadata": {}, |
199 | 240 | "outputs": [], |
200 | 241 | "source": [ |
201 | | - "!docker ps --format \"table {{.ID}}\\t{{.Names}}\\t{{.Status}}\"" |
| 242 | + "%%bash\n", |
| 243 | + "docker ps --format \"table {{.ID}}\\t{{.Names}}\\t{{.Status}}\"" |
202 | 244 | ] |
203 | 245 | }, |
204 | 246 | { |
|
237 | 279 | "metadata": {}, |
238 | 280 | "outputs": [], |
239 | 281 | "source": [ |
240 | | - "!curl localhost:8002/health" |
| 282 | + "import requests\n", |
| 283 | + "\n", |
| 284 | + "def make_request(url, params=None, headers=None):\n", |
| 285 | + "\n", |
| 286 | + " try:\n", |
| 287 | + " # Send GET request with optional parameters and headers\n", |
| 288 | + " response = requests.get(url, params=params, headers=headers)\n", |
| 289 | + " \n", |
| 290 | + " # Check if the request was successful (status code 200)\n", |
| 291 | + " if response.status_code != 200:\n", |
| 292 | + " raise Exception(f\"Request failed with status code {response.status_code}. Response: {response.text}\")\n", |
| 293 | + " \n", |
| 294 | + " # Return the response object if successful\n", |
| 295 | + " return response\n", |
| 296 | + " \n", |
| 297 | + " except requests.exceptions.RequestException as e:\n", |
| 298 | + " print(f\"Error occurred during the request: {e}\")\n", |
| 299 | + " raise Exception(f\"Request failed: {e}\")\n", |
| 300 | + "\n", |
| 301 | + "response = make_request(\"http://localhost:8002/health\")\n", |
| 302 | + "print(response.text)" |
241 | 303 | ] |
242 | 304 | }, |
243 | 305 | { |
|
475 | 537 | "metadata": {}, |
476 | 538 | "outputs": [], |
477 | 539 | "source": [ |
478 | | - "!curl \"localhost:8002/output/{job_id}?userId=test-userid\" --output temp_audio.mp3\n", |
| 540 | + "response = make_request(f\"http://localhost:8002/output/{job_id}?userId=test-userid\")\n", |
| 541 | + "if response.content:\n", |
| 542 | + " with open(\"temp_audio.mp3\", 'wb') as f:\n", |
| 543 | + " f.write(response.content)\n", |
| 544 | + " print(\"MP3 file saved successfully as temp_audio.mp3\")\n", |
| 545 | + "else:\n", |
| 546 | + " print(\"No content received in the response.\")\n", |
479 | 547 | "Audio(\"temp_audio.mp3\")" |
480 | 548 | ] |
481 | 549 | }, |
|
508 | 576 | "metadata": {}, |
509 | 577 | "outputs": [], |
510 | 578 | "source": [ |
511 | | - "!curl \"localhost:8002/saved_podcast/{job_id}/transcript?userId=test-userid\"" |
| 579 | + "response = make_request(f\"http://localhost:8002/saved_podcast/{job_id}/transcript?userId=test-userid\")\n", |
| 580 | + "print(response.text)" |
512 | 581 | ] |
513 | 582 | }, |
514 | 583 | { |
|
544 | 613 | }, |
545 | 614 | "outputs": [], |
546 | 615 | "source": [ |
547 | | - "!curl \"localhost:8002/saved_podcast/{job_id}/history?userId=test-userid\"" |
| 616 | + "response = make_request(f\"http://localhost:8002/saved_podcast/{job_id}/history?userId=test-userid\")\n", |
| 617 | + "print(response.text)\n" |
548 | 618 | ] |
549 | 619 | }, |
550 | 620 | { |
|
554 | 624 | "metadata": {}, |
555 | 625 | "outputs": [], |
556 | 626 | "source": [ |
557 | | - "!curl \"localhost:8002/saved_podcast/{job_id}/metadata?userId=test-userid\"" |
| 627 | + "response = make_request(f\"http://localhost:8002/saved_podcast/{job_id}/metadata?userId=test-userid\")\n", |
| 628 | + "print(response.text)\n" |
558 | 629 | ] |
559 | 630 | }, |
560 | 631 | { |
|
0 commit comments