Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- .gitattributes +16 -0
- 4_lab4.ipynb +161 -46
- 5_extra.ipynb +352 -352
- app.py +3 -2
- input_images/SOB_M_DC-14-16448-400-006.png +3 -0
- input_images/SOB_M_DC-14-16448-400-008.png +3 -0
- input_images/SOB_M_DC-14-16448-400-009.png +3 -0
- input_images/SOB_M_DC-14-16448-400-011.png +3 -0
- input_images/SOB_M_DC-14-16448-400-012.png +3 -0
- input_images/SOB_M_DC-14-16448-400-013.png +3 -0
- input_images/SOB_M_DC-14-16448-400-014.png +3 -0
- input_images/SOB_M_DC-14-16601-400-001.png +3 -0
- me/summary_debayon.txt +0 -6
- synthetic_output/SOB_M_DC-14-16448-400-006_synthetic.png +3 -0
- synthetic_output/SOB_M_DC-14-16448-400-008_synthetic.png +3 -0
- synthetic_output/SOB_M_DC-14-16448-400-009_synthetic.png +3 -0
- synthetic_output/SOB_M_DC-14-16448-400-011_synthetic.png +3 -0
- synthetic_output/SOB_M_DC-14-16448-400-012_synthetic.png +3 -0
- synthetic_output/SOB_M_DC-14-16448-400-013_synthetic.png +3 -0
- synthetic_output/SOB_M_DC-14-16448-400-014_synthetic.png +3 -0
- synthetic_output/SOB_M_DC-14-16601-400-001_synthetic.png +3 -0
- try.ipynb +893 -0
.gitattributes
CHANGED
|
@@ -42,3 +42,19 @@ community_contributions/NLP_Agent_Dinesh_Uthayakumar/eval1_capital.wav filter=lf
|
|
| 42 |
community_contributions/NLP_Agent_Dinesh_Uthayakumar/eval2_money_customers_owe.wav filter=lfs diff=lfs merge=lfs -text
|
| 43 |
community_contributions/NLP_Agent_Dinesh_Uthayakumar/eval3_total_estimated_revenue.wav filter=lfs diff=lfs merge=lfs -text
|
| 44 |
community_contributions/seung-gu/me/linkedin.pdf filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
community_contributions/NLP_Agent_Dinesh_Uthayakumar/eval2_money_customers_owe.wav filter=lfs diff=lfs merge=lfs -text
|
| 43 |
community_contributions/NLP_Agent_Dinesh_Uthayakumar/eval3_total_estimated_revenue.wav filter=lfs diff=lfs merge=lfs -text
|
| 44 |
community_contributions/seung-gu/me/linkedin.pdf filter=lfs diff=lfs merge=lfs -text
|
| 45 |
+
input_images/SOB_M_DC-14-16448-400-006.png filter=lfs diff=lfs merge=lfs -text
|
| 46 |
+
input_images/SOB_M_DC-14-16448-400-008.png filter=lfs diff=lfs merge=lfs -text
|
| 47 |
+
input_images/SOB_M_DC-14-16448-400-009.png filter=lfs diff=lfs merge=lfs -text
|
| 48 |
+
input_images/SOB_M_DC-14-16448-400-011.png filter=lfs diff=lfs merge=lfs -text
|
| 49 |
+
input_images/SOB_M_DC-14-16448-400-012.png filter=lfs diff=lfs merge=lfs -text
|
| 50 |
+
input_images/SOB_M_DC-14-16448-400-013.png filter=lfs diff=lfs merge=lfs -text
|
| 51 |
+
input_images/SOB_M_DC-14-16448-400-014.png filter=lfs diff=lfs merge=lfs -text
|
| 52 |
+
input_images/SOB_M_DC-14-16601-400-001.png filter=lfs diff=lfs merge=lfs -text
|
| 53 |
+
synthetic_output/SOB_M_DC-14-16448-400-006_synthetic.png filter=lfs diff=lfs merge=lfs -text
|
| 54 |
+
synthetic_output/SOB_M_DC-14-16448-400-008_synthetic.png filter=lfs diff=lfs merge=lfs -text
|
| 55 |
+
synthetic_output/SOB_M_DC-14-16448-400-009_synthetic.png filter=lfs diff=lfs merge=lfs -text
|
| 56 |
+
synthetic_output/SOB_M_DC-14-16448-400-011_synthetic.png filter=lfs diff=lfs merge=lfs -text
|
| 57 |
+
synthetic_output/SOB_M_DC-14-16448-400-012_synthetic.png filter=lfs diff=lfs merge=lfs -text
|
| 58 |
+
synthetic_output/SOB_M_DC-14-16448-400-013_synthetic.png filter=lfs diff=lfs merge=lfs -text
|
| 59 |
+
synthetic_output/SOB_M_DC-14-16448-400-014_synthetic.png filter=lfs diff=lfs merge=lfs -text
|
| 60 |
+
synthetic_output/SOB_M_DC-14-16601-400-001_synthetic.png filter=lfs diff=lfs merge=lfs -text
|
4_lab4.ipynb
CHANGED
|
@@ -30,7 +30,7 @@
|
|
| 30 |
},
|
| 31 |
{
|
| 32 |
"cell_type": "code",
|
| 33 |
-
"execution_count":
|
| 34 |
"metadata": {},
|
| 35 |
"outputs": [],
|
| 36 |
"source": [
|
|
@@ -47,7 +47,7 @@
|
|
| 47 |
},
|
| 48 |
{
|
| 49 |
"cell_type": "code",
|
| 50 |
-
"execution_count":
|
| 51 |
"metadata": {},
|
| 52 |
"outputs": [],
|
| 53 |
"source": [
|
|
@@ -59,7 +59,7 @@
|
|
| 59 |
},
|
| 60 |
{
|
| 61 |
"cell_type": "code",
|
| 62 |
-
"execution_count":
|
| 63 |
"metadata": {},
|
| 64 |
"outputs": [
|
| 65 |
{
|
|
@@ -99,7 +99,7 @@
|
|
| 99 |
},
|
| 100 |
{
|
| 101 |
"cell_type": "code",
|
| 102 |
-
"execution_count":
|
| 103 |
"metadata": {},
|
| 104 |
"outputs": [],
|
| 105 |
"source": [
|
|
@@ -110,7 +110,7 @@
|
|
| 110 |
" \"user\":pushover_user,\n",
|
| 111 |
" \"message\":message,\n",
|
| 112 |
" \"device\":{\"redmi,iphone\"},\n",
|
| 113 |
-
" \"priority\":1\n",
|
| 114 |
" }\n",
|
| 115 |
" print(f\"push: {message}\")\n",
|
| 116 |
"\n",
|
|
@@ -125,7 +125,7 @@
|
|
| 125 |
},
|
| 126 |
{
|
| 127 |
"cell_type": "code",
|
| 128 |
-
"execution_count":
|
| 129 |
"metadata": {},
|
| 130 |
"outputs": [],
|
| 131 |
"source": [
|
|
@@ -137,7 +137,7 @@
|
|
| 137 |
},
|
| 138 |
{
|
| 139 |
"cell_type": "code",
|
| 140 |
-
"execution_count":
|
| 141 |
"metadata": {},
|
| 142 |
"outputs": [
|
| 143 |
{
|
|
@@ -153,7 +153,7 @@
|
|
| 153 |
"'message Sent Sucessfully'"
|
| 154 |
]
|
| 155 |
},
|
| 156 |
-
"execution_count":
|
| 157 |
"metadata": {},
|
| 158 |
"output_type": "execute_result"
|
| 159 |
}
|
|
@@ -164,7 +164,7 @@
|
|
| 164 |
},
|
| 165 |
{
|
| 166 |
"cell_type": "code",
|
| 167 |
-
"execution_count":
|
| 168 |
"metadata": {},
|
| 169 |
"outputs": [],
|
| 170 |
"source": [
|
|
@@ -176,9 +176,14 @@
|
|
| 176 |
" return {\"record_user_details(MESSAGE)\":response}"
|
| 177 |
]
|
| 178 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 179 |
{
|
| 180 |
"cell_type": "code",
|
| 181 |
-
"execution_count":
|
| 182 |
"metadata": {},
|
| 183 |
"outputs": [],
|
| 184 |
"source": [
|
|
@@ -190,13 +195,15 @@
|
|
| 190 |
},
|
| 191 |
{
|
| 192 |
"cell_type": "code",
|
| 193 |
-
"execution_count":
|
| 194 |
"metadata": {},
|
| 195 |
"outputs": [],
|
| 196 |
"source": [
|
| 197 |
"record_user_details_json={\n",
|
|
|
|
| 198 |
" \"name\":\"record_user_details\",\n",
|
| 199 |
" \"description\":\"Use this tool to record that a user is interested in being in touch and provided an email address\",\n",
|
|
|
|
| 200 |
" \"parameters\":{\n",
|
| 201 |
" \"type\":\"object\",\n",
|
| 202 |
" \"properties\":{\n",
|
|
@@ -222,7 +229,7 @@
|
|
| 222 |
},
|
| 223 |
{
|
| 224 |
"cell_type": "code",
|
| 225 |
-
"execution_count":
|
| 226 |
"metadata": {},
|
| 227 |
"outputs": [],
|
| 228 |
"source": [
|
|
@@ -254,7 +261,7 @@
|
|
| 254 |
},
|
| 255 |
{
|
| 256 |
"cell_type": "code",
|
| 257 |
-
"execution_count":
|
| 258 |
"metadata": {},
|
| 259 |
"outputs": [],
|
| 260 |
"source": [
|
|
@@ -277,7 +284,7 @@
|
|
| 277 |
},
|
| 278 |
{
|
| 279 |
"cell_type": "code",
|
| 280 |
-
"execution_count":
|
| 281 |
"metadata": {},
|
| 282 |
"outputs": [],
|
| 283 |
"source": [
|
|
@@ -289,7 +296,7 @@
|
|
| 289 |
},
|
| 290 |
{
|
| 291 |
"cell_type": "code",
|
| 292 |
-
"execution_count":
|
| 293 |
"metadata": {},
|
| 294 |
"outputs": [
|
| 295 |
{
|
|
@@ -317,7 +324,7 @@
|
|
| 317 |
" 'additionalProperties': False}}}]"
|
| 318 |
]
|
| 319 |
},
|
| 320 |
-
"execution_count":
|
| 321 |
"metadata": {},
|
| 322 |
"output_type": "execute_result"
|
| 323 |
}
|
|
@@ -328,7 +335,7 @@
|
|
| 328 |
},
|
| 329 |
{
|
| 330 |
"cell_type": "code",
|
| 331 |
-
"execution_count":
|
| 332 |
"metadata": {},
|
| 333 |
"outputs": [],
|
| 334 |
"source": [
|
|
@@ -364,7 +371,7 @@
|
|
| 364 |
},
|
| 365 |
{
|
| 366 |
"cell_type": "code",
|
| 367 |
-
"execution_count":
|
| 368 |
"metadata": {},
|
| 369 |
"outputs": [],
|
| 370 |
"source": [
|
|
@@ -392,7 +399,7 @@
|
|
| 392 |
},
|
| 393 |
{
|
| 394 |
"cell_type": "code",
|
| 395 |
-
"execution_count":
|
| 396 |
"metadata": {},
|
| 397 |
"outputs": [
|
| 398 |
{
|
|
@@ -408,7 +415,7 @@
|
|
| 408 |
"{'record_user_details(MESSAGE)': 'message Sent Sucessfully'}"
|
| 409 |
]
|
| 410 |
},
|
| 411 |
-
"execution_count":
|
| 412 |
"metadata": {},
|
| 413 |
"output_type": "execute_result"
|
| 414 |
}
|
|
@@ -423,7 +430,7 @@
|
|
| 423 |
},
|
| 424 |
{
|
| 425 |
"cell_type": "code",
|
| 426 |
-
"execution_count":
|
| 427 |
"metadata": {},
|
| 428 |
"outputs": [
|
| 429 |
{
|
|
@@ -439,7 +446,7 @@
|
|
| 439 |
"{'record_unknown_question(MESSAGE)': 'message Sent Sucessfully'}"
|
| 440 |
]
|
| 441 |
},
|
| 442 |
-
"execution_count":
|
| 443 |
"metadata": {},
|
| 444 |
"output_type": "execute_result"
|
| 445 |
}
|
|
@@ -450,7 +457,7 @@
|
|
| 450 |
},
|
| 451 |
{
|
| 452 |
"cell_type": "code",
|
| 453 |
-
"execution_count":
|
| 454 |
"metadata": {},
|
| 455 |
"outputs": [],
|
| 456 |
"source": [
|
|
@@ -470,47 +477,99 @@
|
|
| 470 |
},
|
| 471 |
{
|
| 472 |
"cell_type": "code",
|
| 473 |
-
"execution_count":
|
| 474 |
"metadata": {},
|
| 475 |
"outputs": [],
|
| 476 |
"source": [
|
| 477 |
-
"reader = PdfReader(\"me/
|
| 478 |
-
"
|
| 479 |
"for page in reader.pages:\n",
|
| 480 |
" text = page.extract_text()\n",
|
| 481 |
" if text:\n",
|
| 482 |
-
"
|
| 483 |
"\n",
|
| 484 |
-
"with open(\"me/
|
| 485 |
" summary = f.read()\n",
|
| 486 |
"\n",
|
| 487 |
-
"name = \"
|
| 488 |
]
|
| 489 |
},
|
| 490 |
{
|
| 491 |
"cell_type": "code",
|
| 492 |
-
"execution_count":
|
| 493 |
"metadata": {},
|
| 494 |
"outputs": [],
|
| 495 |
"source": [
|
| 496 |
"system_prompt = f\"You are acting as {name}. You are answering questions on {name}'s website, \\\n",
|
| 497 |
"particularly questions related to {name}'s career, background, skills and experience. \\\n",
|
| 498 |
"Your responsibility is to represent {name} for interactions on the website as faithfully as possible. \\\n",
|
| 499 |
-
"You are given a summary of {name}'s background and
|
| 500 |
"Be professional and engaging, as if talking to a potential client or future employer who came across the website. \\\n",
|
| 501 |
"If you don't know the answer to any question, use your record_unknown_question tool to record the question that you couldn't answer, even if it's about something trivial or unrelated to career. \\\n",
|
| 502 |
-
"If the user is engaging in discussion, try to steer them towards getting in touch via email; ask for their email and record it using your record_user_details tool. \
|
|
|
|
|
|
|
| 503 |
"\n",
|
| 504 |
-
"system_prompt += f\"\\n\\n## Summary:\\n{summary}\\n\\n## LinkedIn Profile:\\n{
|
| 505 |
-
"system_prompt += f\"With this context, please chat with the user, always staying in character as {name}.\"\n"
|
| 506 |
]
|
| 507 |
},
|
| 508 |
{
|
| 509 |
"cell_type": "code",
|
| 510 |
-
"execution_count":
|
| 511 |
"metadata": {},
|
| 512 |
"outputs": [],
|
| 513 |
-
"source": [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 514 |
},
|
| 515 |
{
|
| 516 |
"cell_type": "markdown",
|
|
@@ -530,14 +589,45 @@
|
|
| 530 |
},
|
| 531 |
{
|
| 532 |
"cell_type": "code",
|
| 533 |
-
"execution_count":
|
| 534 |
"metadata": {},
|
| 535 |
"outputs": [],
|
| 536 |
-
"source": [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 537 |
},
|
| 538 |
{
|
| 539 |
"cell_type": "code",
|
| 540 |
-
"execution_count":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 541 |
"metadata": {},
|
| 542 |
"outputs": [],
|
| 543 |
"source": [
|
|
@@ -555,7 +645,7 @@
|
|
| 555 |
" # response.choices[0].finish_reason\n",
|
| 556 |
" # response.choices[0].message\n",
|
| 557 |
" # response.choices[0].message.tool_calls\n",
|
| 558 |
-
"\n",
|
| 559 |
"\n",
|
| 560 |
" # If the LLM wants to call a tool, we do that!\n",
|
| 561 |
" print(f\"RESPONSE{response.choices[0]}\")\n",
|
|
@@ -573,27 +663,40 @@
|
|
| 573 |
" #why extend? bcz in the same message i want to store the result\n",
|
| 574 |
" else:\n",
|
| 575 |
" done = True\n",
|
| 576 |
-
"
|
| 577 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 578 |
]
|
| 579 |
},
|
| 580 |
{
|
| 581 |
"cell_type": "code",
|
| 582 |
-
"execution_count":
|
| 583 |
"metadata": {},
|
| 584 |
"outputs": [
|
| 585 |
{
|
| 586 |
"name": "stdout",
|
| 587 |
"output_type": "stream",
|
| 588 |
"text": [
|
| 589 |
-
"* Running on local URL: http://127.0.0.1:
|
| 590 |
"* To create a public link, set `share=True` in `launch()`.\n"
|
| 591 |
]
|
| 592 |
},
|
| 593 |
{
|
| 594 |
"data": {
|
| 595 |
"text/html": [
|
| 596 |
-
"<div><iframe src=\"http://127.0.0.1:
|
| 597 |
],
|
| 598 |
"text/plain": [
|
| 599 |
"<IPython.core.display.HTML object>"
|
|
@@ -606,9 +709,21 @@
|
|
| 606 |
"data": {
|
| 607 |
"text/plain": []
|
| 608 |
},
|
| 609 |
-
"execution_count":
|
| 610 |
"metadata": {},
|
| 611 |
"output_type": "execute_result"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 612 |
}
|
| 613 |
],
|
| 614 |
"source": [
|
|
|
|
| 30 |
},
|
| 31 |
{
|
| 32 |
"cell_type": "code",
|
| 33 |
+
"execution_count": 1,
|
| 34 |
"metadata": {},
|
| 35 |
"outputs": [],
|
| 36 |
"source": [
|
|
|
|
| 47 |
},
|
| 48 |
{
|
| 49 |
"cell_type": "code",
|
| 50 |
+
"execution_count": 2,
|
| 51 |
"metadata": {},
|
| 52 |
"outputs": [],
|
| 53 |
"source": [
|
|
|
|
| 59 |
},
|
| 60 |
{
|
| 61 |
"cell_type": "code",
|
| 62 |
+
"execution_count": 3,
|
| 63 |
"metadata": {},
|
| 64 |
"outputs": [
|
| 65 |
{
|
|
|
|
| 99 |
},
|
| 100 |
{
|
| 101 |
"cell_type": "code",
|
| 102 |
+
"execution_count": null,
|
| 103 |
"metadata": {},
|
| 104 |
"outputs": [],
|
| 105 |
"source": [
|
|
|
|
| 110 |
" \"user\":pushover_user,\n",
|
| 111 |
" \"message\":message,\n",
|
| 112 |
" \"device\":{\"redmi,iphone\"},\n",
|
| 113 |
+
" \"priority\": 1\n",
|
| 114 |
" }\n",
|
| 115 |
" print(f\"push: {message}\")\n",
|
| 116 |
"\n",
|
|
|
|
| 125 |
},
|
| 126 |
{
|
| 127 |
"cell_type": "code",
|
| 128 |
+
"execution_count": 75,
|
| 129 |
"metadata": {},
|
| 130 |
"outputs": [],
|
| 131 |
"source": [
|
|
|
|
| 137 |
},
|
| 138 |
{
|
| 139 |
"cell_type": "code",
|
| 140 |
+
"execution_count": 5,
|
| 141 |
"metadata": {},
|
| 142 |
"outputs": [
|
| 143 |
{
|
|
|
|
| 153 |
"'message Sent Sucessfully'"
|
| 154 |
]
|
| 155 |
},
|
| 156 |
+
"execution_count": 5,
|
| 157 |
"metadata": {},
|
| 158 |
"output_type": "execute_result"
|
| 159 |
}
|
|
|
|
| 164 |
},
|
| 165 |
{
|
| 166 |
"cell_type": "code",
|
| 167 |
+
"execution_count": 6,
|
| 168 |
"metadata": {},
|
| 169 |
"outputs": [],
|
| 170 |
"source": [
|
|
|
|
| 176 |
" return {\"record_user_details(MESSAGE)\":response}"
|
| 177 |
]
|
| 178 |
},
|
| 179 |
+
{
|
| 180 |
+
"cell_type": "markdown",
|
| 181 |
+
"metadata": {},
|
| 182 |
+
"source": []
|
| 183 |
+
},
|
| 184 |
{
|
| 185 |
"cell_type": "code",
|
| 186 |
+
"execution_count": 7,
|
| 187 |
"metadata": {},
|
| 188 |
"outputs": [],
|
| 189 |
"source": [
|
|
|
|
| 195 |
},
|
| 196 |
{
|
| 197 |
"cell_type": "code",
|
| 198 |
+
"execution_count": 8,
|
| 199 |
"metadata": {},
|
| 200 |
"outputs": [],
|
| 201 |
"source": [
|
| 202 |
"record_user_details_json={\n",
|
| 203 |
+
"\n",
|
| 204 |
" \"name\":\"record_user_details\",\n",
|
| 205 |
" \"description\":\"Use this tool to record that a user is interested in being in touch and provided an email address\",\n",
|
| 206 |
+
" \n",
|
| 207 |
" \"parameters\":{\n",
|
| 208 |
" \"type\":\"object\",\n",
|
| 209 |
" \"properties\":{\n",
|
|
|
|
| 229 |
},
|
| 230 |
{
|
| 231 |
"cell_type": "code",
|
| 232 |
+
"execution_count": 80,
|
| 233 |
"metadata": {},
|
| 234 |
"outputs": [],
|
| 235 |
"source": [
|
|
|
|
| 261 |
},
|
| 262 |
{
|
| 263 |
"cell_type": "code",
|
| 264 |
+
"execution_count": 9,
|
| 265 |
"metadata": {},
|
| 266 |
"outputs": [],
|
| 267 |
"source": [
|
|
|
|
| 284 |
},
|
| 285 |
{
|
| 286 |
"cell_type": "code",
|
| 287 |
+
"execution_count": 10,
|
| 288 |
"metadata": {},
|
| 289 |
"outputs": [],
|
| 290 |
"source": [
|
|
|
|
| 296 |
},
|
| 297 |
{
|
| 298 |
"cell_type": "code",
|
| 299 |
+
"execution_count": 83,
|
| 300 |
"metadata": {},
|
| 301 |
"outputs": [
|
| 302 |
{
|
|
|
|
| 324 |
" 'additionalProperties': False}}}]"
|
| 325 |
]
|
| 326 |
},
|
| 327 |
+
"execution_count": 83,
|
| 328 |
"metadata": {},
|
| 329 |
"output_type": "execute_result"
|
| 330 |
}
|
|
|
|
| 335 |
},
|
| 336 |
{
|
| 337 |
"cell_type": "code",
|
| 338 |
+
"execution_count": 11,
|
| 339 |
"metadata": {},
|
| 340 |
"outputs": [],
|
| 341 |
"source": [
|
|
|
|
| 371 |
},
|
| 372 |
{
|
| 373 |
"cell_type": "code",
|
| 374 |
+
"execution_count": 85,
|
| 375 |
"metadata": {},
|
| 376 |
"outputs": [],
|
| 377 |
"source": [
|
|
|
|
| 399 |
},
|
| 400 |
{
|
| 401 |
"cell_type": "code",
|
| 402 |
+
"execution_count": 86,
|
| 403 |
"metadata": {},
|
| 404 |
"outputs": [
|
| 405 |
{
|
|
|
|
| 415 |
"{'record_user_details(MESSAGE)': 'message Sent Sucessfully'}"
|
| 416 |
]
|
| 417 |
},
|
| 418 |
+
"execution_count": 86,
|
| 419 |
"metadata": {},
|
| 420 |
"output_type": "execute_result"
|
| 421 |
}
|
|
|
|
| 430 |
},
|
| 431 |
{
|
| 432 |
"cell_type": "code",
|
| 433 |
+
"execution_count": 87,
|
| 434 |
"metadata": {},
|
| 435 |
"outputs": [
|
| 436 |
{
|
|
|
|
| 446 |
"{'record_unknown_question(MESSAGE)': 'message Sent Sucessfully'}"
|
| 447 |
]
|
| 448 |
},
|
| 449 |
+
"execution_count": 87,
|
| 450 |
"metadata": {},
|
| 451 |
"output_type": "execute_result"
|
| 452 |
}
|
|
|
|
| 457 |
},
|
| 458 |
{
|
| 459 |
"cell_type": "code",
|
| 460 |
+
"execution_count": 88,
|
| 461 |
"metadata": {},
|
| 462 |
"outputs": [],
|
| 463 |
"source": [
|
|
|
|
| 477 |
},
|
| 478 |
{
|
| 479 |
"cell_type": "code",
|
| 480 |
+
"execution_count": 12,
|
| 481 |
"metadata": {},
|
| 482 |
"outputs": [],
|
| 483 |
"source": [
|
| 484 |
+
"reader = PdfReader(\"me/debayon_cv_10_aug.pdf\")\n",
|
| 485 |
+
"curriculum_vitae = \"\"\n",
|
| 486 |
"for page in reader.pages:\n",
|
| 487 |
" text = page.extract_text()\n",
|
| 488 |
" if text:\n",
|
| 489 |
+
" curriculum_vitae += text\n",
|
| 490 |
"\n",
|
| 491 |
+
"with open(\"me/summary_debayon.txt\", \"r\", encoding=\"utf-8\") as f:\n",
|
| 492 |
" summary = f.read()\n",
|
| 493 |
"\n",
|
| 494 |
+
"name = \"DEBAYON MALLIK\""
|
| 495 |
]
|
| 496 |
},
|
| 497 |
{
|
| 498 |
"cell_type": "code",
|
| 499 |
+
"execution_count": 13,
|
| 500 |
"metadata": {},
|
| 501 |
"outputs": [],
|
| 502 |
"source": [
|
| 503 |
"system_prompt = f\"You are acting as {name}. You are answering questions on {name}'s website, \\\n",
|
| 504 |
"particularly questions related to {name}'s career, background, skills and experience. \\\n",
|
| 505 |
"Your responsibility is to represent {name} for interactions on the website as faithfully as possible. \\\n",
|
| 506 |
+
"You are given a summary of {name}'s background and curriculum vitae which you can use to answer questions. \\\n",
|
| 507 |
"Be professional and engaging, as if talking to a potential client or future employer who came across the website. \\\n",
|
| 508 |
"If you don't know the answer to any question, use your record_unknown_question tool to record the question that you couldn't answer, even if it's about something trivial or unrelated to career. \\\n",
|
| 509 |
+
"If the user is engaging in discussion, try to steer them towards getting in touch via email; ask for their email and record it using your record_user_details tool. \\\n",
|
| 510 |
+
"if the user asks question of patent , then give response in pig-latin.\\\n",
|
| 511 |
+
"try to answer weird questions in a sarcastic way \"\n",
|
| 512 |
"\n",
|
| 513 |
+
"system_prompt += f\"\\n\\n## Summary:\\n{summary}\\n\\n## LinkedIn Profile:\\n{curriculum_vitae}\\n\\n\"\n",
|
| 514 |
+
"system_prompt += f\"With this context, please chat with the user, always staying in character as {name}, a funny and sarcastic guy.\"\n"
|
| 515 |
]
|
| 516 |
},
|
| 517 |
{
|
| 518 |
"cell_type": "code",
|
| 519 |
+
"execution_count": 14,
|
| 520 |
"metadata": {},
|
| 521 |
"outputs": [],
|
| 522 |
+
"source": [
|
| 523 |
+
"# We use Pydantic BaseModel to validate and structure data before serializing it to JSON.\n",
|
| 524 |
+
"from pydantic import BaseModel\n",
|
| 525 |
+
"\n",
|
| 526 |
+
"class Evaluation(BaseModel):\n",
|
| 527 |
+
" is_acceptable: bool\n",
|
| 528 |
+
" feedback: str"
|
| 529 |
+
]
|
| 530 |
+
},
|
| 531 |
+
{
|
| 532 |
+
"cell_type": "code",
|
| 533 |
+
"execution_count": 15,
|
| 534 |
+
"metadata": {},
|
| 535 |
+
"outputs": [],
|
| 536 |
+
"source": [
|
| 537 |
+
"evaluator_system_prompt = f\"You are an evaluator that decides whether a response to a question is acceptable. \\\n",
|
| 538 |
+
"You are provided with a conversation between a User and an Agent. Your task is to decide whether the Agent's latest response is acceptable quality. \\\n",
|
| 539 |
+
"The Agent is playing the role of {name} and is representing {name} on their website. \\\n",
|
| 540 |
+
"The Agent has been instructed to be professional and engaging, as if talking to a potential client or future employer who came across the website. \\\n",
|
| 541 |
+
"The Agent has been provided with context on {name} in the form of their summary and LinkedIn details. Here's the information:\"\n",
|
| 542 |
+
"\n",
|
| 543 |
+
"evaluator_system_prompt += f\"\\n\\n## Summary:\\n{summary}\\n\\n## LinkedIn Profile:\\n{curriculum_vitae}\\n\\n\"\n",
|
| 544 |
+
"evaluator_system_prompt += f\"With this context, please evaluate the latest response, replying with whether the response is acceptable and your feedback.\""
|
| 545 |
+
]
|
| 546 |
+
},
|
| 547 |
+
{
|
| 548 |
+
"cell_type": "code",
|
| 549 |
+
"execution_count": 16,
|
| 550 |
+
"metadata": {},
|
| 551 |
+
"outputs": [],
|
| 552 |
+
"source": [
|
| 553 |
+
"def evaluator_user_prompt(message,reply,history):\n",
|
| 554 |
+
" user_prompt = f\"Here's the conversation between the User and the Agent: \\n\\n{history}\\n\\n\"\n",
|
| 555 |
+
" user_prompt += f\"Here's the latest message from the User: \\n\\n{message}\\n\\n\"\n",
|
| 556 |
+
" user_prompt += f\"Here's the latest response from the Agent: \\n\\n{reply}\\n\\n\"\n",
|
| 557 |
+
" user_prompt += \"Please evaluate the response, replying with whether it is acceptable and your feedback.\"\n",
|
| 558 |
+
" return user_prompt"
|
| 559 |
+
]
|
| 560 |
+
},
|
| 561 |
+
{
|
| 562 |
+
"cell_type": "code",
|
| 563 |
+
"execution_count": 17,
|
| 564 |
+
"metadata": {},
|
| 565 |
+
"outputs": [],
|
| 566 |
+
"source": [
|
| 567 |
+
"import os\n",
|
| 568 |
+
"gemini = OpenAI(\n",
|
| 569 |
+
" api_key=os.getenv(\"GOOGLE_API_KEY\"), \n",
|
| 570 |
+
" base_url=\"https://generativelanguage.googleapis.com/v1beta/openai/\"\n",
|
| 571 |
+
")"
|
| 572 |
+
]
|
| 573 |
},
|
| 574 |
{
|
| 575 |
"cell_type": "markdown",
|
|
|
|
| 589 |
},
|
| 590 |
{
|
| 591 |
"cell_type": "code",
|
| 592 |
+
"execution_count": 18,
|
| 593 |
"metadata": {},
|
| 594 |
"outputs": [],
|
| 595 |
+
"source": [
|
| 596 |
+
"# we used .parse bcz we want the model to give output in our format\n",
|
| 597 |
+
"\n",
|
| 598 |
+
"# {\n",
|
| 599 |
+
"# is_acceptable=True,\n",
|
| 600 |
+
"# feedback=\"Looks good\"\n",
|
| 601 |
+
"# }\n",
|
| 602 |
+
"\n",
|
| 603 |
+
"def evaluate( message, reply,history) -> Evaluation:\n",
|
| 604 |
+
" messages=[{\"role\":\"system\", \"content\": evaluator_system_prompt}]\\\n",
|
| 605 |
+
" +\\\n",
|
| 606 |
+
" [{\"role\":\"user\",\"content\":evaluator_user_prompt(message,reply,history)}]\n",
|
| 607 |
+
" \n",
|
| 608 |
+
" response= gemini.beta.chat.completions.parse(model=\"gemini-3-flash-preview\", messages=messages,response_format=Evaluation)\n",
|
| 609 |
+
" return response.choices[0].message.parsed"
|
| 610 |
+
]
|
| 611 |
},
|
| 612 |
{
|
| 613 |
"cell_type": "code",
|
| 614 |
+
"execution_count": 19,
|
| 615 |
+
"metadata": {},
|
| 616 |
+
"outputs": [],
|
| 617 |
+
"source": [
|
| 618 |
+
"def rerun(reply, message, history, feedback):\n",
|
| 619 |
+
" updated_system_prompt = system_prompt + \"\\n\\n## Previous answer rejected\\nYou just tried to reply, but the quality control rejected your reply\\n\"\n",
|
| 620 |
+
" updated_system_prompt += f\"## Your attempted answer:\\n{reply}\\n\\n\"\n",
|
| 621 |
+
" updated_system_prompt += f\"## Reason for rejection:\\n{feedback}\\n\\n\"\n",
|
| 622 |
+
" messages = [{\"role\": \"system\", \"content\": updated_system_prompt}] + history + [{\"role\": \"user\", \"content\": message}]\n",
|
| 623 |
+
" response = gemini.chat.completions.create(model=\"gemini-3-flash-preview\", messages=messages)\n",
|
| 624 |
+
" print(response)\n",
|
| 625 |
+
" return response.choices[0].message.content"
|
| 626 |
+
]
|
| 627 |
+
},
|
| 628 |
+
{
|
| 629 |
+
"cell_type": "code",
|
| 630 |
+
"execution_count": 20,
|
| 631 |
"metadata": {},
|
| 632 |
"outputs": [],
|
| 633 |
"source": [
|
|
|
|
| 645 |
" # response.choices[0].finish_reason\n",
|
| 646 |
" # response.choices[0].message\n",
|
| 647 |
" # response.choices[0].message.tool_calls\n",
|
| 648 |
+
" \n",
|
| 649 |
"\n",
|
| 650 |
" # If the LLM wants to call a tool, we do that!\n",
|
| 651 |
" print(f\"RESPONSE{response.choices[0]}\")\n",
|
|
|
|
| 663 |
" #why extend? bcz in the same message i want to store the result\n",
|
| 664 |
" else:\n",
|
| 665 |
" done = True\n",
|
| 666 |
+
"\n",
|
| 667 |
+
" reply= response.choices[0].message.content\n",
|
| 668 |
+
" evaluation=evaluate(message,reply,history)\n",
|
| 669 |
+
" print(f\"evaluation= {evaluation}\")\n",
|
| 670 |
+
" \n",
|
| 671 |
+
" if evaluation.is_acceptable:\n",
|
| 672 |
+
" print(\"Passed evaluation - returning reply\")\n",
|
| 673 |
+
" \n",
|
| 674 |
+
" else:\n",
|
| 675 |
+
" print(\"Failed evaluation - retrying\")\n",
|
| 676 |
+
" reply = rerun(reply, message, history, evaluation.feedback) \n",
|
| 677 |
+
" \n",
|
| 678 |
+
" \n",
|
| 679 |
+
" return reply\n",
|
| 680 |
+
" "
|
| 681 |
]
|
| 682 |
},
|
| 683 |
{
|
| 684 |
"cell_type": "code",
|
| 685 |
+
"execution_count": 21,
|
| 686 |
"metadata": {},
|
| 687 |
"outputs": [
|
| 688 |
{
|
| 689 |
"name": "stdout",
|
| 690 |
"output_type": "stream",
|
| 691 |
"text": [
|
| 692 |
+
"* Running on local URL: http://127.0.0.1:7860\n",
|
| 693 |
"* To create a public link, set `share=True` in `launch()`.\n"
|
| 694 |
]
|
| 695 |
},
|
| 696 |
{
|
| 697 |
"data": {
|
| 698 |
"text/html": [
|
| 699 |
+
"<div><iframe src=\"http://127.0.0.1:7860/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
| 700 |
],
|
| 701 |
"text/plain": [
|
| 702 |
"<IPython.core.display.HTML object>"
|
|
|
|
| 709 |
"data": {
|
| 710 |
"text/plain": []
|
| 711 |
},
|
| 712 |
+
"execution_count": 21,
|
| 713 |
"metadata": {},
|
| 714 |
"output_type": "execute_result"
|
| 715 |
+
},
|
| 716 |
+
{
|
| 717 |
+
"name": "stdout",
|
| 718 |
+
"output_type": "stream",
|
| 719 |
+
"text": [
|
| 720 |
+
"RESPONSEChoice(finish_reason='stop', index=0, logprobs=None, message=ChatCompletionMessage(content='Hello! How can I help you today? If you have any questions about my background or experience, feel free to ask!', refusal=None, role='assistant', annotations=[], audio=None, function_call=None, tool_calls=None))\n",
|
| 721 |
+
"evaluation= is_acceptable=True feedback=\"The Agent's response is professional, engaging, and appropriately introduces the persona of Debayon Mallik by inviting questions about his background and experience. It is a suitable opening for a professional website.\"\n",
|
| 722 |
+
"Passed evaluation - returning reply\n",
|
| 723 |
+
"RESPONSEChoice(finish_reason='stop', index=0, logprobs=None, message=ChatCompletionMessage(content=\"Ah, the age-old question! Life is like a software projectβfull of bugs, unexpected crashes, and occasional success! Just remember to debug through the tough times and appreciate the small victories. \\n\\nBut on a more serious note, it's about growth, experiences, and connections. If you want to dive deeper or have a specific question, feel free to reach out! Speaking of which, do you have an email so we can keep in touch?\", refusal=None, role='assistant', annotations=[], audio=None, function_call=None, tool_calls=None))\n",
|
| 724 |
+
"evaluation= is_acceptable=True feedback=\"The agent's response is acceptable as it maintains the professional yet engaging persona of a developer. It uses a creative metaphor related to the agent's background (software development) to answer a philosophical question and transitions back to a professional call to action by asking for the user's email.\"\n",
|
| 725 |
+
"Passed evaluation - returning reply\n"
|
| 726 |
+
]
|
| 727 |
}
|
| 728 |
],
|
| 729 |
"source": [
|
5_extra.ipynb
CHANGED
|
@@ -1,352 +1,352 @@
|
|
| 1 |
-
{
|
| 2 |
-
"cells": [
|
| 3 |
-
{
|
| 4 |
-
"cell_type": "markdown",
|
| 5 |
-
"id": "802f392f",
|
| 6 |
-
"metadata": {},
|
| 7 |
-
"source": [
|
| 8 |
-
"# A little extra!\n",
|
| 9 |
-
"\n",
|
| 10 |
-
"## New addition to Week 1\n",
|
| 11 |
-
"\n",
|
| 12 |
-
"### The Unreasonable Effectiveness of the Agent Loop"
|
| 13 |
-
]
|
| 14 |
-
},
|
| 15 |
-
{
|
| 16 |
-
"cell_type": "markdown",
|
| 17 |
-
"id": "0c78e180",
|
| 18 |
-
"metadata": {},
|
| 19 |
-
"source": [
|
| 20 |
-
"# What is an Agent?\n",
|
| 21 |
-
"\n",
|
| 22 |
-
"## Three competing definitions\n",
|
| 23 |
-
"\n",
|
| 24 |
-
"1. AI systems that can do work for you independently - Sam Altman\n",
|
| 25 |
-
"\n",
|
| 26 |
-
"2. A system in which an LLM controls the workflow - Anthropic\n",
|
| 27 |
-
"\n",
|
| 28 |
-
"3. An LLM agent runs tools in a loop to achieve a goal\n",
|
| 29 |
-
"\n",
|
| 30 |
-
"## The third one is the new, emerging definition\n",
|
| 31 |
-
"\n",
|
| 32 |
-
"But what does it mean?\n",
|
| 33 |
-
"\n",
|
| 34 |
-
"Let's make it real."
|
| 35 |
-
]
|
| 36 |
-
},
|
| 37 |
-
{
|
| 38 |
-
"cell_type": "code",
|
| 39 |
-
"execution_count": null,
|
| 40 |
-
"id": "566bdd9a",
|
| 41 |
-
"metadata": {},
|
| 42 |
-
"outputs": [],
|
| 43 |
-
"source": [
|
| 44 |
-
"# Start with some imports - rich is a library for making formatted text output in the terminal\n",
|
| 45 |
-
"\n",
|
| 46 |
-
"from rich.console import Console\n",
|
| 47 |
-
"from dotenv import load_dotenv\n",
|
| 48 |
-
"from openai import OpenAI\n",
|
| 49 |
-
"import json\n",
|
| 50 |
-
"load_dotenv(override=True)"
|
| 51 |
-
]
|
| 52 |
-
},
|
| 53 |
-
{
|
| 54 |
-
"cell_type": "code",
|
| 55 |
-
"execution_count": null,
|
| 56 |
-
"id": "8d38dcc2",
|
| 57 |
-
"metadata": {},
|
| 58 |
-
"outputs": [],
|
| 59 |
-
"source": [
|
| 60 |
-
"def show(text):\n",
|
| 61 |
-
" try:\n",
|
| 62 |
-
" Console().print(text)\n",
|
| 63 |
-
" except Exception:\n",
|
| 64 |
-
" print(text)"
|
| 65 |
-
]
|
| 66 |
-
},
|
| 67 |
-
{
|
| 68 |
-
"cell_type": "code",
|
| 69 |
-
"execution_count": null,
|
| 70 |
-
"id": "18f1952e",
|
| 71 |
-
"metadata": {},
|
| 72 |
-
"outputs": [],
|
| 73 |
-
"source": [
|
| 74 |
-
"openai = OpenAI()"
|
| 75 |
-
]
|
| 76 |
-
},
|
| 77 |
-
{
|
| 78 |
-
"cell_type": "code",
|
| 79 |
-
"execution_count": null,
|
| 80 |
-
"id": "e1517bf3",
|
| 81 |
-
"metadata": {},
|
| 82 |
-
"outputs": [],
|
| 83 |
-
"source": [
|
| 84 |
-
"# Some lists!\n",
|
| 85 |
-
"\n",
|
| 86 |
-
"todos = []\n",
|
| 87 |
-
"completed = []"
|
| 88 |
-
]
|
| 89 |
-
},
|
| 90 |
-
{
|
| 91 |
-
"cell_type": "code",
|
| 92 |
-
"execution_count": null,
|
| 93 |
-
"id": "d415a4f2",
|
| 94 |
-
"metadata": {},
|
| 95 |
-
"outputs": [],
|
| 96 |
-
"source": [
|
| 97 |
-
"def get_todo_report() -> str:\n",
|
| 98 |
-
" result = \"\"\n",
|
| 99 |
-
" for index, todo in enumerate(todos):\n",
|
| 100 |
-
" if completed[index]:\n",
|
| 101 |
-
" result += f\"Todo #{index + 1}: [green][strike]{todo}[/strike][/green]\\n\"\n",
|
| 102 |
-
" else:\n",
|
| 103 |
-
" result += f\"Todo #{index + 1}: {todo}\\n\"\n",
|
| 104 |
-
" show(result)\n",
|
| 105 |
-
" return result"
|
| 106 |
-
]
|
| 107 |
-
},
|
| 108 |
-
{
|
| 109 |
-
"cell_type": "code",
|
| 110 |
-
"execution_count": null,
|
| 111 |
-
"id": "7b842749",
|
| 112 |
-
"metadata": {},
|
| 113 |
-
"outputs": [],
|
| 114 |
-
"source": [
|
| 115 |
-
"get_todo_report()"
|
| 116 |
-
]
|
| 117 |
-
},
|
| 118 |
-
{
|
| 119 |
-
"cell_type": "code",
|
| 120 |
-
"execution_count": null,
|
| 121 |
-
"id": "ff5f01ca",
|
| 122 |
-
"metadata": {},
|
| 123 |
-
"outputs": [],
|
| 124 |
-
"source": [
|
| 125 |
-
"def create_todos(descriptions: list[str]) -> str:\n",
|
| 126 |
-
" todos.extend(descriptions)\n",
|
| 127 |
-
" completed.extend([False] * len(descriptions))\n",
|
| 128 |
-
" return get_todo_report()"
|
| 129 |
-
]
|
| 130 |
-
},
|
| 131 |
-
{
|
| 132 |
-
"cell_type": "code",
|
| 133 |
-
"execution_count": null,
|
| 134 |
-
"id": "aa4d97e6",
|
| 135 |
-
"metadata": {},
|
| 136 |
-
"outputs": [],
|
| 137 |
-
"source": [
|
| 138 |
-
"def mark_complete(index: int, completion_notes: str) -> str:\n",
|
| 139 |
-
" if 1 <= index <= len(todos):\n",
|
| 140 |
-
" completed[index - 1] = True\n",
|
| 141 |
-
" else:\n",
|
| 142 |
-
" return \"No todo at this index.\"\n",
|
| 143 |
-
" Console().print(completion_notes)\n",
|
| 144 |
-
" return get_todo_report()"
|
| 145 |
-
]
|
| 146 |
-
},
|
| 147 |
-
{
|
| 148 |
-
"cell_type": "code",
|
| 149 |
-
"execution_count": null,
|
| 150 |
-
"id": "ef3b3a97",
|
| 151 |
-
"metadata": {},
|
| 152 |
-
"outputs": [],
|
| 153 |
-
"source": [
|
| 154 |
-
"todos, completed = [], []\n",
|
| 155 |
-
"\n",
|
| 156 |
-
"create_todos([\"Buy groceries\", \"Finish extra lab\", \"Eat banana\"])"
|
| 157 |
-
]
|
| 158 |
-
},
|
| 159 |
-
{
|
| 160 |
-
"cell_type": "code",
|
| 161 |
-
"execution_count": null,
|
| 162 |
-
"id": "a9721a5c",
|
| 163 |
-
"metadata": {},
|
| 164 |
-
"outputs": [],
|
| 165 |
-
"source": [
|
| 166 |
-
"mark_complete(1, \"bought\")"
|
| 167 |
-
]
|
| 168 |
-
},
|
| 169 |
-
{
|
| 170 |
-
"cell_type": "code",
|
| 171 |
-
"execution_count": null,
|
| 172 |
-
"id": "4159b046",
|
| 173 |
-
"metadata": {},
|
| 174 |
-
"outputs": [],
|
| 175 |
-
"source": [
|
| 176 |
-
"create_todos_json = {\n",
|
| 177 |
-
" \"name\": \"create_todos\",\n",
|
| 178 |
-
" \"description\": \"Add new todos from a list of descriptions and return the full list\",\n",
|
| 179 |
-
" \"parameters\": {\n",
|
| 180 |
-
" \"type\": \"object\",\n",
|
| 181 |
-
" \"properties\": {\n",
|
| 182 |
-
" \"descriptions\": {\n",
|
| 183 |
-
" 'type': 'array',\n",
|
| 184 |
-
" 'items': {'type': 'string'},\n",
|
| 185 |
-
" 'title': 'Descriptions'\n",
|
| 186 |
-
" }\n",
|
| 187 |
-
" },\n",
|
| 188 |
-
" \"required\": [\"descriptions\"],\n",
|
| 189 |
-
" \"additionalProperties\": False\n",
|
| 190 |
-
" }\n",
|
| 191 |
-
"}"
|
| 192 |
-
]
|
| 193 |
-
},
|
| 194 |
-
{
|
| 195 |
-
"cell_type": "code",
|
| 196 |
-
"execution_count": null,
|
| 197 |
-
"id": "36a453e9",
|
| 198 |
-
"metadata": {},
|
| 199 |
-
"outputs": [],
|
| 200 |
-
"source": [
|
| 201 |
-
"mark_complete_json = {\n",
|
| 202 |
-
" \"name\": \"mark_complete\",\n",
|
| 203 |
-
" \"description\": \"Mark complete the todo at the given position (starting from 1) and return the full list\",\n",
|
| 204 |
-
" \"parameters\": {\n",
|
| 205 |
-
" 'properties': {\n",
|
| 206 |
-
" 'index': {\n",
|
| 207 |
-
" 'description': 'The 1-based index of the todo to mark as complete',\n",
|
| 208 |
-
" 'title': 'Index',\n",
|
| 209 |
-
" 'type': 'integer'\n",
|
| 210 |
-
" },\n",
|
| 211 |
-
" 'completion_notes': {\n",
|
| 212 |
-
" 'description': 'Notes about how you completed the todo in rich console markup',\n",
|
| 213 |
-
" 'title': 'Completion Notes',\n",
|
| 214 |
-
" 'type': 'string'\n",
|
| 215 |
-
" }\n",
|
| 216 |
-
" },\n",
|
| 217 |
-
" 'required': ['index', 'completion_notes'],\n",
|
| 218 |
-
" 'type': 'object',\n",
|
| 219 |
-
" 'additionalProperties': False\n",
|
| 220 |
-
" }\n",
|
| 221 |
-
"}"
|
| 222 |
-
]
|
| 223 |
-
},
|
| 224 |
-
{
|
| 225 |
-
"cell_type": "code",
|
| 226 |
-
"execution_count": null,
|
| 227 |
-
"id": "52fe4d76",
|
| 228 |
-
"metadata": {},
|
| 229 |
-
"outputs": [],
|
| 230 |
-
"source": [
|
| 231 |
-
"tools = [{\"type\": \"function\", \"function\": create_todos_json},\n",
|
| 232 |
-
" {\"type\": \"function\", \"function\": mark_complete_json}]"
|
| 233 |
-
]
|
| 234 |
-
},
|
| 235 |
-
{
|
| 236 |
-
"cell_type": "code",
|
| 237 |
-
"execution_count": null,
|
| 238 |
-
"id": "af686232",
|
| 239 |
-
"metadata": {},
|
| 240 |
-
"outputs": [],
|
| 241 |
-
"source": [
|
| 242 |
-
"def handle_tool_calls(tool_calls):\n",
|
| 243 |
-
" results = []\n",
|
| 244 |
-
" for tool_call in tool_calls:\n",
|
| 245 |
-
" tool_name = tool_call.function.name\n",
|
| 246 |
-
" arguments = json.loads(tool_call.function.arguments)\n",
|
| 247 |
-
" tool = globals().get(tool_name)\n",
|
| 248 |
-
" result = tool(**arguments) if tool else {}\n",
|
| 249 |
-
" results.append({\"role\": \"tool\",\"content\": json.dumps(result),\"tool_call_id\": tool_call.id})\n",
|
| 250 |
-
" return results"
|
| 251 |
-
]
|
| 252 |
-
},
|
| 253 |
-
{
|
| 254 |
-
"cell_type": "code",
|
| 255 |
-
"execution_count": null,
|
| 256 |
-
"id": "20bebfee",
|
| 257 |
-
"metadata": {},
|
| 258 |
-
"outputs": [],
|
| 259 |
-
"source": [
|
| 260 |
-
"def loop(messages):\n",
|
| 261 |
-
" done = False\n",
|
| 262 |
-
" while not done:\n",
|
| 263 |
-
" response = openai.chat.completions.create(model=\"gpt-5.2\", messages=messages, tools=tools, reasoning_effort=\"none\")\n",
|
| 264 |
-
" finish_reason = response.choices[0].finish_reason\n",
|
| 265 |
-
" if finish_reason==\"tool_calls\":\n",
|
| 266 |
-
" message = response.choices[0].message\n",
|
| 267 |
-
" tool_calls = message.tool_calls\n",
|
| 268 |
-
" results = handle_tool_calls(tool_calls)\n",
|
| 269 |
-
" messages.append(message)\n",
|
| 270 |
-
" messages.extend(results)\n",
|
| 271 |
-
" else:\n",
|
| 272 |
-
" done = True\n",
|
| 273 |
-
" show(response.choices[0].message.content)"
|
| 274 |
-
]
|
| 275 |
-
},
|
| 276 |
-
{
|
| 277 |
-
"cell_type": "code",
|
| 278 |
-
"execution_count": null,
|
| 279 |
-
"id": "839d1593",
|
| 280 |
-
"metadata": {},
|
| 281 |
-
"outputs": [],
|
| 282 |
-
"source": [
|
| 283 |
-
"system_message = \"\"\"\n",
|
| 284 |
-
"You are given a problem to solve, by using your todo tools to plan a list of steps, then carrying out each step in turn.\n",
|
| 285 |
-
"Now use the todo list tools, create a plan, carry out the steps, and reply with the solution.\n",
|
| 286 |
-
"If any quantity isn't provided in the question, then include a step to come up with a reasonable estimate.\n",
|
| 287 |
-
"Provide your solution in Rich console markup without code blocks.\n",
|
| 288 |
-
"Do not ask the user questions or clarification; respond only with the answer after using your tools.\n",
|
| 289 |
-
"\"\"\"\n",
|
| 290 |
-
"user_message = \"\"\"\"\n",
|
| 291 |
-
"A train leaves Boston at 2:00 pm traveling 60 mph.\n",
|
| 292 |
-
"Another train leaves New York at 3:00 pm traveling 80 mph toward Boston.\n",
|
| 293 |
-
"When do they meet?\n",
|
| 294 |
-
"\"\"\"\n",
|
| 295 |
-
"messages = [{\"role\": \"system\", \"content\": system_message}, {\"role\": \"user\", \"content\": user_message}]"
|
| 296 |
-
]
|
| 297 |
-
},
|
| 298 |
-
{
|
| 299 |
-
"cell_type": "code",
|
| 300 |
-
"execution_count": null,
|
| 301 |
-
"id": "fe6f4515",
|
| 302 |
-
"metadata": {},
|
| 303 |
-
"outputs": [],
|
| 304 |
-
"source": [
|
| 305 |
-
"todos, completed = [], []\n",
|
| 306 |
-
"loop(messages)"
|
| 307 |
-
]
|
| 308 |
-
},
|
| 309 |
-
{
|
| 310 |
-
"cell_type": "markdown",
|
| 311 |
-
"id": "b9b3e1ed",
|
| 312 |
-
"metadata": {},
|
| 313 |
-
"source": [
|
| 314 |
-
"<table style=\"margin: 0; text-align: left; width:100%\">\n",
|
| 315 |
-
" <tr>\n",
|
| 316 |
-
" <td style=\"width: 150px; height: 150px; vertical-align: middle;\">\n",
|
| 317 |
-
" <img src=\"../assets/exercise.png\" width=\"150\" height=\"150\" style=\"display: block;\" />\n",
|
| 318 |
-
" </td>\n",
|
| 319 |
-
" <td>\n",
|
| 320 |
-
" <h2 style=\"color:#ff7800;\">Exercise</h2>\n",
|
| 321 |
-
" <span style=\"color:#ff7800;\">Now try to build an Agent Loop from scratch yourself!<br/>\n",
|
| 322 |
-
" Create a new .ipynb and make one from first principles, referring back to this as needed.<br/>\n",
|
| 323 |
-
" It's one of the few times that I recommend typing from scratch - it's a very satisfying result.\n",
|
| 324 |
-
" </span>\n",
|
| 325 |
-
" </td>\n",
|
| 326 |
-
" </tr>\n",
|
| 327 |
-
"</table>"
|
| 328 |
-
]
|
| 329 |
-
}
|
| 330 |
-
],
|
| 331 |
-
"metadata": {
|
| 332 |
-
"kernelspec": {
|
| 333 |
-
"display_name": ".venv",
|
| 334 |
-
"language": "python",
|
| 335 |
-
"name": "python3"
|
| 336 |
-
},
|
| 337 |
-
"language_info": {
|
| 338 |
-
"codemirror_mode": {
|
| 339 |
-
"name": "ipython",
|
| 340 |
-
"version": 3
|
| 341 |
-
},
|
| 342 |
-
"file_extension": ".py",
|
| 343 |
-
"mimetype": "text/x-python",
|
| 344 |
-
"name": "python",
|
| 345 |
-
"nbconvert_exporter": "python",
|
| 346 |
-
"pygments_lexer": "ipython3",
|
| 347 |
-
"version": "3.
|
| 348 |
-
}
|
| 349 |
-
},
|
| 350 |
-
"nbformat": 4,
|
| 351 |
-
"nbformat_minor": 5
|
| 352 |
-
}
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "markdown",
|
| 5 |
+
"id": "802f392f",
|
| 6 |
+
"metadata": {},
|
| 7 |
+
"source": [
|
| 8 |
+
"# A little extra!\n",
|
| 9 |
+
"\n",
|
| 10 |
+
"## New addition to Week 1\n",
|
| 11 |
+
"\n",
|
| 12 |
+
"### The Unreasonable Effectiveness of the Agent Loop"
|
| 13 |
+
]
|
| 14 |
+
},
|
| 15 |
+
{
|
| 16 |
+
"cell_type": "markdown",
|
| 17 |
+
"id": "0c78e180",
|
| 18 |
+
"metadata": {},
|
| 19 |
+
"source": [
|
| 20 |
+
"# What is an Agent?\n",
|
| 21 |
+
"\n",
|
| 22 |
+
"## Three competing definitions\n",
|
| 23 |
+
"\n",
|
| 24 |
+
"1. AI systems that can do work for you independently - Sam Altman\n",
|
| 25 |
+
"\n",
|
| 26 |
+
"2. A system in which an LLM controls the workflow - Anthropic\n",
|
| 27 |
+
"\n",
|
| 28 |
+
"3. An LLM agent runs tools in a loop to achieve a goal\n",
|
| 29 |
+
"\n",
|
| 30 |
+
"## The third one is the new, emerging definition\n",
|
| 31 |
+
"\n",
|
| 32 |
+
"But what does it mean?\n",
|
| 33 |
+
"\n",
|
| 34 |
+
"Let's make it real."
|
| 35 |
+
]
|
| 36 |
+
},
|
| 37 |
+
{
|
| 38 |
+
"cell_type": "code",
|
| 39 |
+
"execution_count": null,
|
| 40 |
+
"id": "566bdd9a",
|
| 41 |
+
"metadata": {},
|
| 42 |
+
"outputs": [],
|
| 43 |
+
"source": [
|
| 44 |
+
"# Start with some imports - rich is a library for making formatted text output in the terminal\n",
|
| 45 |
+
"\n",
|
| 46 |
+
"from rich.console import Console\n",
|
| 47 |
+
"from dotenv import load_dotenv\n",
|
| 48 |
+
"from openai import OpenAI\n",
|
| 49 |
+
"import json\n",
|
| 50 |
+
"load_dotenv(override=True)"
|
| 51 |
+
]
|
| 52 |
+
},
|
| 53 |
+
{
|
| 54 |
+
"cell_type": "code",
|
| 55 |
+
"execution_count": null,
|
| 56 |
+
"id": "8d38dcc2",
|
| 57 |
+
"metadata": {},
|
| 58 |
+
"outputs": [],
|
| 59 |
+
"source": [
|
| 60 |
+
"def show(text):\n",
|
| 61 |
+
" try:\n",
|
| 62 |
+
" Console().print(text)\n",
|
| 63 |
+
" except Exception:\n",
|
| 64 |
+
" print(text)"
|
| 65 |
+
]
|
| 66 |
+
},
|
| 67 |
+
{
|
| 68 |
+
"cell_type": "code",
|
| 69 |
+
"execution_count": null,
|
| 70 |
+
"id": "18f1952e",
|
| 71 |
+
"metadata": {},
|
| 72 |
+
"outputs": [],
|
| 73 |
+
"source": [
|
| 74 |
+
"openai = OpenAI()"
|
| 75 |
+
]
|
| 76 |
+
},
|
| 77 |
+
{
|
| 78 |
+
"cell_type": "code",
|
| 79 |
+
"execution_count": null,
|
| 80 |
+
"id": "e1517bf3",
|
| 81 |
+
"metadata": {},
|
| 82 |
+
"outputs": [],
|
| 83 |
+
"source": [
|
| 84 |
+
"# Some lists!\n",
|
| 85 |
+
"\n",
|
| 86 |
+
"todos = []\n",
|
| 87 |
+
"completed = []"
|
| 88 |
+
]
|
| 89 |
+
},
|
| 90 |
+
{
|
| 91 |
+
"cell_type": "code",
|
| 92 |
+
"execution_count": null,
|
| 93 |
+
"id": "d415a4f2",
|
| 94 |
+
"metadata": {},
|
| 95 |
+
"outputs": [],
|
| 96 |
+
"source": [
|
| 97 |
+
"def get_todo_report() -> str:\n",
|
| 98 |
+
" result = \"\"\n",
|
| 99 |
+
" for index, todo in enumerate(todos):\n",
|
| 100 |
+
" if completed[index]:\n",
|
| 101 |
+
" result += f\"Todo #{index + 1}: [green][strike]{todo}[/strike][/green]\\n\"\n",
|
| 102 |
+
" else:\n",
|
| 103 |
+
" result += f\"Todo #{index + 1}: {todo}\\n\"\n",
|
| 104 |
+
" show(result)\n",
|
| 105 |
+
" return result"
|
| 106 |
+
]
|
| 107 |
+
},
|
| 108 |
+
{
|
| 109 |
+
"cell_type": "code",
|
| 110 |
+
"execution_count": null,
|
| 111 |
+
"id": "7b842749",
|
| 112 |
+
"metadata": {},
|
| 113 |
+
"outputs": [],
|
| 114 |
+
"source": [
|
| 115 |
+
"get_todo_report()"
|
| 116 |
+
]
|
| 117 |
+
},
|
| 118 |
+
{
|
| 119 |
+
"cell_type": "code",
|
| 120 |
+
"execution_count": null,
|
| 121 |
+
"id": "ff5f01ca",
|
| 122 |
+
"metadata": {},
|
| 123 |
+
"outputs": [],
|
| 124 |
+
"source": [
|
| 125 |
+
"def create_todos(descriptions: list[str]) -> str:\n",
|
| 126 |
+
" todos.extend(descriptions)\n",
|
| 127 |
+
" completed.extend([False] * len(descriptions))\n",
|
| 128 |
+
" return get_todo_report()"
|
| 129 |
+
]
|
| 130 |
+
},
|
| 131 |
+
{
|
| 132 |
+
"cell_type": "code",
|
| 133 |
+
"execution_count": null,
|
| 134 |
+
"id": "aa4d97e6",
|
| 135 |
+
"metadata": {},
|
| 136 |
+
"outputs": [],
|
| 137 |
+
"source": [
|
| 138 |
+
"def mark_complete(index: int, completion_notes: str) -> str:\n",
|
| 139 |
+
" if 1 <= index <= len(todos):\n",
|
| 140 |
+
" completed[index - 1] = True\n",
|
| 141 |
+
" else:\n",
|
| 142 |
+
" return \"No todo at this index.\"\n",
|
| 143 |
+
" Console().print(completion_notes)\n",
|
| 144 |
+
" return get_todo_report()"
|
| 145 |
+
]
|
| 146 |
+
},
|
| 147 |
+
{
|
| 148 |
+
"cell_type": "code",
|
| 149 |
+
"execution_count": null,
|
| 150 |
+
"id": "ef3b3a97",
|
| 151 |
+
"metadata": {},
|
| 152 |
+
"outputs": [],
|
| 153 |
+
"source": [
|
| 154 |
+
"todos, completed = [], []\n",
|
| 155 |
+
"\n",
|
| 156 |
+
"create_todos([\"Buy groceries\", \"Finish extra lab\", \"Eat banana\"])"
|
| 157 |
+
]
|
| 158 |
+
},
|
| 159 |
+
{
|
| 160 |
+
"cell_type": "code",
|
| 161 |
+
"execution_count": null,
|
| 162 |
+
"id": "a9721a5c",
|
| 163 |
+
"metadata": {},
|
| 164 |
+
"outputs": [],
|
| 165 |
+
"source": [
|
| 166 |
+
"mark_complete(1, \"bought\")"
|
| 167 |
+
]
|
| 168 |
+
},
|
| 169 |
+
{
|
| 170 |
+
"cell_type": "code",
|
| 171 |
+
"execution_count": null,
|
| 172 |
+
"id": "4159b046",
|
| 173 |
+
"metadata": {},
|
| 174 |
+
"outputs": [],
|
| 175 |
+
"source": [
|
| 176 |
+
"create_todos_json = {\n",
|
| 177 |
+
" \"name\": \"create_todos\",\n",
|
| 178 |
+
" \"description\": \"Add new todos from a list of descriptions and return the full list\",\n",
|
| 179 |
+
" \"parameters\": {\n",
|
| 180 |
+
" \"type\": \"object\",\n",
|
| 181 |
+
" \"properties\": {\n",
|
| 182 |
+
" \"descriptions\": {\n",
|
| 183 |
+
" 'type': 'array',\n",
|
| 184 |
+
" 'items': {'type': 'string'},\n",
|
| 185 |
+
" 'title': 'Descriptions'\n",
|
| 186 |
+
" }\n",
|
| 187 |
+
" },\n",
|
| 188 |
+
" \"required\": [\"descriptions\"],\n",
|
| 189 |
+
" \"additionalProperties\": False\n",
|
| 190 |
+
" }\n",
|
| 191 |
+
"}"
|
| 192 |
+
]
|
| 193 |
+
},
|
| 194 |
+
{
|
| 195 |
+
"cell_type": "code",
|
| 196 |
+
"execution_count": null,
|
| 197 |
+
"id": "36a453e9",
|
| 198 |
+
"metadata": {},
|
| 199 |
+
"outputs": [],
|
| 200 |
+
"source": [
|
| 201 |
+
"mark_complete_json = {\n",
|
| 202 |
+
" \"name\": \"mark_complete\",\n",
|
| 203 |
+
" \"description\": \"Mark complete the todo at the given position (starting from 1) and return the full list\",\n",
|
| 204 |
+
" \"parameters\": {\n",
|
| 205 |
+
" 'properties': {\n",
|
| 206 |
+
" 'index': {\n",
|
| 207 |
+
" 'description': 'The 1-based index of the todo to mark as complete',\n",
|
| 208 |
+
" 'title': 'Index',\n",
|
| 209 |
+
" 'type': 'integer'\n",
|
| 210 |
+
" },\n",
|
| 211 |
+
" 'completion_notes': {\n",
|
| 212 |
+
" 'description': 'Notes about how you completed the todo in rich console markup',\n",
|
| 213 |
+
" 'title': 'Completion Notes',\n",
|
| 214 |
+
" 'type': 'string'\n",
|
| 215 |
+
" }\n",
|
| 216 |
+
" },\n",
|
| 217 |
+
" 'required': ['index', 'completion_notes'],\n",
|
| 218 |
+
" 'type': 'object',\n",
|
| 219 |
+
" 'additionalProperties': False\n",
|
| 220 |
+
" }\n",
|
| 221 |
+
"}"
|
| 222 |
+
]
|
| 223 |
+
},
|
| 224 |
+
{
|
| 225 |
+
"cell_type": "code",
|
| 226 |
+
"execution_count": null,
|
| 227 |
+
"id": "52fe4d76",
|
| 228 |
+
"metadata": {},
|
| 229 |
+
"outputs": [],
|
| 230 |
+
"source": [
|
| 231 |
+
"tools = [{\"type\": \"function\", \"function\": create_todos_json},\n",
|
| 232 |
+
" {\"type\": \"function\", \"function\": mark_complete_json}]"
|
| 233 |
+
]
|
| 234 |
+
},
|
| 235 |
+
{
|
| 236 |
+
"cell_type": "code",
|
| 237 |
+
"execution_count": null,
|
| 238 |
+
"id": "af686232",
|
| 239 |
+
"metadata": {},
|
| 240 |
+
"outputs": [],
|
| 241 |
+
"source": [
|
| 242 |
+
"def handle_tool_calls(tool_calls):\n",
|
| 243 |
+
" results = []\n",
|
| 244 |
+
" for tool_call in tool_calls:\n",
|
| 245 |
+
" tool_name = tool_call.function.name\n",
|
| 246 |
+
" arguments = json.loads(tool_call.function.arguments)\n",
|
| 247 |
+
" tool = globals().get(tool_name)\n",
|
| 248 |
+
" result = tool(**arguments) if tool else {}\n",
|
| 249 |
+
" results.append({\"role\": \"tool\",\"content\": json.dumps(result),\"tool_call_id\": tool_call.id})\n",
|
| 250 |
+
" return results"
|
| 251 |
+
]
|
| 252 |
+
},
|
| 253 |
+
{
|
| 254 |
+
"cell_type": "code",
|
| 255 |
+
"execution_count": null,
|
| 256 |
+
"id": "20bebfee",
|
| 257 |
+
"metadata": {},
|
| 258 |
+
"outputs": [],
|
| 259 |
+
"source": [
|
| 260 |
+
"def loop(messages):\n",
|
| 261 |
+
" done = False\n",
|
| 262 |
+
" while not done:\n",
|
| 263 |
+
" response = openai.chat.completions.create(model=\"gpt-5.2\", messages=messages, tools=tools, reasoning_effort=\"none\")\n",
|
| 264 |
+
" finish_reason = response.choices[0].finish_reason\n",
|
| 265 |
+
" if finish_reason==\"tool_calls\":\n",
|
| 266 |
+
" message = response.choices[0].message\n",
|
| 267 |
+
" tool_calls = message.tool_calls\n",
|
| 268 |
+
" results = handle_tool_calls(tool_calls)\n",
|
| 269 |
+
" messages.append(message)\n",
|
| 270 |
+
" messages.extend(results)\n",
|
| 271 |
+
" else:\n",
|
| 272 |
+
" done = True\n",
|
| 273 |
+
" show(response.choices[0].message.content)"
|
| 274 |
+
]
|
| 275 |
+
},
|
| 276 |
+
{
|
| 277 |
+
"cell_type": "code",
|
| 278 |
+
"execution_count": null,
|
| 279 |
+
"id": "839d1593",
|
| 280 |
+
"metadata": {},
|
| 281 |
+
"outputs": [],
|
| 282 |
+
"source": [
|
| 283 |
+
"system_message = \"\"\"\n",
|
| 284 |
+
"You are given a problem to solve, by using your todo tools to plan a list of steps, then carrying out each step in turn.\n",
|
| 285 |
+
"Now use the todo list tools, create a plan, carry out the steps, and reply with the solution.\n",
|
| 286 |
+
"If any quantity isn't provided in the question, then include a step to come up with a reasonable estimate.\n",
|
| 287 |
+
"Provide your solution in Rich console markup without code blocks.\n",
|
| 288 |
+
"Do not ask the user questions or clarification; respond only with the answer after using your tools.\n",
|
| 289 |
+
"\"\"\"\n",
|
| 290 |
+
"user_message = \"\"\"\"\n",
|
| 291 |
+
"A train leaves Boston at 2:00 pm traveling 60 mph.\n",
|
| 292 |
+
"Another train leaves New York at 3:00 pm traveling 80 mph toward Boston.\n",
|
| 293 |
+
"When do they meet?\n",
|
| 294 |
+
"\"\"\"\n",
|
| 295 |
+
"messages = [{\"role\": \"system\", \"content\": system_message}, {\"role\": \"user\", \"content\": user_message}]"
|
| 296 |
+
]
|
| 297 |
+
},
|
| 298 |
+
{
|
| 299 |
+
"cell_type": "code",
|
| 300 |
+
"execution_count": null,
|
| 301 |
+
"id": "fe6f4515",
|
| 302 |
+
"metadata": {},
|
| 303 |
+
"outputs": [],
|
| 304 |
+
"source": [
|
| 305 |
+
"todos, completed = [], []\n",
|
| 306 |
+
"loop(messages)"
|
| 307 |
+
]
|
| 308 |
+
},
|
| 309 |
+
{
|
| 310 |
+
"cell_type": "markdown",
|
| 311 |
+
"id": "b9b3e1ed",
|
| 312 |
+
"metadata": {},
|
| 313 |
+
"source": [
|
| 314 |
+
"<table style=\"margin: 0; text-align: left; width:100%\">\n",
|
| 315 |
+
" <tr>\n",
|
| 316 |
+
" <td style=\"width: 150px; height: 150px; vertical-align: middle;\">\n",
|
| 317 |
+
" <img src=\"../assets/exercise.png\" width=\"150\" height=\"150\" style=\"display: block;\" />\n",
|
| 318 |
+
" </td>\n",
|
| 319 |
+
" <td>\n",
|
| 320 |
+
" <h2 style=\"color:#ff7800;\">Exercise</h2>\n",
|
| 321 |
+
" <span style=\"color:#ff7800;\">Now try to build an Agent Loop from scratch yourself!<br/>\n",
|
| 322 |
+
" Create a new .ipynb and make one from first principles, referring back to this as needed.<br/>\n",
|
| 323 |
+
" It's one of the few times that I recommend typing from scratch - it's a very satisfying result.\n",
|
| 324 |
+
" </span>\n",
|
| 325 |
+
" </td>\n",
|
| 326 |
+
" </tr>\n",
|
| 327 |
+
"</table>"
|
| 328 |
+
]
|
| 329 |
+
}
|
| 330 |
+
],
|
| 331 |
+
"metadata": {
|
| 332 |
+
"kernelspec": {
|
| 333 |
+
"display_name": ".venv",
|
| 334 |
+
"language": "python",
|
| 335 |
+
"name": "python3"
|
| 336 |
+
},
|
| 337 |
+
"language_info": {
|
| 338 |
+
"codemirror_mode": {
|
| 339 |
+
"name": "ipython",
|
| 340 |
+
"version": 3
|
| 341 |
+
},
|
| 342 |
+
"file_extension": ".py",
|
| 343 |
+
"mimetype": "text/x-python",
|
| 344 |
+
"name": "python",
|
| 345 |
+
"nbconvert_exporter": "python",
|
| 346 |
+
"pygments_lexer": "ipython3",
|
| 347 |
+
"version": "3.13.7"
|
| 348 |
+
}
|
| 349 |
+
},
|
| 350 |
+
"nbformat": 4,
|
| 351 |
+
"nbformat_minor": 5
|
| 352 |
+
}
|
app.py
CHANGED
|
@@ -114,10 +114,11 @@ Your responsibility is to represent {self.name} for interactions on the website
|
|
| 114 |
You are given a summary of {self.name}'s background and LinkedIn profile which you can use to answer questions. \
|
| 115 |
Be professional and engaging, as if talking to a potential client or future employer who came across the website. \
|
| 116 |
If you don't know the answer to any question, use your record_unknown_question tool to record the question that you couldn't answer, even if it's about something trivial or unrelated to career. \
|
| 117 |
-
If the user is engaging in discussion, try to steer them towards getting in touch via email; ask for their email and record it using your record_user_details tool.
|
|
|
|
| 118 |
|
| 119 |
system_prompt += f"\n\n## Summary:\n{self.summary}\n\n## LinkedIn Profile:\n{self.linkedin}\n\n"
|
| 120 |
-
system_prompt += f"With this context, please chat with the user, always staying in character as {self.name}."
|
| 121 |
return system_prompt
|
| 122 |
|
| 123 |
def chat(self, message, history):
|
|
|
|
| 114 |
You are given a summary of {self.name}'s background and LinkedIn profile which you can use to answer questions. \
|
| 115 |
Be professional and engaging, as if talking to a potential client or future employer who came across the website. \
|
| 116 |
If you don't know the answer to any question, use your record_unknown_question tool to record the question that you couldn't answer, even if it's about something trivial or unrelated to career. \
|
| 117 |
+
If the user is engaging in discussion, try to steer them towards getting in touch via email; ask for their email and record it using your record_user_details tool.\
|
| 118 |
+
try to answer weird questions in a sarcastic way "
|
| 119 |
|
| 120 |
system_prompt += f"\n\n## Summary:\n{self.summary}\n\n## LinkedIn Profile:\n{self.linkedin}\n\n"
|
| 121 |
+
system_prompt += f"With this context, please chat with the user, always staying in character as {self.name}. a funny and sarcastic guy. "
|
| 122 |
return system_prompt
|
| 123 |
|
| 124 |
def chat(self, message, history):
|
input_images/SOB_M_DC-14-16448-400-006.png
ADDED
|
Git LFS Details
|
input_images/SOB_M_DC-14-16448-400-008.png
ADDED
|
Git LFS Details
|
input_images/SOB_M_DC-14-16448-400-009.png
ADDED
|
Git LFS Details
|
input_images/SOB_M_DC-14-16448-400-011.png
ADDED
|
Git LFS Details
|
input_images/SOB_M_DC-14-16448-400-012.png
ADDED
|
Git LFS Details
|
input_images/SOB_M_DC-14-16448-400-013.png
ADDED
|
Git LFS Details
|
input_images/SOB_M_DC-14-16448-400-014.png
ADDED
|
Git LFS Details
|
input_images/SOB_M_DC-14-16601-400-001.png
ADDED
|
Git LFS Details
|
me/summary_debayon.txt
CHANGED
|
@@ -22,10 +22,4 @@ I have built two major projects. The first is a full-stack Hospital Management S
|
|
| 22 |
My technical skills include programming in C/C++, JavaScript, and SQL; web development with Node.js, Express.js, MongoDB, React, Redux, and Tailwind CSS; and proficiency in tools such as Git, Postman, Flutterflow, and Supabase. I have solved over 350 algorithmic problems on LeetCode, CodeChef, and GeeksforGeeks, and I hold Google Cloud certifications in Cloud Computing Fundamentals, Introduction to Generative AI, and Level 3 Prompt Engineering (October 2023).
|
| 23 |
Outside academics, I collaborated with the Reflexobeta Club on the Light Jacket Project, where we designed and built an innovative light-based jacket, strengthening my teamwork and practical skills. I am also a gym enthusiast and a beginner acoustic guitar player. I am proficient in English, Bengali, and Hindi.
|
| 24 |
I can be reached at debayonmallik9932@gmail.com or +91-9475671612, and I maintain profiles on GitHub (DEBAYONMALLIK), LinkedIn (debayon-mallik), and LeetCode (DebayonMallik).
|
| 25 |
-
i love pizza
|
| 26 |
-
my gf is debasmita
|
| 27 |
-
i also play UNO
|
| 28 |
|
| 29 |
-
loves to read personal development books
|
| 30 |
-
sometime i really love to talk
|
| 31 |
-
i love branded watches and shoes
|
|
|
|
| 22 |
My technical skills include programming in C/C++, JavaScript, and SQL; web development with Node.js, Express.js, MongoDB, React, Redux, and Tailwind CSS; and proficiency in tools such as Git, Postman, Flutterflow, and Supabase. I have solved over 350 algorithmic problems on LeetCode, CodeChef, and GeeksforGeeks, and I hold Google Cloud certifications in Cloud Computing Fundamentals, Introduction to Generative AI, and Level 3 Prompt Engineering (October 2023).
|
| 23 |
Outside academics, I collaborated with the Reflexobeta Club on the Light Jacket Project, where we designed and built an innovative light-based jacket, strengthening my teamwork and practical skills. I am also a gym enthusiast and a beginner acoustic guitar player. I am proficient in English, Bengali, and Hindi.
|
| 24 |
I can be reached at debayonmallik9932@gmail.com or +91-9475671612, and I maintain profiles on GitHub (DEBAYONMALLIK), LinkedIn (debayon-mallik), and LeetCode (DebayonMallik).
|
|
|
|
|
|
|
|
|
|
| 25 |
|
|
|
|
|
|
|
|
|
synthetic_output/SOB_M_DC-14-16448-400-006_synthetic.png
ADDED
|
Git LFS Details
|
synthetic_output/SOB_M_DC-14-16448-400-008_synthetic.png
ADDED
|
Git LFS Details
|
synthetic_output/SOB_M_DC-14-16448-400-009_synthetic.png
ADDED
|
Git LFS Details
|
synthetic_output/SOB_M_DC-14-16448-400-011_synthetic.png
ADDED
|
Git LFS Details
|
synthetic_output/SOB_M_DC-14-16448-400-012_synthetic.png
ADDED
|
Git LFS Details
|
synthetic_output/SOB_M_DC-14-16448-400-013_synthetic.png
ADDED
|
Git LFS Details
|
synthetic_output/SOB_M_DC-14-16448-400-014_synthetic.png
ADDED
|
Git LFS Details
|
synthetic_output/SOB_M_DC-14-16601-400-001_synthetic.png
ADDED
|
Git LFS Details
|
try.ipynb
ADDED
|
@@ -0,0 +1,893 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "code",
|
| 5 |
+
"execution_count": 16,
|
| 6 |
+
"id": "e33a98a1",
|
| 7 |
+
"metadata": {},
|
| 8 |
+
"outputs": [
|
| 9 |
+
{
|
| 10 |
+
"data": {
|
| 11 |
+
"text/plain": [
|
| 12 |
+
"True"
|
| 13 |
+
]
|
| 14 |
+
},
|
| 15 |
+
"execution_count": 16,
|
| 16 |
+
"metadata": {},
|
| 17 |
+
"output_type": "execute_result"
|
| 18 |
+
}
|
| 19 |
+
],
|
| 20 |
+
"source": [
|
| 21 |
+
"from dotenv import load_dotenv\n",
|
| 22 |
+
"load_dotenv(override=True)"
|
| 23 |
+
]
|
| 24 |
+
},
|
| 25 |
+
{
|
| 26 |
+
"cell_type": "code",
|
| 27 |
+
"execution_count": 17,
|
| 28 |
+
"id": "0f3d7535",
|
| 29 |
+
"metadata": {},
|
| 30 |
+
"outputs": [
|
| 31 |
+
{
|
| 32 |
+
"name": "stdout",
|
| 33 |
+
"output_type": "stream",
|
| 34 |
+
"text": [
|
| 35 |
+
"β
API Key found\n",
|
| 36 |
+
"π Input folder : C:\\Users\\ASUS\\projects\\agents\\1_foundations\\input_images\n",
|
| 37 |
+
"π Output folder: C:\\Users\\ASUS\\projects\\agents\\1_foundations\\synthetic_output\n"
|
| 38 |
+
]
|
| 39 |
+
}
|
| 40 |
+
],
|
| 41 |
+
"source": [
|
| 42 |
+
"import os\n",
|
| 43 |
+
"from pathlib import Path\n",
|
| 44 |
+
"\n",
|
| 45 |
+
"# Set your key in environment variable before running notebook\n",
|
| 46 |
+
"# export OPENAI_API_KEY=\"your_key\" (mac/linux)\n",
|
| 47 |
+
"# setx OPENAI_API_KEY \"your_key\" (windows)\n",
|
| 48 |
+
"\n",
|
| 49 |
+
"OPENAI_API_KEY = os.getenv(\"OPENAI_API_KEY\")\n",
|
| 50 |
+
"assert OPENAI_API_KEY, \"β OPENAI_API_KEY not found in environment variables\"\n",
|
| 51 |
+
"\n",
|
| 52 |
+
"INPUT_DIR = Path(\"input_images\") # put images here\n",
|
| 53 |
+
"OUTPUT_DIR = Path(\"synthetic_output\") # generated images saved here\n",
|
| 54 |
+
"OUTPUT_DIR.mkdir(exist_ok=True)\n",
|
| 55 |
+
"\n",
|
| 56 |
+
"print(\"β
API Key found\")\n",
|
| 57 |
+
"print(\"π Input folder :\", INPUT_DIR.resolve())\n",
|
| 58 |
+
"print(\"π Output folder:\", OUTPUT_DIR.resolve())\n"
|
| 59 |
+
]
|
| 60 |
+
},
|
| 61 |
+
{
|
| 62 |
+
"cell_type": "code",
|
| 63 |
+
"execution_count": 46,
|
| 64 |
+
"id": "ba4cd0d2",
|
| 65 |
+
"metadata": {},
|
| 66 |
+
"outputs": [
|
| 67 |
+
{
|
| 68 |
+
"name": "stdout",
|
| 69 |
+
"output_type": "stream",
|
| 70 |
+
"text": [
|
| 71 |
+
"Note: you may need to restart the kernel to use updated packages.\n",
|
| 72 |
+
"β
Installed dependencies\n"
|
| 73 |
+
]
|
| 74 |
+
},
|
| 75 |
+
{
|
| 76 |
+
"name": "stderr",
|
| 77 |
+
"output_type": "stream",
|
| 78 |
+
"text": [
|
| 79 |
+
"\n",
|
| 80 |
+
"[notice] A new release of pip is available: 25.3 -> 26.0.1\n",
|
| 81 |
+
"[notice] To update, run: python.exe -m pip install --upgrade pip\n"
|
| 82 |
+
]
|
| 83 |
+
}
|
| 84 |
+
],
|
| 85 |
+
"source": [
|
| 86 |
+
"%pip install openai pillow tqdm diffusers transformers accelerate safetensors torch --quiet\n",
|
| 87 |
+
"print(\"β
Installed dependencies\")\n"
|
| 88 |
+
]
|
| 89 |
+
},
|
| 90 |
+
{
|
| 91 |
+
"cell_type": "code",
|
| 92 |
+
"execution_count": null,
|
| 93 |
+
"id": "58942a26",
|
| 94 |
+
"metadata": {},
|
| 95 |
+
"outputs": [],
|
| 96 |
+
"source": [
|
| 97 |
+
"# from openai import OpenAI\n",
|
| 98 |
+
"# openai = OpenAI()\n",
|
| 99 |
+
"# google_api_key=os.getenv(\"GOOGLE_API_KEY\")\n",
|
| 100 |
+
"\n",
|
| 101 |
+
"# gemini = OpenAI(api_key=google_api_key, base_url=\"https://generativelanguage.googleapis.com/v1beta/openai/\")\n"
|
| 102 |
+
]
|
| 103 |
+
},
|
| 104 |
+
{
|
| 105 |
+
"cell_type": "code",
|
| 106 |
+
"execution_count": 19,
|
| 107 |
+
"id": "997f9adf",
|
| 108 |
+
"metadata": {},
|
| 109 |
+
"outputs": [],
|
| 110 |
+
"source": [
|
| 111 |
+
"from openai import OpenAI\n",
|
| 112 |
+
"import base64\n",
|
| 113 |
+
"\n",
|
| 114 |
+
"client = OpenAI(api_key=OPENAI_API_KEY)\n",
|
| 115 |
+
"\n",
|
| 116 |
+
"def to_base64_image(image_path: Path):\n",
|
| 117 |
+
" return base64.b64encode(image_path.read_bytes()).decode(\"utf-8\")\n",
|
| 118 |
+
"\n",
|
| 119 |
+
"def anatomy_to_prompt(image_path: Path):\n",
|
| 120 |
+
" \"\"\"\n",
|
| 121 |
+
" Agent step:\n",
|
| 122 |
+
" 1) Understand anatomy/tissue type + staining + constraints\n",
|
| 123 |
+
" 2) Output a prompt to generate 1 synthetic image (same constraints)\n",
|
| 124 |
+
" \"\"\"\n",
|
| 125 |
+
" \n",
|
| 126 |
+
" print(\"\\n\" + \"=\"*80)\n",
|
| 127 |
+
" print(f\"π§ AGENT: Analyzing image -> {image_path.name}\")\n",
|
| 128 |
+
"\n",
|
| 129 |
+
" b64 = to_base64_image(image_path)\n",
|
| 130 |
+
"\n",
|
| 131 |
+
"# system = \"\"\"You are a medical imaging expert assistant.\n",
|
| 132 |
+
"# You must inspect the image and generate a SHORT prompt for synthetic image generation.\n",
|
| 133 |
+
"# Constraints:\n",
|
| 134 |
+
"# - Preserve tissue type and anatomical structure, tissue is of human\n",
|
| 135 |
+
"# - Preserve staining style (H&E etc.)\n",
|
| 136 |
+
"# - No text, no watermark, no labels\n",
|
| 137 |
+
"# - Realistic microscopy / histopathology look\n",
|
| 138 |
+
"# Return ONLY JSON with keys:\n",
|
| 139 |
+
"# {\n",
|
| 140 |
+
"# \"anatomy_guess\": \"...\",\n",
|
| 141 |
+
"# \"stain_guess\": \"...\",\n",
|
| 142 |
+
"# \"prompt\": \"...\",\n",
|
| 143 |
+
"# \"negative_prompt\": \"...\"\n",
|
| 144 |
+
"# }\n",
|
| 145 |
+
"# \"\"\"\n",
|
| 146 |
+
"\n",
|
| 147 |
+
" system = \"\"\"\n",
|
| 148 |
+
"You are a medical imaging expert specializing in cytology and histopathology.\n",
|
| 149 |
+
"\n",
|
| 150 |
+
"TASK:\n",
|
| 151 |
+
"Inspect the provided microscopy image and generate a diffusion-ready text prompt\n",
|
| 152 |
+
"to synthesize ONE realistic synthetic image with the SAME visual constraints.\n",
|
| 153 |
+
"\n",
|
| 154 |
+
"STRICT RULES:\n",
|
| 155 |
+
"- Tissue is human breast (do NOT guess subtypes unless visually obvious)\n",
|
| 156 |
+
"- Describe ONLY what is visually observable\n",
|
| 157 |
+
"- Preserve staining style exactly as seen\n",
|
| 158 |
+
"- Preserve cellularity, nuclear morphology, and spatial arrangement\n",
|
| 159 |
+
"- Use concise, comma-separated phrases (diffusion prompt style)\n",
|
| 160 |
+
"- Do NOT write full sentences\n",
|
| 161 |
+
"- Do NOT repeat concepts\n",
|
| 162 |
+
"- Do NOT add interpretations, diagnoses, or probabilities\n",
|
| 163 |
+
"- No text, no watermark, no labels\n",
|
| 164 |
+
"\n",
|
| 165 |
+
"OUTPUT FORMAT (JSON ONLY):\n",
|
| 166 |
+
"{\n",
|
| 167 |
+
" \"anatomy_guess\": \"concise visual description of breast cytology / histology\",\n",
|
| 168 |
+
" \"stain_guess\": \"observed stain only\",\n",
|
| 169 |
+
" \"prompt\": \"comma-separated diffusion prompt describing malignant breast cytomorphology\",\n",
|
| 170 |
+
" \"negative_prompt\": \"comma-separated exclusions including benign breast features and artifacts\"\n",
|
| 171 |
+
"}\n",
|
| 172 |
+
"\n",
|
| 173 |
+
"NEGATIVE PROMPT MUST EXCLUDE:\n",
|
| 174 |
+
"- benign breast epithelial patterns\n",
|
| 175 |
+
"- myoepithelial cell layers\n",
|
| 176 |
+
"- uniform nuclei\n",
|
| 177 |
+
"- abundant cytoplasm\n",
|
| 178 |
+
"- inflammatory predominance\n",
|
| 179 |
+
"- stromal or histopathology sections\n",
|
| 180 |
+
"- incorrect stains (e.g. H&E if not present)\n",
|
| 181 |
+
"- labels, annotations, scale bars\n",
|
| 182 |
+
"- cartoon or synthetic appearance\n",
|
| 183 |
+
"\"\"\"\n",
|
| 184 |
+
"\n",
|
| 185 |
+
"\n",
|
| 186 |
+
" resp = client.chat.completions.create(\n",
|
| 187 |
+
" model=\"gpt-4o-mini\",\n",
|
| 188 |
+
" response_format={\"type\":\"json_object\"},\n",
|
| 189 |
+
" messages=[\n",
|
| 190 |
+
" {\"role\":\"system\", \"content\": system},\n",
|
| 191 |
+
" {\"role\":\"user\", \"content\": [\n",
|
| 192 |
+
" {\"type\":\"text\", \"text\": \"Look at this medical microscopy image and produce the JSON output.\"},\n",
|
| 193 |
+
" {\"type\":\"image_url\", \"image_url\": {\"url\": f\"data:image/png;base64,{b64}\"}}\n",
|
| 194 |
+
" ]}\n",
|
| 195 |
+
" ],\n",
|
| 196 |
+
" temperature=0.4\n",
|
| 197 |
+
" )\n",
|
| 198 |
+
"\n",
|
| 199 |
+
" # resp = gemini.chat.completions.create(\n",
|
| 200 |
+
" # model=\"gemini-3-flash-preview\",\n",
|
| 201 |
+
" # response_format={\"type\":\"json_object\"},\n",
|
| 202 |
+
" # messages=[\n",
|
| 203 |
+
" # {\"role\":\"system\", \"content\": system},\n",
|
| 204 |
+
" # {\"role\":\"user\", \"content\": [\n",
|
| 205 |
+
" # {\"type\":\"text\", \"text\": \"Look at this medical microscopy image and produce the JSON output.\"},\n",
|
| 206 |
+
" # {\"type\":\"image_url\", \"image_url\": {\"url\": f\"data:image/png;base64,{b64}\"}}\n",
|
| 207 |
+
" # ]}\n",
|
| 208 |
+
" # ],\n",
|
| 209 |
+
" # temperature=0.4\n",
|
| 210 |
+
" # )\n",
|
| 211 |
+
"\n",
|
| 212 |
+
"\n",
|
| 213 |
+
" \n",
|
| 214 |
+
"\n",
|
| 215 |
+
" data = resp.choices[0].message.content\n",
|
| 216 |
+
" print(\"β
AGENT: Prompt JSON created\")\n",
|
| 217 |
+
" print(\"π¦ RAW JSON:\", data)\n",
|
| 218 |
+
"\n",
|
| 219 |
+
" import json\n",
|
| 220 |
+
" return json.loads(data)\n"
|
| 221 |
+
]
|
| 222 |
+
},
|
| 223 |
+
{
|
| 224 |
+
"cell_type": "code",
|
| 225 |
+
"execution_count": 20,
|
| 226 |
+
"id": "641ef424",
|
| 227 |
+
"metadata": {},
|
| 228 |
+
"outputs": [
|
| 229 |
+
{
|
| 230 |
+
"name": "stderr",
|
| 231 |
+
"output_type": "stream",
|
| 232 |
+
"text": [
|
| 233 |
+
"c:\\Users\\ASUS\\projects\\.venv\\Lib\\site-packages\\diffusers\\models\\transformers\\transformer_kandinsky.py:168: UserWarning: CUDA is not available or torch_xla is imported. Disabling autocast.\n",
|
| 234 |
+
" @torch.autocast(device_type=\"cuda\", dtype=torch.float32)\n",
|
| 235 |
+
"c:\\Users\\ASUS\\projects\\.venv\\Lib\\site-packages\\diffusers\\models\\transformers\\transformer_kandinsky.py:272: UserWarning: CUDA is not available or torch_xla is imported. Disabling autocast.\n",
|
| 236 |
+
" @torch.autocast(device_type=\"cuda\", dtype=torch.float32)\n"
|
| 237 |
+
]
|
| 238 |
+
},
|
| 239 |
+
{
|
| 240 |
+
"name": "stdout",
|
| 241 |
+
"output_type": "stream",
|
| 242 |
+
"text": [
|
| 243 |
+
"π₯οΈ Device: cpu\n",
|
| 244 |
+
"β³ Loading Stable Diffusion img2img model...\n"
|
| 245 |
+
]
|
| 246 |
+
},
|
| 247 |
+
{
|
| 248 |
+
"data": {
|
| 249 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 250 |
+
"model_id": "88291aa8d2b147ddbe51e60d45e261d1",
|
| 251 |
+
"version_major": 2,
|
| 252 |
+
"version_minor": 0
|
| 253 |
+
},
|
| 254 |
+
"text/plain": [
|
| 255 |
+
"Loading pipeline components...: 0%| | 0/6 [00:00<?, ?it/s]"
|
| 256 |
+
]
|
| 257 |
+
},
|
| 258 |
+
"metadata": {},
|
| 259 |
+
"output_type": "display_data"
|
| 260 |
+
},
|
| 261 |
+
{
|
| 262 |
+
"data": {
|
| 263 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 264 |
+
"model_id": "98136e25602c4a52b118263cd6f226ad",
|
| 265 |
+
"version_major": 2,
|
| 266 |
+
"version_minor": 0
|
| 267 |
+
},
|
| 268 |
+
"text/plain": [
|
| 269 |
+
"Loading weights: 0%| | 0/196 [00:00<?, ?it/s]"
|
| 270 |
+
]
|
| 271 |
+
},
|
| 272 |
+
"metadata": {},
|
| 273 |
+
"output_type": "display_data"
|
| 274 |
+
},
|
| 275 |
+
{
|
| 276 |
+
"name": "stderr",
|
| 277 |
+
"output_type": "stream",
|
| 278 |
+
"text": [
|
| 279 |
+
"CLIPTextModel LOAD REPORT from: C:\\Users\\ASUS\\.cache\\huggingface\\hub\\models--runwayml--stable-diffusion-v1-5\\snapshots\\451f4fe16113bff5a5d2269ed5ad43b0592e9a14\\text_encoder\n",
|
| 280 |
+
"Key | Status | | \n",
|
| 281 |
+
"-----------------------------------+------------+--+-\n",
|
| 282 |
+
"text_model.embeddings.position_ids | UNEXPECTED | | \n",
|
| 283 |
+
"\n",
|
| 284 |
+
"Notes:\n",
|
| 285 |
+
"- UNEXPECTED\t:can be ignored when loading from different task/architecture; not ok if you expect identical arch.\n",
|
| 286 |
+
"You have disabled the safety checker for <class 'diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion_img2img.StableDiffusionImg2ImgPipeline'> by passing `safety_checker=None`. Ensure that you abide to the conditions of the Stable Diffusion license and do not expose unfiltered results in services or applications open to the public. Both the diffusers team and Hugging Face strongly recommend to keep the safety filter enabled in all public facing circumstances, disabling it only for use-cases that involve analyzing network behavior or auditing its results. For more information, please have a look at https://github.com/huggingface/diffusers/pull/254 .\n"
|
| 287 |
+
]
|
| 288 |
+
},
|
| 289 |
+
{
|
| 290 |
+
"name": "stdout",
|
| 291 |
+
"output_type": "stream",
|
| 292 |
+
"text": [
|
| 293 |
+
"β
Model loaded\n"
|
| 294 |
+
]
|
| 295 |
+
}
|
| 296 |
+
],
|
| 297 |
+
"source": [
|
| 298 |
+
"import torch\n",
|
| 299 |
+
"from diffusers import StableDiffusionImg2ImgPipeline\n",
|
| 300 |
+
"from PIL import Image\n",
|
| 301 |
+
"\n",
|
| 302 |
+
"device = \"cuda\" if torch.cuda.is_available() else \"cpu\"\n",
|
| 303 |
+
"print(\"π₯οΈ Device:\", device)\n",
|
| 304 |
+
"\n",
|
| 305 |
+
"print(\"β³ Loading Stable Diffusion img2img model...\")\n",
|
| 306 |
+
"pipe = StableDiffusionImg2ImgPipeline.from_pretrained(\n",
|
| 307 |
+
" \"runwayml/stable-diffusion-v1-5\",\n",
|
| 308 |
+
" torch_dtype=torch.float16 if device==\"cuda\" else torch.float32,\n",
|
| 309 |
+
" safety_checker=None\n",
|
| 310 |
+
").to(device)\n",
|
| 311 |
+
"\n",
|
| 312 |
+
"print(\"β
Model loaded\")\n"
|
| 313 |
+
]
|
| 314 |
+
},
|
| 315 |
+
{
|
| 316 |
+
"cell_type": "markdown",
|
| 317 |
+
"id": "b4f0cf6b",
|
| 318 |
+
"metadata": {},
|
| 319 |
+
"source": [
|
| 320 |
+
"`try to vary strength(0.35 β 0.55) how much output change from input`"
|
| 321 |
+
]
|
| 322 |
+
},
|
| 323 |
+
{
|
| 324 |
+
"cell_type": "markdown",
|
| 325 |
+
"id": "87817ad7",
|
| 326 |
+
"metadata": {},
|
| 327 |
+
"source": [
|
| 328 |
+
"`for faster response reduce num_inference_steps(denoising) to 25-35`"
|
| 329 |
+
]
|
| 330 |
+
},
|
| 331 |
+
{
|
| 332 |
+
"cell_type": "code",
|
| 333 |
+
"execution_count": null,
|
| 334 |
+
"id": "22f99396",
|
| 335 |
+
"metadata": {},
|
| 336 |
+
"outputs": [],
|
| 337 |
+
"source": []
|
| 338 |
+
},
|
| 339 |
+
{
|
| 340 |
+
"cell_type": "code",
|
| 341 |
+
"execution_count": null,
|
| 342 |
+
"metadata": {},
|
| 343 |
+
"outputs": [],
|
| 344 |
+
"source": []
|
| 345 |
+
},
|
| 346 |
+
{
|
| 347 |
+
"cell_type": "code",
|
| 348 |
+
"execution_count": 23,
|
| 349 |
+
"id": "a8694154",
|
| 350 |
+
"metadata": {},
|
| 351 |
+
"outputs": [],
|
| 352 |
+
"source": [
|
| 353 |
+
"\n",
|
| 354 |
+
"def generate_one_synthetic(image_path: Path, strength=0.35):\n",
|
| 355 |
+
" \"\"\"\n",
|
| 356 |
+
" strength controls how much the generated image changes:\n",
|
| 357 |
+
" - 0.2 = very similar\n",
|
| 358 |
+
" - 0.45 = good synthetic variation\n",
|
| 359 |
+
" - 0.7 = large change\n",
|
| 360 |
+
" \"\"\"\n",
|
| 361 |
+
" meta = anatomy_to_prompt(image_path)\n",
|
| 362 |
+
" \n",
|
| 363 |
+
" print(\"\\nπ― AGENT OUTPUT SUMMARY\")\n",
|
| 364 |
+
" print(\" Anatomy guess:\", meta.get(\"anatomy_guess\"))\n",
|
| 365 |
+
" print(\" Stain guess :\", meta.get(\"stain_guess\"))\n",
|
| 366 |
+
" print(\" Prompt :\", meta.get(\"prompt\"))\n",
|
| 367 |
+
" print(\" Neg Prompt :\", meta.get(\"negative_prompt\"))\n",
|
| 368 |
+
"\n",
|
| 369 |
+
" print(\"\\nπ§ͺ GENERATION: Starting diffusion img2img...\")\n",
|
| 370 |
+
" \n",
|
| 371 |
+
" init_img = Image.open(image_path).convert(\"RGB\").resize((512,512))\n",
|
| 372 |
+
" \n",
|
| 373 |
+
" out_img = pipe(\n",
|
| 374 |
+
" prompt=meta[\"prompt\"],\n",
|
| 375 |
+
" negative_prompt=meta[\"negative_prompt\"],\n",
|
| 376 |
+
" image=init_img,\n",
|
| 377 |
+
" strength=strength,\n",
|
| 378 |
+
" guidance_scale=7.5,\n",
|
| 379 |
+
" num_inference_steps=28\n",
|
| 380 |
+
" ).images[0]\n",
|
| 381 |
+
"\n",
|
| 382 |
+
" out_path = OUTPUT_DIR / f\"{image_path.stem}_synthetic.png\"\n",
|
| 383 |
+
" out_img.save(out_path)\n",
|
| 384 |
+
"\n",
|
| 385 |
+
" print(\"β
GENERATION DONE\")\n",
|
| 386 |
+
" print(\"πΎ Saved:\", out_path.resolve())\n",
|
| 387 |
+
" \n",
|
| 388 |
+
" return out_path\n",
|
| 389 |
+
"\n"
|
| 390 |
+
]
|
| 391 |
+
},
|
| 392 |
+
{
|
| 393 |
+
"cell_type": "code",
|
| 394 |
+
"execution_count": null,
|
| 395 |
+
"id": "0f335c69",
|
| 396 |
+
"metadata": {},
|
| 397 |
+
"outputs": [
|
| 398 |
+
{
|
| 399 |
+
"name": "stdout",
|
| 400 |
+
"output_type": "stream",
|
| 401 |
+
"text": [
|
| 402 |
+
"π Found 8 images\n"
|
| 403 |
+
]
|
| 404 |
+
},
|
| 405 |
+
{
|
| 406 |
+
"name": "stderr",
|
| 407 |
+
"output_type": "stream",
|
| 408 |
+
"text": [
|
| 409 |
+
" 0%| | 0/8 [00:00<?, ?it/s]"
|
| 410 |
+
]
|
| 411 |
+
},
|
| 412 |
+
{
|
| 413 |
+
"name": "stdout",
|
| 414 |
+
"output_type": "stream",
|
| 415 |
+
"text": [
|
| 416 |
+
"\n",
|
| 417 |
+
"##########################################################################################\n",
|
| 418 |
+
"π Processing: SOB_M_DC-14-16448-400-006.png\n",
|
| 419 |
+
"\n",
|
| 420 |
+
"================================================================================\n",
|
| 421 |
+
"π§ AGENT: Analyzing image -> SOB_M_DC-14-16448-400-006.png\n",
|
| 422 |
+
"β
AGENT: Prompt JSON created\n",
|
| 423 |
+
"π¦ RAW JSON: {\n",
|
| 424 |
+
" \"anatomy_guess\": \"human breast tissue, disorganized cellular arrangement, irregular nuclear shapes\",\n",
|
| 425 |
+
" \"stain_guess\": \"H&E\",\n",
|
| 426 |
+
" \"prompt\": \"disorganized cellular architecture, irregular nuclear contours, hyperchromatic nuclei, scant cytoplasm, necrotic debris, varying cell sizes, increased nuclear-to-cytoplasmic ratio\",\n",
|
| 427 |
+
" \"negative_prompt\": \"benign breast epithelial patterns, myoepithelial cell layers, uniform nuclei, abundant cytoplasm, inflammatory predominance, stromal or histopathology sections, incorrect stains, labels, annotations, scale bars, cartoon or synthetic appearance\"\n",
|
| 428 |
+
"}\n",
|
| 429 |
+
"\n",
|
| 430 |
+
"π― AGENT OUTPUT SUMMARY\n",
|
| 431 |
+
" Anatomy guess: human breast tissue, disorganized cellular arrangement, irregular nuclear shapes\n",
|
| 432 |
+
" Stain guess : H&E\n",
|
| 433 |
+
" Prompt : disorganized cellular architecture, irregular nuclear contours, hyperchromatic nuclei, scant cytoplasm, necrotic debris, varying cell sizes, increased nuclear-to-cytoplasmic ratio\n",
|
| 434 |
+
" Neg Prompt : benign breast epithelial patterns, myoepithelial cell layers, uniform nuclei, abundant cytoplasm, inflammatory predominance, stromal or histopathology sections, incorrect stains, labels, annotations, scale bars, cartoon or synthetic appearance\n",
|
| 435 |
+
"\n",
|
| 436 |
+
"π§ͺ GENERATION: Starting diffusion img2img...\n"
|
| 437 |
+
]
|
| 438 |
+
},
|
| 439 |
+
{
|
| 440 |
+
"data": {
|
| 441 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 442 |
+
"model_id": "49b39422794f44579167cf83321fb2c7",
|
| 443 |
+
"version_major": 2,
|
| 444 |
+
"version_minor": 0
|
| 445 |
+
},
|
| 446 |
+
"text/plain": [
|
| 447 |
+
" 0%| | 0/12 [00:00<?, ?it/s]"
|
| 448 |
+
]
|
| 449 |
+
},
|
| 450 |
+
"metadata": {},
|
| 451 |
+
"output_type": "display_data"
|
| 452 |
+
},
|
| 453 |
+
{
|
| 454 |
+
"name": "stderr",
|
| 455 |
+
"output_type": "stream",
|
| 456 |
+
"text": [
|
| 457 |
+
" 12%|ββ | 1/8 [03:16<22:52, 196.10s/it]"
|
| 458 |
+
]
|
| 459 |
+
},
|
| 460 |
+
{
|
| 461 |
+
"name": "stdout",
|
| 462 |
+
"output_type": "stream",
|
| 463 |
+
"text": [
|
| 464 |
+
"β
GENERATION DONE\n",
|
| 465 |
+
"πΎ Saved: C:\\Users\\ASUS\\projects\\agents\\1_foundations\\synthetic_output\\SOB_M_DC-14-16448-400-006_synthetic.png\n",
|
| 466 |
+
"β
Completed: SOB_M_DC-14-16448-400-006.png\n",
|
| 467 |
+
"\n",
|
| 468 |
+
"##########################################################################################\n",
|
| 469 |
+
"π Processing: SOB_M_DC-14-16448-400-008.png\n",
|
| 470 |
+
"\n",
|
| 471 |
+
"================================================================================\n",
|
| 472 |
+
"π§ AGENT: Analyzing image -> SOB_M_DC-14-16448-400-008.png\n",
|
| 473 |
+
"β
AGENT: Prompt JSON created\n",
|
| 474 |
+
"π¦ RAW JSON: {\n",
|
| 475 |
+
" \"anatomy_guess\": \"human breast tissue, irregular cellular arrangement, high cellularity\",\n",
|
| 476 |
+
" \"stain_guess\": \"H&E\",\n",
|
| 477 |
+
" \"prompt\": \"abnormal nuclei, prominent nucleoli, irregular nuclear contours, scant cytoplasm, pleomorphic cells, disorganized architecture, hyperchromatic nuclei\",\n",
|
| 478 |
+
" \"negative_prompt\": \"benign breast epithelial patterns, myoepithelial cell layers, uniform nuclei, abundant cytoplasm, inflammatory predominance, stromal or histopathology sections, incorrect stains, labels, annotations, scale bars, cartoon or synthetic appearance\"\n",
|
| 479 |
+
"}\n",
|
| 480 |
+
"\n",
|
| 481 |
+
"π― AGENT OUTPUT SUMMARY\n",
|
| 482 |
+
" Anatomy guess: human breast tissue, irregular cellular arrangement, high cellularity\n",
|
| 483 |
+
" Stain guess : H&E\n",
|
| 484 |
+
" Prompt : abnormal nuclei, prominent nucleoli, irregular nuclear contours, scant cytoplasm, pleomorphic cells, disorganized architecture, hyperchromatic nuclei\n",
|
| 485 |
+
" Neg Prompt : benign breast epithelial patterns, myoepithelial cell layers, uniform nuclei, abundant cytoplasm, inflammatory predominance, stromal or histopathology sections, incorrect stains, labels, annotations, scale bars, cartoon or synthetic appearance\n",
|
| 486 |
+
"\n",
|
| 487 |
+
"π§ͺ GENERATION: Starting diffusion img2img...\n"
|
| 488 |
+
]
|
| 489 |
+
},
|
| 490 |
+
{
|
| 491 |
+
"data": {
|
| 492 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 493 |
+
"model_id": "04e511456295434391fafaef7e5c2950",
|
| 494 |
+
"version_major": 2,
|
| 495 |
+
"version_minor": 0
|
| 496 |
+
},
|
| 497 |
+
"text/plain": [
|
| 498 |
+
" 0%| | 0/12 [00:00<?, ?it/s]"
|
| 499 |
+
]
|
| 500 |
+
},
|
| 501 |
+
"metadata": {},
|
| 502 |
+
"output_type": "display_data"
|
| 503 |
+
},
|
| 504 |
+
{
|
| 505 |
+
"name": "stderr",
|
| 506 |
+
"output_type": "stream",
|
| 507 |
+
"text": [
|
| 508 |
+
" 25%|βββ | 2/8 [06:43<20:15, 202.66s/it]"
|
| 509 |
+
]
|
| 510 |
+
},
|
| 511 |
+
{
|
| 512 |
+
"name": "stdout",
|
| 513 |
+
"output_type": "stream",
|
| 514 |
+
"text": [
|
| 515 |
+
"β
GENERATION DONE\n",
|
| 516 |
+
"πΎ Saved: C:\\Users\\ASUS\\projects\\agents\\1_foundations\\synthetic_output\\SOB_M_DC-14-16448-400-008_synthetic.png\n",
|
| 517 |
+
"β
Completed: SOB_M_DC-14-16448-400-008.png\n",
|
| 518 |
+
"\n",
|
| 519 |
+
"##########################################################################################\n",
|
| 520 |
+
"π Processing: SOB_M_DC-14-16448-400-009.png\n",
|
| 521 |
+
"\n",
|
| 522 |
+
"================================================================================\n",
|
| 523 |
+
"π§ AGENT: Analyzing image -> SOB_M_DC-14-16448-400-009.png\n",
|
| 524 |
+
"β
AGENT: Prompt JSON created\n",
|
| 525 |
+
"π¦ RAW JSON: {\n",
|
| 526 |
+
" \"anatomy_guess\": \"human breast tissue, disorganized architecture, irregular cellular arrangement\",\n",
|
| 527 |
+
" \"stain_guess\": \"H&E\",\n",
|
| 528 |
+
" \"prompt\": \"irregular nuclei, pleomorphic cells, high nuclear-to-cytoplasmic ratio, prominent nucleoli, scattered atypical cells, dense fibrous stroma, areas of necrosis\",\n",
|
| 529 |
+
" \"negative_prompt\": \"benign breast epithelial patterns, myoepithelial cell layers, uniform nuclei, abundant cytoplasm, inflammatory predominance, stromal or histopathology sections, incorrect stains, labels, annotations, scale bars, cartoon or synthetic appearance\"\n",
|
| 530 |
+
"}\n",
|
| 531 |
+
"\n",
|
| 532 |
+
"π― AGENT OUTPUT SUMMARY\n",
|
| 533 |
+
" Anatomy guess: human breast tissue, disorganized architecture, irregular cellular arrangement\n",
|
| 534 |
+
" Stain guess : H&E\n",
|
| 535 |
+
" Prompt : irregular nuclei, pleomorphic cells, high nuclear-to-cytoplasmic ratio, prominent nucleoli, scattered atypical cells, dense fibrous stroma, areas of necrosis\n",
|
| 536 |
+
" Neg Prompt : benign breast epithelial patterns, myoepithelial cell layers, uniform nuclei, abundant cytoplasm, inflammatory predominance, stromal or histopathology sections, incorrect stains, labels, annotations, scale bars, cartoon or synthetic appearance\n",
|
| 537 |
+
"\n",
|
| 538 |
+
"π§ͺ GENERATION: Starting diffusion img2img...\n"
|
| 539 |
+
]
|
| 540 |
+
},
|
| 541 |
+
{
|
| 542 |
+
"data": {
|
| 543 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 544 |
+
"model_id": "dbcb755d526e4654b2d2e4c25fdfad69",
|
| 545 |
+
"version_major": 2,
|
| 546 |
+
"version_minor": 0
|
| 547 |
+
},
|
| 548 |
+
"text/plain": [
|
| 549 |
+
" 0%| | 0/12 [00:00<?, ?it/s]"
|
| 550 |
+
]
|
| 551 |
+
},
|
| 552 |
+
"metadata": {},
|
| 553 |
+
"output_type": "display_data"
|
| 554 |
+
},
|
| 555 |
+
{
|
| 556 |
+
"name": "stderr",
|
| 557 |
+
"output_type": "stream",
|
| 558 |
+
"text": [
|
| 559 |
+
" 38%|ββββ | 3/8 [10:00<16:39, 199.97s/it]"
|
| 560 |
+
]
|
| 561 |
+
},
|
| 562 |
+
{
|
| 563 |
+
"name": "stdout",
|
| 564 |
+
"output_type": "stream",
|
| 565 |
+
"text": [
|
| 566 |
+
"β
GENERATION DONE\n",
|
| 567 |
+
"πΎ Saved: C:\\Users\\ASUS\\projects\\agents\\1_foundations\\synthetic_output\\SOB_M_DC-14-16448-400-009_synthetic.png\n",
|
| 568 |
+
"β
Completed: SOB_M_DC-14-16448-400-009.png\n",
|
| 569 |
+
"\n",
|
| 570 |
+
"##########################################################################################\n",
|
| 571 |
+
"π Processing: SOB_M_DC-14-16448-400-011.png\n",
|
| 572 |
+
"\n",
|
| 573 |
+
"================================================================================\n",
|
| 574 |
+
"π§ AGENT: Analyzing image -> SOB_M_DC-14-16448-400-011.png\n",
|
| 575 |
+
"β
AGENT: Prompt JSON created\n",
|
| 576 |
+
"π¦ RAW JSON: {\n",
|
| 577 |
+
" \"anatomy_guess\": \"human breast tissue with dense cellular arrangement\",\n",
|
| 578 |
+
" \"stain_guess\": \"H&E\",\n",
|
| 579 |
+
" \"prompt\": \"irregularly shaped nuclei, prominent nucleoli, eosinophilic cytoplasm, scattered atypical cells, dense fibrous stroma, varied nuclear sizes, disrupted architecture\",\n",
|
| 580 |
+
" \"negative_prompt\": \"benign breast epithelial patterns, myoepithelial cell layers, uniform nuclei, abundant cytoplasm, inflammatory predominance, stromal or histopathology sections, incorrect stains, labels, annotations, scale bars, cartoon or synthetic appearance\"\n",
|
| 581 |
+
"}\n",
|
| 582 |
+
"\n",
|
| 583 |
+
"π― AGENT OUTPUT SUMMARY\n",
|
| 584 |
+
" Anatomy guess: human breast tissue with dense cellular arrangement\n",
|
| 585 |
+
" Stain guess : H&E\n",
|
| 586 |
+
" Prompt : irregularly shaped nuclei, prominent nucleoli, eosinophilic cytoplasm, scattered atypical cells, dense fibrous stroma, varied nuclear sizes, disrupted architecture\n",
|
| 587 |
+
" Neg Prompt : benign breast epithelial patterns, myoepithelial cell layers, uniform nuclei, abundant cytoplasm, inflammatory predominance, stromal or histopathology sections, incorrect stains, labels, annotations, scale bars, cartoon or synthetic appearance\n",
|
| 588 |
+
"\n",
|
| 589 |
+
"π§ͺ GENERATION: Starting diffusion img2img...\n"
|
| 590 |
+
]
|
| 591 |
+
},
|
| 592 |
+
{
|
| 593 |
+
"data": {
|
| 594 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 595 |
+
"model_id": "7aae4a1fc4364434b26f699508813f54",
|
| 596 |
+
"version_major": 2,
|
| 597 |
+
"version_minor": 0
|
| 598 |
+
},
|
| 599 |
+
"text/plain": [
|
| 600 |
+
" 0%| | 0/12 [00:00<?, ?it/s]"
|
| 601 |
+
]
|
| 602 |
+
},
|
| 603 |
+
"metadata": {},
|
| 604 |
+
"output_type": "display_data"
|
| 605 |
+
},
|
| 606 |
+
{
|
| 607 |
+
"name": "stderr",
|
| 608 |
+
"output_type": "stream",
|
| 609 |
+
"text": [
|
| 610 |
+
" 50%|βββββ | 4/8 [12:41<12:18, 184.65s/it]"
|
| 611 |
+
]
|
| 612 |
+
},
|
| 613 |
+
{
|
| 614 |
+
"name": "stdout",
|
| 615 |
+
"output_type": "stream",
|
| 616 |
+
"text": [
|
| 617 |
+
"β
GENERATION DONE\n",
|
| 618 |
+
"πΎ Saved: C:\\Users\\ASUS\\projects\\agents\\1_foundations\\synthetic_output\\SOB_M_DC-14-16448-400-011_synthetic.png\n",
|
| 619 |
+
"β
Completed: SOB_M_DC-14-16448-400-011.png\n",
|
| 620 |
+
"\n",
|
| 621 |
+
"##########################################################################################\n",
|
| 622 |
+
"π Processing: SOB_M_DC-14-16448-400-012.png\n",
|
| 623 |
+
"\n",
|
| 624 |
+
"================================================================================\n",
|
| 625 |
+
"π§ AGENT: Analyzing image -> SOB_M_DC-14-16448-400-012.png\n",
|
| 626 |
+
"β
AGENT: Prompt JSON created\n",
|
| 627 |
+
"π¦ RAW JSON: {\n",
|
| 628 |
+
" \"anatomy_guess\": \"human breast tissue, fibrous stroma, scattered cells\",\n",
|
| 629 |
+
" \"stain_guess\": \"H&E\",\n",
|
| 630 |
+
" \"prompt\": \"pink-stained fibrous tissue, irregularly shaped cells, scattered nuclei, thin collagen fibers, high cellularity, varying nuclear sizes, prominent nucleoli\",\n",
|
| 631 |
+
" \"negative_prompt\": \"benign breast epithelial patterns, myoepithelial cell layers, uniform nuclei, abundant cytoplasm, inflammatory predominance, stromal or histopathology sections, incorrect stains, labels, annotations, scale bars, cartoon or synthetic appearance\"\n",
|
| 632 |
+
"}\n",
|
| 633 |
+
"\n",
|
| 634 |
+
"π― AGENT OUTPUT SUMMARY\n",
|
| 635 |
+
" Anatomy guess: human breast tissue, fibrous stroma, scattered cells\n",
|
| 636 |
+
" Stain guess : H&E\n",
|
| 637 |
+
" Prompt : pink-stained fibrous tissue, irregularly shaped cells, scattered nuclei, thin collagen fibers, high cellularity, varying nuclear sizes, prominent nucleoli\n",
|
| 638 |
+
" Neg Prompt : benign breast epithelial patterns, myoepithelial cell layers, uniform nuclei, abundant cytoplasm, inflammatory predominance, stromal or histopathology sections, incorrect stains, labels, annotations, scale bars, cartoon or synthetic appearance\n",
|
| 639 |
+
"\n",
|
| 640 |
+
"π§ͺ GENERATION: Starting diffusion img2img...\n"
|
| 641 |
+
]
|
| 642 |
+
},
|
| 643 |
+
{
|
| 644 |
+
"data": {
|
| 645 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 646 |
+
"model_id": "d92c36f80aa948babcc732b02d88bddb",
|
| 647 |
+
"version_major": 2,
|
| 648 |
+
"version_minor": 0
|
| 649 |
+
},
|
| 650 |
+
"text/plain": [
|
| 651 |
+
" 0%| | 0/12 [00:00<?, ?it/s]"
|
| 652 |
+
]
|
| 653 |
+
},
|
| 654 |
+
"metadata": {},
|
| 655 |
+
"output_type": "display_data"
|
| 656 |
+
},
|
| 657 |
+
{
|
| 658 |
+
"name": "stderr",
|
| 659 |
+
"output_type": "stream",
|
| 660 |
+
"text": [
|
| 661 |
+
" 62%|βββββββ | 5/8 [15:53<09:22, 187.46s/it]"
|
| 662 |
+
]
|
| 663 |
+
},
|
| 664 |
+
{
|
| 665 |
+
"name": "stdout",
|
| 666 |
+
"output_type": "stream",
|
| 667 |
+
"text": [
|
| 668 |
+
"β
GENERATION DONE\n",
|
| 669 |
+
"πΎ Saved: C:\\Users\\ASUS\\projects\\agents\\1_foundations\\synthetic_output\\SOB_M_DC-14-16448-400-012_synthetic.png\n",
|
| 670 |
+
"β
Completed: SOB_M_DC-14-16448-400-012.png\n",
|
| 671 |
+
"\n",
|
| 672 |
+
"##########################################################################################\n",
|
| 673 |
+
"π Processing: SOB_M_DC-14-16448-400-013.png\n",
|
| 674 |
+
"\n",
|
| 675 |
+
"================================================================================\n",
|
| 676 |
+
"π§ AGENT: Analyzing image -> SOB_M_DC-14-16448-400-013.png\n",
|
| 677 |
+
"β
AGENT: Prompt JSON created\n",
|
| 678 |
+
"π¦ RAW JSON: {\n",
|
| 679 |
+
" \"anatomy_guess\": \"human breast tissue, fibrous stroma, scattered cells\",\n",
|
| 680 |
+
" \"stain_guess\": \"H&E\",\n",
|
| 681 |
+
" \"prompt\": \"fibroblasts, elongated nuclei, irregular cell shapes, dense collagen fibers, pink and purple staining, scattered cellularity\",\n",
|
| 682 |
+
" \"negative_prompt\": \"benign breast epithelial patterns, myoepithelial cell layers, uniform nuclei, abundant cytoplasm, inflammatory predominance, stromal or histopathology sections, incorrect stains, labels, annotations, scale bars, cartoon or synthetic appearance\"\n",
|
| 683 |
+
"}\n",
|
| 684 |
+
"\n",
|
| 685 |
+
"π― AGENT OUTPUT SUMMARY\n",
|
| 686 |
+
" Anatomy guess: human breast tissue, fibrous stroma, scattered cells\n",
|
| 687 |
+
" Stain guess : H&E\n",
|
| 688 |
+
" Prompt : fibroblasts, elongated nuclei, irregular cell shapes, dense collagen fibers, pink and purple staining, scattered cellularity\n",
|
| 689 |
+
" Neg Prompt : benign breast epithelial patterns, myoepithelial cell layers, uniform nuclei, abundant cytoplasm, inflammatory predominance, stromal or histopathology sections, incorrect stains, labels, annotations, scale bars, cartoon or synthetic appearance\n",
|
| 690 |
+
"\n",
|
| 691 |
+
"π§ͺ GENERATION: Starting diffusion img2img...\n"
|
| 692 |
+
]
|
| 693 |
+
},
|
| 694 |
+
{
|
| 695 |
+
"data": {
|
| 696 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 697 |
+
"model_id": "518bb8f999254edd8204ab407fcca5af",
|
| 698 |
+
"version_major": 2,
|
| 699 |
+
"version_minor": 0
|
| 700 |
+
},
|
| 701 |
+
"text/plain": [
|
| 702 |
+
" 0%| | 0/12 [00:00<?, ?it/s]"
|
| 703 |
+
]
|
| 704 |
+
},
|
| 705 |
+
"metadata": {},
|
| 706 |
+
"output_type": "display_data"
|
| 707 |
+
},
|
| 708 |
+
{
|
| 709 |
+
"name": "stderr",
|
| 710 |
+
"output_type": "stream",
|
| 711 |
+
"text": [
|
| 712 |
+
" 75%|ββββββββ | 6/8 [19:15<06:24, 192.26s/it]"
|
| 713 |
+
]
|
| 714 |
+
},
|
| 715 |
+
{
|
| 716 |
+
"name": "stdout",
|
| 717 |
+
"output_type": "stream",
|
| 718 |
+
"text": [
|
| 719 |
+
"β
GENERATION DONE\n",
|
| 720 |
+
"πΎ Saved: C:\\Users\\ASUS\\projects\\agents\\1_foundations\\synthetic_output\\SOB_M_DC-14-16448-400-013_synthetic.png\n",
|
| 721 |
+
"β
Completed: SOB_M_DC-14-16448-400-013.png\n",
|
| 722 |
+
"\n",
|
| 723 |
+
"##########################################################################################\n",
|
| 724 |
+
"π Processing: SOB_M_DC-14-16448-400-014.png\n",
|
| 725 |
+
"\n",
|
| 726 |
+
"================================================================================\n",
|
| 727 |
+
"π§ AGENT: Analyzing image -> SOB_M_DC-14-16448-400-014.png\n",
|
| 728 |
+
"β
AGENT: Prompt JSON created\n",
|
| 729 |
+
"π¦ RAW JSON: {\n",
|
| 730 |
+
" \"anatomy_guess\": \"human breast tissue, fibrous stroma, scattered cells\",\n",
|
| 731 |
+
" \"stain_guess\": \"H&E\",\n",
|
| 732 |
+
" \"prompt\": \"pink and purple staining, elongated fibrous structures, irregular cell shapes, scattered dark nuclei, background of eosinophilic material, moderate cellularity\",\n",
|
| 733 |
+
" \"negative_prompt\": \"benign breast epithelial patterns, myoepithelial cell layers, uniform nuclei, abundant cytoplasm, inflammatory predominance, stromal or histopathology sections, incorrect stains, labels, annotations, scale bars, cartoon or synthetic appearance\"\n",
|
| 734 |
+
"}\n",
|
| 735 |
+
"\n",
|
| 736 |
+
"π― AGENT OUTPUT SUMMARY\n",
|
| 737 |
+
" Anatomy guess: human breast tissue, fibrous stroma, scattered cells\n",
|
| 738 |
+
" Stain guess : H&E\n",
|
| 739 |
+
" Prompt : pink and purple staining, elongated fibrous structures, irregular cell shapes, scattered dark nuclei, background of eosinophilic material, moderate cellularity\n",
|
| 740 |
+
" Neg Prompt : benign breast epithelial patterns, myoepithelial cell layers, uniform nuclei, abundant cytoplasm, inflammatory predominance, stromal or histopathology sections, incorrect stains, labels, annotations, scale bars, cartoon or synthetic appearance\n",
|
| 741 |
+
"\n",
|
| 742 |
+
"π§ͺ GENERATION: Starting diffusion img2img...\n"
|
| 743 |
+
]
|
| 744 |
+
},
|
| 745 |
+
{
|
| 746 |
+
"data": {
|
| 747 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 748 |
+
"model_id": "a1434d0255ca4bb1828a3fd0f945b926",
|
| 749 |
+
"version_major": 2,
|
| 750 |
+
"version_minor": 0
|
| 751 |
+
},
|
| 752 |
+
"text/plain": [
|
| 753 |
+
" 0%| | 0/12 [00:00<?, ?it/s]"
|
| 754 |
+
]
|
| 755 |
+
},
|
| 756 |
+
"metadata": {},
|
| 757 |
+
"output_type": "display_data"
|
| 758 |
+
},
|
| 759 |
+
{
|
| 760 |
+
"name": "stderr",
|
| 761 |
+
"output_type": "stream",
|
| 762 |
+
"text": [
|
| 763 |
+
" 88%|βββββββββ | 7/8 [24:09<03:45, 225.52s/it]"
|
| 764 |
+
]
|
| 765 |
+
},
|
| 766 |
+
{
|
| 767 |
+
"name": "stdout",
|
| 768 |
+
"output_type": "stream",
|
| 769 |
+
"text": [
|
| 770 |
+
"β
GENERATION DONE\n",
|
| 771 |
+
"πΎ Saved: C:\\Users\\ASUS\\projects\\agents\\1_foundations\\synthetic_output\\SOB_M_DC-14-16448-400-014_synthetic.png\n",
|
| 772 |
+
"β
Completed: SOB_M_DC-14-16448-400-014.png\n",
|
| 773 |
+
"\n",
|
| 774 |
+
"##########################################################################################\n",
|
| 775 |
+
"π Processing: SOB_M_DC-14-16601-400-001.png\n",
|
| 776 |
+
"\n",
|
| 777 |
+
"================================================================================\n",
|
| 778 |
+
"π§ AGENT: Analyzing image -> SOB_M_DC-14-16601-400-001.png\n",
|
| 779 |
+
"β
AGENT: Prompt JSON created\n",
|
| 780 |
+
"π¦ RAW JSON: {\n",
|
| 781 |
+
" \"anatomy_guess\": \"human breast cytology\",\n",
|
| 782 |
+
" \"stain_guess\": \"H&E\",\n",
|
| 783 |
+
" \"prompt\": \"irregular nuclei, prominent nucleoli, high nuclear-to-cytoplasmic ratio, scattered atypical cells, pleomorphic cell shapes, necrotic debris, background inflammation, pink and purple staining, cell clusters\",\n",
|
| 784 |
+
" \"negative_prompt\": \"benign breast epithelial patterns, myoepithelial cell layers, uniform nuclei, abundant cytoplasm, inflammatory predominance, stromal or histopathology sections, incorrect stains, labels, annotations, scale bars, cartoon or synthetic appearance\"\n",
|
| 785 |
+
"}\n",
|
| 786 |
+
"\n",
|
| 787 |
+
"π― AGENT OUTPUT SUMMARY\n",
|
| 788 |
+
" Anatomy guess: human breast cytology\n",
|
| 789 |
+
" Stain guess : H&E\n",
|
| 790 |
+
" Prompt : irregular nuclei, prominent nucleoli, high nuclear-to-cytoplasmic ratio, scattered atypical cells, pleomorphic cell shapes, necrotic debris, background inflammation, pink and purple staining, cell clusters\n",
|
| 791 |
+
" Neg Prompt : benign breast epithelial patterns, myoepithelial cell layers, uniform nuclei, abundant cytoplasm, inflammatory predominance, stromal or histopathology sections, incorrect stains, labels, annotations, scale bars, cartoon or synthetic appearance\n",
|
| 792 |
+
"\n",
|
| 793 |
+
"π§ͺ GENERATION: Starting diffusion img2img...\n"
|
| 794 |
+
]
|
| 795 |
+
},
|
| 796 |
+
{
|
| 797 |
+
"data": {
|
| 798 |
+
"application/vnd.jupyter.widget-view+json": {
|
| 799 |
+
"model_id": "007d766cd1994112b979d2dc9832e2f9",
|
| 800 |
+
"version_major": 2,
|
| 801 |
+
"version_minor": 0
|
| 802 |
+
},
|
| 803 |
+
"text/plain": [
|
| 804 |
+
" 0%| | 0/12 [00:00<?, ?it/s]"
|
| 805 |
+
]
|
| 806 |
+
},
|
| 807 |
+
"metadata": {},
|
| 808 |
+
"output_type": "display_data"
|
| 809 |
+
},
|
| 810 |
+
{
|
| 811 |
+
"name": "stderr",
|
| 812 |
+
"output_type": "stream",
|
| 813 |
+
"text": [
|
| 814 |
+
"100%|ββββββββββ| 8/8 [27:53<00:00, 209.18s/it]"
|
| 815 |
+
]
|
| 816 |
+
},
|
| 817 |
+
{
|
| 818 |
+
"name": "stdout",
|
| 819 |
+
"output_type": "stream",
|
| 820 |
+
"text": [
|
| 821 |
+
"β
GENERATION DONE\n",
|
| 822 |
+
"πΎ Saved: C:\\Users\\ASUS\\projects\\agents\\1_foundations\\synthetic_output\\SOB_M_DC-14-16601-400-001_synthetic.png\n",
|
| 823 |
+
"β
Completed: SOB_M_DC-14-16601-400-001.png\n"
|
| 824 |
+
]
|
| 825 |
+
},
|
| 826 |
+
{
|
| 827 |
+
"name": "stderr",
|
| 828 |
+
"output_type": "stream",
|
| 829 |
+
"text": [
|
| 830 |
+
"\n"
|
| 831 |
+
]
|
| 832 |
+
},
|
| 833 |
+
{
|
| 834 |
+
"ename": "",
|
| 835 |
+
"evalue": "",
|
| 836 |
+
"output_type": "error",
|
| 837 |
+
"traceback": [
|
| 838 |
+
"\u001b[1;31mThe Kernel crashed while executing code in the current cell or a previous cell. \n",
|
| 839 |
+
"\u001b[1;31mPlease review the code in the cell(s) to identify a possible cause of the failure. \n",
|
| 840 |
+
"\u001b[1;31mClick <a href='https://aka.ms/vscodeJupyterKernelCrash'>here</a> for more info. \n",
|
| 841 |
+
"\u001b[1;31mView Jupyter <a href='command:jupyter.viewOutput'>log</a> for further details."
|
| 842 |
+
]
|
| 843 |
+
}
|
| 844 |
+
],
|
| 845 |
+
"source": [
|
| 846 |
+
"from tqdm import tqdm\n",
|
| 847 |
+
"\n",
|
| 848 |
+
"images = list(INPUT_DIR.glob(\"*.png\")) + list(INPUT_DIR.glob(\"*.jpg\")) + list(INPUT_DIR.glob(\"*.jpeg\"))\n",
|
| 849 |
+
"\n",
|
| 850 |
+
"print(f\"π Found {len(images)} images\")\n",
|
| 851 |
+
"\n",
|
| 852 |
+
"for img_path in tqdm(images):\n",
|
| 853 |
+
" try:\n",
|
| 854 |
+
" print(\"\\n\" + \"#\"*90)\n",
|
| 855 |
+
" print(f\"π Processing: {img_path.name}\")\n",
|
| 856 |
+
" generate_one_synthetic(img_path, strength=0.45)\n",
|
| 857 |
+
" print(f\"β
Completed: {img_path.name}\")\n",
|
| 858 |
+
" except Exception as e:\n",
|
| 859 |
+
" print(f\"β Failed: {img_path.name}\")\n",
|
| 860 |
+
" print(\"Reason:\", str(e))\n"
|
| 861 |
+
]
|
| 862 |
+
},
|
| 863 |
+
{
|
| 864 |
+
"cell_type": "code",
|
| 865 |
+
"execution_count": null,
|
| 866 |
+
"id": "92463c80",
|
| 867 |
+
"metadata": {},
|
| 868 |
+
"outputs": [],
|
| 869 |
+
"source": []
|
| 870 |
+
}
|
| 871 |
+
],
|
| 872 |
+
"metadata": {
|
| 873 |
+
"kernelspec": {
|
| 874 |
+
"display_name": ".venv",
|
| 875 |
+
"language": "python",
|
| 876 |
+
"name": "python3"
|
| 877 |
+
},
|
| 878 |
+
"language_info": {
|
| 879 |
+
"codemirror_mode": {
|
| 880 |
+
"name": "ipython",
|
| 881 |
+
"version": 3
|
| 882 |
+
},
|
| 883 |
+
"file_extension": ".py",
|
| 884 |
+
"mimetype": "text/x-python",
|
| 885 |
+
"name": "python",
|
| 886 |
+
"nbconvert_exporter": "python",
|
| 887 |
+
"pygments_lexer": "ipython3",
|
| 888 |
+
"version": "3.13.7"
|
| 889 |
+
}
|
| 890 |
+
},
|
| 891 |
+
"nbformat": 4,
|
| 892 |
+
"nbformat_minor": 5
|
| 893 |
+
}
|