Spaces:
Runtime error
Runtime error
Roland Ding commited on
Commit ·
c769f48
1
Parent(s): d1682ed
11.11.27.77
Browse filesupdated as per request 2023-11-23
+ added pre_view table heading and others extension
+ updated the assessment categories to lower cases.
+ added logic to the article revision.
+ extended the task generation into input_variables and chat_prompt generation
functions.
+ added reformat_instruction function to the application.py due to
generalized instruction format.
On branch main
Changes to be committed:
modified: .data/instruction_agg_performance.json
modified: application.py
modified: backend_update.ipynb
modified: chains.py
modified: features.py
- .data/instruction_agg_performance.json +1 -1
- application.py +2 -0
- backend_update.ipynb +49 -424
- chains.py +19 -8
- features.py +44 -21
.data/instruction_agg_performance.json
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
[{"name":"clin-perfFUtable-FIN","inputs":"Change in Probing Depth\nFFI\nGlobal Rating of Change\nGood to Excellent Odom Score\nGrip Strength\nIncision Length\nJOA\nKaplan-Meier\nLikert\nMcCormick Grade\nNDI\nNeer's Grade\nPatient Improvement\nPSS\nPinch Strength\nPocket Depth\nROM\nStride Length\nSWMT\nTime to Fusion\nVAS Change\nVAS Score\nWalking Velocity\nNew Clinical Symptoms","section_sequence":"","assessment":"
|
|
|
|
| 1 |
+
[{"name":"clin-perfFUtable-FIN","inputs":"Change in Probing Depth\nFFI\nGlobal Rating of Change\nGood to Excellent Odom Score\nGrip Strength\nIncision Length\nJOA\nKaplan-Meier\nLikert\nMcCormick Grade\nNDI\nNeer's Grade\nPatient Improvement\nPSS\nPinch Strength\nPocket Depth\nROM\nStride Length\nSWMT\nTime to Fusion\nVAS Change\nVAS Score\nWalking Velocity\nNew Clinical Symptoms","section_sequence":"","assessment":"clinical","chain":["Report ALL of the information of the above text by performing the following tasks.\n\nPerform the following tasks:\n1) REPORT each table with the SAME columns as listed.\n\n\nFor Each Table\n1) Report EACH \"table heading\".\n2) Identify if the Table has Groups or NO groups. \n A) If the Table has \"Group\", Report each Group Name as written in the text. \n B) If the Table has No Group, \n 1. Add a Column 0 named: \"Group\". Column 0 will precede Column 1.\n 2. Report: \"No Group\" for each row.\n\n3) Identify if the Table has a \"Preoperative Value (Units)\" or NO \"Preoperative Value (Units)\" Heading. \n A) If the Table has \"Preoperative Value (Units)\", Report each Preoperative Value as written in the text. \n B) If the Table has NO \"Preoperative Value (Units)\" Heading. \n 1. Add a Column 3a named: \"Group\". Column 3a will follow the \"Outcome\" Column\n 2. Report: \"Not Reported\" for each row.\n\n\n4) Report the corresponding Outcome, Values, and Study N for each \"Clinical Outcome\" Table.\n A) Report each VALUE to only One Decimal Point.\n\n5) IF the table is Vertical, Transpose each VERTICAL table to a HORIZONTAL table.\n\n\n\nOverall rules:\n1) Do not exclude any Groups. \n2) Do not exclude any Tables. \n3) Do not exclude any Outcomes.\n4) Do not exclude any Values."]},{"name":"rad-perfFUtable-FIN","inputs":"Adjacent Segment ROM\nCarpal Height Ratio\nCervical Lordosis Profeta Method\nChange in Disc Height\nChange in Segmental Lordosis Angle\nCoronal Vertical Axis\nDeltoid Tuberosity Index\nDisc Height\nEngh grading scale\nFatty Atrophy\nForaminal Area Height\nFusion Assessment\nFusion Events-simplified 2\nParallel Pitch Lines\nScrew Placement Accuracy\nSegmental Lordosis Angle","section_sequence":"","assessment":"radiologic","chain":["Report ALL of the information of the above text by performing the following tasks.\n\nPerform the following tasks:\n1) REPORT each table with the SAME columns as listed.\n\n\nFor Each Table\n1) Report EACH \"table heading\".\n2) Identify if the Table has Groups or NO groups. \n A) If the Table has \"Group\", Report each Group Name as written in the text. \n B) If the Table has No Group, \n 1. Add a Column 0 named: \"Group\". Column 0 will precede Column 1.\n 2. Report: \"No Group\" for each row.\n\n3) Identify if the Table has a \"Preoperative Value (Units)\" or NO \"Preoperative Value (Units)\" Heading. \n A) If the Table has \"Preoperative Value (Units)\", Report each Preoperative Value as written in the text. \n B) If the Table has NO \"Preoperative Value (Units)\" Heading. \n 1. Add a Column 3a named: \"Group\". Column 3a will follow the \"Outcome\" Column\n 2. Report: \"Not Reported\" for each row.\n\n\n4) Report the corresponding Outcome, Values, and Study N for each \"Radiologic Outcome\" Table.\n A) Report each VALUE to only One Decimal Point.\n\n5) IF the table is Vertical, Transpose each VERTICAL table to a HORIZONTAL table.\n\n\n\nOverall rules:\n1) Do not exclude any Groups. \n2) Do not exclude any Tables. \n3) Do not exclude any Outcomes.\n4) Do not exclude any Values."]},{"name":"saf-Futable-FIN","inputs":"abb Nonunion-NG\nGeneric Combo-NG\nMerged Revision\/Reoperation-NG\nSubsidence-NG","section_sequence":"","assessment":"safety","chain":["From the above text, extract information to complete the following sections sequentially to create a TABLE. \nCreate ONE table with the following Heading and Columns.\n\nPerform the following tasks\n1) Create the following \"table heading\" as described. \n2) Create the following columns.\n3) Populate each column as described. \n\n\n\n\n\n1) Combine the above Tables. \n2) Create one Table Heading--\"Safety Outcome Summary\"\n\n3) Report EACH Column heading. Only report what is inside of quotes. Remove the Quotation marks and the terms \"Column\" and \"Heading\". \n NOTE: Report ALL the Column Headings in ONE ROW.\n A) REPLACE the first column heading as: \"Adverse Events\".\n B) Report the second column heading as: \"Event N\".\n C) Report the third column heading as: \"Study N\".\n D) Report the fourth column heading as: \"Event %\".\n 1. Report the Event % Value to One Decimal Point.\n Note: Do Not Report any Levels N column or values.\n\n4) Report the corresponding data for each Column Values for each \"Safety Outcome\" Table.\n A) Report all the Adverse Events in the First Column.\n B) Report all the Event N Values in the SAME Column.\n Note: For Duplicate adverse events chose the Highest Event N. Only report one Event N per Adverse Event.\n C) Report all the Study N Values in the SAME Column.\n D) Report all the Event % Values in the SAME Column.\n Note: For Duplicate adverse events chose the Highest Event %. Only report one Event % per Adverse Event.\n\n\n5) IF the table is Vertical, Transpose each VERTICAL table to a HORIZONTAL table."]},{"name":"oth-perfFUtable-FIN","inputs":"Blood Loss\nHospital Charge\nLength of Hospital Stay\nNeed for ICU\nOperation Time\nTransfusion Rate\nTime to Readmission","section_sequence":"","assessment":"other","chain":["Report ALL of the information of the above text by performing the following tasks.\n\nPerform the following tasks:\n1) REPORT each table with the SAME columns as listed.\n\n\nFor Each Table\n1) Report EACH \"table heading\".\n2) Identify if the Table has Groups or NO groups. \n A) If the Table has \"Group\", Report each Group Name as written in the text. \n B) If the Table has No Group, \n 1. Add a Column 0 named: \"Group\". Column 0 will precede Column 1.\n 2. Report: \"No Group\" for each row.\n\n3) Identify if the Table has NO \"Preoperative Value (Units)\" Heading. \n A) If the Table has NO \"Preoperative Value (Units)\" Heading:\n 1. INSERT a column named: \"Group\". The \"Group\" Column will follow the \"Outcome\" Column.\n 2. Report: \"Not Reported\" for each row.\n\n\n4) Report the corresponding Outcome, Values, and Study N for each \"Other Outcome\" Table.\n A) Report each VALUE to only One Decimal Point.\n\n5) IF the table is Vertical, Transpose each VERTICAL table to a HORIZONTAL table.\n\n\n\nOverall rules:\n1) Do not exclude any Groups. \n2) Do not exclude any Tables. \n3) Do not exclude any Outcomes.\n4) Do not exclude any Values."]}]
|
application.py
CHANGED
|
@@ -52,6 +52,8 @@ tables_inst=[
|
|
| 52 |
f"include all table titles."
|
| 53 |
]
|
| 54 |
|
|
|
|
|
|
|
| 55 |
article_prompts = {
|
| 56 |
"Authors": '''extract all of the authors of the article from the above text.\n
|
| 57 |
Return the results on the same line separated by commas as Authors: Author A, Author B...
|
|
|
|
| 52 |
f"include all table titles."
|
| 53 |
]
|
| 54 |
|
| 55 |
+
reformat_inst = f"reformat the returned tables into a markdown table syntax if applicable."
|
| 56 |
+
|
| 57 |
article_prompts = {
|
| 58 |
"Authors": '''extract all of the authors of the article from the above text.\n
|
| 59 |
Return the results on the same line separated by commas as Authors: Author A, Author B...
|
backend_update.ipynb
CHANGED
|
@@ -25,7 +25,7 @@
|
|
| 25 |
},
|
| 26 |
{
|
| 27 |
"cell_type": "code",
|
| 28 |
-
"execution_count":
|
| 29 |
"metadata": {},
|
| 30 |
"outputs": [],
|
| 31 |
"source": [
|
|
@@ -68,7 +68,7 @@
|
|
| 68 |
},
|
| 69 |
{
|
| 70 |
"cell_type": "code",
|
| 71 |
-
"execution_count":
|
| 72 |
"metadata": {},
|
| 73 |
"outputs": [],
|
| 74 |
"source": [
|
|
@@ -234,16 +234,16 @@
|
|
| 234 |
},
|
| 235 |
{
|
| 236 |
"cell_type": "code",
|
| 237 |
-
"execution_count":
|
| 238 |
"metadata": {},
|
| 239 |
"outputs": [
|
| 240 |
{
|
| 241 |
"data": {
|
| 242 |
"text/plain": [
|
| 243 |
-
"dict_keys(['Checklist', 'Revision', 'Overview', 'Overview Command', 'Overview Summary Com.', 'Clinical', 'Clinical Command', 'Clin Summary Com', 'Radiologic', 'Radiologic Command', 'Rad Summary Com', 'Safety', 'Safety Command', 'Safety Summary
|
| 244 |
]
|
| 245 |
},
|
| 246 |
-
"execution_count":
|
| 247 |
"metadata": {},
|
| 248 |
"output_type": "execute_result"
|
| 249 |
}
|
|
@@ -251,7 +251,7 @@
|
|
| 251 |
"source": [
|
| 252 |
"import pandas as pd\n",
|
| 253 |
"\n",
|
| 254 |
-
"raw = pd.read_excel(\"./.data/AMRA AI Reader_Search
|
| 255 |
"raw.keys()"
|
| 256 |
]
|
| 257 |
},
|
|
@@ -259,450 +259,75 @@
|
|
| 259 |
"cell_type": "markdown",
|
| 260 |
"metadata": {},
|
| 261 |
"source": [
|
| 262 |
-
"####
|
| 263 |
]
|
| 264 |
},
|
| 265 |
{
|
| 266 |
"cell_type": "code",
|
| 267 |
-
"execution_count":
|
| 268 |
"metadata": {},
|
| 269 |
"outputs": [
|
| 270 |
{
|
| 271 |
"name": "stdout",
|
| 272 |
"output_type": "stream",
|
| 273 |
"text": [
|
| 274 |
-
"
|
| 275 |
-
]
|
| 276 |
-
},
|
| 277 |
-
{
|
| 278 |
-
"data": {
|
| 279 |
-
"text/plain": [
|
| 280 |
-
"['Roland CheckList',\n",
|
| 281 |
-
" 'Roland to Confirm',\n",
|
| 282 |
-
" 'Unnamed: 2',\n",
|
| 283 |
-
" 'Unnamed: 3',\n",
|
| 284 |
-
" 'Unnamed: 4',\n",
|
| 285 |
-
" 'Unnamed: 5',\n",
|
| 286 |
-
" 'Unnamed: 6',\n",
|
| 287 |
-
" 'Unnamed: 7',\n",
|
| 288 |
-
" 'Unnamed: 8',\n",
|
| 289 |
-
" 'Unnamed: 9',\n",
|
| 290 |
-
" 'Unnamed: 10',\n",
|
| 291 |
-
" 'Unnamed: 11',\n",
|
| 292 |
-
" 'Unnamed: 12',\n",
|
| 293 |
-
" 'Unnamed: 13',\n",
|
| 294 |
-
" 'Unnamed: 14',\n",
|
| 295 |
-
" 'Unnamed: 15']"
|
| 296 |
-
]
|
| 297 |
-
},
|
| 298 |
-
"metadata": {},
|
| 299 |
-
"output_type": "display_data"
|
| 300 |
-
},
|
| 301 |
-
{
|
| 302 |
-
"name": "stdout",
|
| 303 |
-
"output_type": "stream",
|
| 304 |
-
"text": [
|
| 305 |
-
"Revision\n"
|
| 306 |
-
]
|
| 307 |
-
},
|
| 308 |
-
{
|
| 309 |
-
"data": {
|
| 310 |
-
"text/plain": [
|
| 311 |
-
"['Revision History', 'Unnamed: 1', 'Unnamed: 2', 'Unnamed: 3']"
|
| 312 |
-
]
|
| 313 |
-
},
|
| 314 |
-
"metadata": {},
|
| 315 |
-
"output_type": "display_data"
|
| 316 |
-
},
|
| 317 |
-
{
|
| 318 |
-
"name": "stdout",
|
| 319 |
-
"output_type": "stream",
|
| 320 |
-
"text": [
|
| 321 |
-
"Overview\n"
|
| 322 |
-
]
|
| 323 |
-
},
|
| 324 |
-
{
|
| 325 |
-
"data": {
|
| 326 |
-
"text/plain": [
|
| 327 |
-
"['Assessment Step',\n",
|
| 328 |
-
" 'Spine',\n",
|
| 329 |
-
" 'Extermity',\n",
|
| 330 |
-
" 'Notes for Roland',\n",
|
| 331 |
-
" 'Unnamed: 4',\n",
|
| 332 |
-
" 'Unnamed: 5',\n",
|
| 333 |
-
" 'Unnamed: 6',\n",
|
| 334 |
-
" 'Unnamed: 7',\n",
|
| 335 |
-
" 'Unnamed: 8',\n",
|
| 336 |
-
" 'Unnamed: 9',\n",
|
| 337 |
-
" 'Notes']"
|
| 338 |
-
]
|
| 339 |
-
},
|
| 340 |
-
"metadata": {},
|
| 341 |
-
"output_type": "display_data"
|
| 342 |
-
},
|
| 343 |
-
{
|
| 344 |
-
"name": "stdout",
|
| 345 |
-
"output_type": "stream",
|
| 346 |
-
"text": [
|
| 347 |
-
"Overview Command\n"
|
| 348 |
-
]
|
| 349 |
-
},
|
| 350 |
-
{
|
| 351 |
-
"data": {
|
| 352 |
-
"text/plain": [
|
| 353 |
-
"['name', 'inputs', 'instruction', 'Command Depends on IFU']"
|
| 354 |
-
]
|
| 355 |
-
},
|
| 356 |
-
"metadata": {},
|
| 357 |
-
"output_type": "display_data"
|
| 358 |
-
},
|
| 359 |
-
{
|
| 360 |
-
"name": "stdout",
|
| 361 |
-
"output_type": "stream",
|
| 362 |
-
"text": [
|
| 363 |
-
"Overview Summary Com.\n"
|
| 364 |
-
]
|
| 365 |
-
},
|
| 366 |
-
{
|
| 367 |
-
"data": {
|
| 368 |
-
"text/plain": [
|
| 369 |
-
"['name', 'inputs', 'instruction']"
|
| 370 |
-
]
|
| 371 |
-
},
|
| 372 |
-
"metadata": {},
|
| 373 |
-
"output_type": "display_data"
|
| 374 |
-
},
|
| 375 |
-
{
|
| 376 |
-
"name": "stdout",
|
| 377 |
-
"output_type": "stream",
|
| 378 |
-
"text": [
|
| 379 |
-
"Clinical\n"
|
| 380 |
]
|
| 381 |
-
}
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
"text": [
|
| 400 |
-
"Clinical Command\n"
|
| 401 |
-
]
|
| 402 |
-
},
|
| 403 |
-
{
|
| 404 |
-
"data": {
|
| 405 |
-
"text/plain": [
|
| 406 |
-
"['name',\n",
|
| 407 |
-
" 'inputs',\n",
|
| 408 |
-
" 'Command Template with Preop with Group',\n",
|
| 409 |
-
" 'Command Template with Preop without Group',\n",
|
| 410 |
-
" 'Command Template without Preop with Group',\n",
|
| 411 |
-
" 'Command Template without Preop without Group',\n",
|
| 412 |
-
" 'root',\n",
|
| 413 |
-
" 'group',\n",
|
| 414 |
-
" 'outcome',\n",
|
| 415 |
-
" 'preoperative',\n",
|
| 416 |
-
" 'postoperative',\n",
|
| 417 |
-
" 'study_n']"
|
| 418 |
-
]
|
| 419 |
-
},
|
| 420 |
-
"metadata": {},
|
| 421 |
-
"output_type": "display_data"
|
| 422 |
-
},
|
| 423 |
-
{
|
| 424 |
-
"name": "stdout",
|
| 425 |
-
"output_type": "stream",
|
| 426 |
-
"text": [
|
| 427 |
-
"Clin Summary Com\n"
|
| 428 |
-
]
|
| 429 |
-
},
|
| 430 |
-
{
|
| 431 |
-
"data": {
|
| 432 |
-
"text/plain": [
|
| 433 |
-
"['name', 'inputs', 'search_term', 'instruction', 'Unnamed: 4']"
|
| 434 |
-
]
|
| 435 |
-
},
|
| 436 |
-
"metadata": {},
|
| 437 |
-
"output_type": "display_data"
|
| 438 |
-
},
|
| 439 |
-
{
|
| 440 |
-
"name": "stdout",
|
| 441 |
-
"output_type": "stream",
|
| 442 |
-
"text": [
|
| 443 |
-
"Radiologic\n"
|
| 444 |
-
]
|
| 445 |
-
},
|
| 446 |
-
{
|
| 447 |
-
"data": {
|
| 448 |
-
"text/plain": [
|
| 449 |
-
"['Assessment Step',\n",
|
| 450 |
-
" 'Region',\n",
|
| 451 |
-
" 'search_term',\n",
|
| 452 |
-
" 'Command Term',\n",
|
| 453 |
-
" 'KeyRadPerfOutcome',\n",
|
| 454 |
-
" 'Command Template with Preop with Group']"
|
| 455 |
-
]
|
| 456 |
-
},
|
| 457 |
-
"metadata": {},
|
| 458 |
-
"output_type": "display_data"
|
| 459 |
-
},
|
| 460 |
-
{
|
| 461 |
-
"name": "stdout",
|
| 462 |
-
"output_type": "stream",
|
| 463 |
-
"text": [
|
| 464 |
-
"Radiologic Command\n"
|
| 465 |
-
]
|
| 466 |
-
},
|
| 467 |
-
{
|
| 468 |
-
"data": {
|
| 469 |
-
"text/plain": [
|
| 470 |
-
"['name',\n",
|
| 471 |
-
" 'inputs',\n",
|
| 472 |
-
" 'Command Template with Preop with Group',\n",
|
| 473 |
-
" 'Command Template with Preop without Group',\n",
|
| 474 |
-
" 'Command Template without Preop with Group',\n",
|
| 475 |
-
" 'Command Template without Preop without Group',\n",
|
| 476 |
-
" 'root',\n",
|
| 477 |
-
" 'group',\n",
|
| 478 |
-
" 'outcome',\n",
|
| 479 |
-
" 'preoperative',\n",
|
| 480 |
-
" 'postoperative',\n",
|
| 481 |
-
" 'study_n']"
|
| 482 |
-
]
|
| 483 |
-
},
|
| 484 |
-
"metadata": {},
|
| 485 |
-
"output_type": "display_data"
|
| 486 |
-
},
|
| 487 |
-
{
|
| 488 |
-
"name": "stdout",
|
| 489 |
-
"output_type": "stream",
|
| 490 |
-
"text": [
|
| 491 |
-
"Rad Summary Com\n"
|
| 492 |
-
]
|
| 493 |
-
},
|
| 494 |
-
{
|
| 495 |
-
"data": {
|
| 496 |
-
"text/plain": [
|
| 497 |
-
"['name', 'inputs', 'search_term', 'Summary Command Template', 'Unnamed: 4']"
|
| 498 |
-
]
|
| 499 |
-
},
|
| 500 |
-
"metadata": {},
|
| 501 |
-
"output_type": "display_data"
|
| 502 |
-
},
|
| 503 |
-
{
|
| 504 |
-
"name": "stdout",
|
| 505 |
-
"output_type": "stream",
|
| 506 |
-
"text": [
|
| 507 |
-
"Safety\n"
|
| 508 |
-
]
|
| 509 |
-
},
|
| 510 |
-
{
|
| 511 |
-
"data": {
|
| 512 |
-
"text/plain": [
|
| 513 |
-
"['Assessment Step',\n",
|
| 514 |
-
" 'Region',\n",
|
| 515 |
-
" 'search_term',\n",
|
| 516 |
-
" 'Command Term',\n",
|
| 517 |
-
" 'Clinical Study Table Term',\n",
|
| 518 |
-
" 'Summary Table Term',\n",
|
| 519 |
-
" 'Command Template',\n",
|
| 520 |
-
" 'Input']"
|
| 521 |
-
]
|
| 522 |
-
},
|
| 523 |
-
"metadata": {},
|
| 524 |
-
"output_type": "display_data"
|
| 525 |
-
},
|
| 526 |
-
{
|
| 527 |
-
"name": "stdout",
|
| 528 |
-
"output_type": "stream",
|
| 529 |
-
"text": [
|
| 530 |
-
"Safety Command\n"
|
| 531 |
-
]
|
| 532 |
-
},
|
| 533 |
-
{
|
| 534 |
-
"data": {
|
| 535 |
-
"text/plain": [
|
| 536 |
-
"['name',\n",
|
| 537 |
-
" 'inputs',\n",
|
| 538 |
-
" 'instruction',\n",
|
| 539 |
-
" 'root',\n",
|
| 540 |
-
" 'group',\n",
|
| 541 |
-
" 'outcome',\n",
|
| 542 |
-
" 'preoperative',\n",
|
| 543 |
-
" 'postoperative',\n",
|
| 544 |
-
" 'study_n']"
|
| 545 |
-
]
|
| 546 |
-
},
|
| 547 |
-
"metadata": {},
|
| 548 |
-
"output_type": "display_data"
|
| 549 |
-
},
|
| 550 |
-
{
|
| 551 |
-
"name": "stdout",
|
| 552 |
-
"output_type": "stream",
|
| 553 |
-
"text": [
|
| 554 |
-
"Safety Summary\n"
|
| 555 |
-
]
|
| 556 |
-
},
|
| 557 |
-
{
|
| 558 |
-
"data": {
|
| 559 |
-
"text/plain": [
|
| 560 |
-
"['Assessment Step',\n",
|
| 561 |
-
" 'Region',\n",
|
| 562 |
-
" 'search_term',\n",
|
| 563 |
-
" 'Summary Replacement Term',\n",
|
| 564 |
-
" 'Risk Replacement Term']"
|
| 565 |
-
]
|
| 566 |
-
},
|
| 567 |
-
"metadata": {},
|
| 568 |
-
"output_type": "display_data"
|
| 569 |
-
},
|
| 570 |
-
{
|
| 571 |
-
"name": "stdout",
|
| 572 |
-
"output_type": "stream",
|
| 573 |
-
"text": [
|
| 574 |
-
"Safety Summary Com\n"
|
| 575 |
-
]
|
| 576 |
-
},
|
| 577 |
-
{
|
| 578 |
-
"data": {
|
| 579 |
-
"text/plain": [
|
| 580 |
-
"['name', 'inputs', 'instruction']"
|
| 581 |
-
]
|
| 582 |
-
},
|
| 583 |
-
"metadata": {},
|
| 584 |
-
"output_type": "display_data"
|
| 585 |
-
},
|
| 586 |
-
{
|
| 587 |
-
"name": "stdout",
|
| 588 |
-
"output_type": "stream",
|
| 589 |
-
"text": [
|
| 590 |
-
"Other\n"
|
| 591 |
-
]
|
| 592 |
-
},
|
| 593 |
-
{
|
| 594 |
-
"data": {
|
| 595 |
-
"text/plain": [
|
| 596 |
-
"['Assessment Step',\n",
|
| 597 |
-
" 'Region',\n",
|
| 598 |
-
" 'search_term',\n",
|
| 599 |
-
" 'Command Term',\n",
|
| 600 |
-
" 'OtherOutcome',\n",
|
| 601 |
-
" 'Command Template with Preoperative with Group']"
|
| 602 |
-
]
|
| 603 |
-
},
|
| 604 |
-
"metadata": {},
|
| 605 |
-
"output_type": "display_data"
|
| 606 |
-
},
|
| 607 |
-
{
|
| 608 |
-
"name": "stdout",
|
| 609 |
-
"output_type": "stream",
|
| 610 |
-
"text": [
|
| 611 |
-
"Other Command\n"
|
| 612 |
-
]
|
| 613 |
-
},
|
| 614 |
-
{
|
| 615 |
-
"data": {
|
| 616 |
-
"text/plain": [
|
| 617 |
-
"['name',\n",
|
| 618 |
-
" 'inputs',\n",
|
| 619 |
-
" 'Command Template with Preop with Group',\n",
|
| 620 |
-
" 'Command Template with Preop without Group',\n",
|
| 621 |
-
" 'Command Template without Preop with Group',\n",
|
| 622 |
-
" 'Command Template without Preop without Group',\n",
|
| 623 |
-
" 'root',\n",
|
| 624 |
-
" 'group',\n",
|
| 625 |
-
" 'outcome',\n",
|
| 626 |
-
" 'preoperative',\n",
|
| 627 |
-
" 'postoperative',\n",
|
| 628 |
-
" 'study_n']"
|
| 629 |
-
]
|
| 630 |
-
},
|
| 631 |
-
"metadata": {},
|
| 632 |
-
"output_type": "display_data"
|
| 633 |
-
},
|
| 634 |
-
{
|
| 635 |
-
"name": "stdout",
|
| 636 |
-
"output_type": "stream",
|
| 637 |
-
"text": [
|
| 638 |
-
"Oth Summary Com\n"
|
| 639 |
-
]
|
| 640 |
-
},
|
| 641 |
-
{
|
| 642 |
-
"data": {
|
| 643 |
-
"text/plain": [
|
| 644 |
-
"['name', 'inputs', 'search_term', 'instruction', 'Unnamed: 4']"
|
| 645 |
-
]
|
| 646 |
-
},
|
| 647 |
-
"metadata": {},
|
| 648 |
-
"output_type": "display_data"
|
| 649 |
-
},
|
| 650 |
-
{
|
| 651 |
-
"name": "stdout",
|
| 652 |
-
"output_type": "stream",
|
| 653 |
-
"text": [
|
| 654 |
-
"Units\n"
|
| 655 |
-
]
|
| 656 |
-
},
|
| 657 |
-
{
|
| 658 |
-
"data": {
|
| 659 |
-
"text/plain": [
|
| 660 |
-
"['Units']"
|
| 661 |
-
]
|
| 662 |
-
},
|
| 663 |
-
"metadata": {},
|
| 664 |
-
"output_type": "display_data"
|
| 665 |
-
},
|
| 666 |
{
|
| 667 |
"name": "stdout",
|
| 668 |
"output_type": "stream",
|
| 669 |
"text": [
|
| 670 |
-
"
|
|
|
|
| 671 |
]
|
| 672 |
},
|
| 673 |
{
|
| 674 |
"data": {
|
| 675 |
"text/plain": [
|
| 676 |
-
"[
|
| 677 |
-
" 'Unnamed: 1',\n",
|
| 678 |
-
" 'Unnamed: 2',\n",
|
| 679 |
-
" 'Unnamed: 3',\n",
|
| 680 |
-
" 'Unnamed: 4',\n",
|
| 681 |
-
" 'Unnamed: 5',\n",
|
| 682 |
-
" 'Unnamed: 6',\n",
|
| 683 |
-
" 'Unnamed: 7',\n",
|
| 684 |
-
" 'Unnamed: 8',\n",
|
| 685 |
-
" 'Unnamed: 9',\n",
|
| 686 |
-
" 'Unnamed: 10',\n",
|
| 687 |
-
" 'Unnamed: 11',\n",
|
| 688 |
-
" 'Unnamed: 12',\n",
|
| 689 |
-
" 'Unnamed: 13',\n",
|
| 690 |
-
" 'Unnamed: 14',\n",
|
| 691 |
-
" 'Unnamed: 15',\n",
|
| 692 |
-
" 'Unnamed: 16',\n",
|
| 693 |
-
" 'Unnamed: 17',\n",
|
| 694 |
-
" 'Unnamed: 18',\n",
|
| 695 |
-
" '\\n\\n\\nTable Heading--Radiologic Outcome-Fusion Events\\nGroup\\tN Fusion Events n (%)\\tN Nonunion Events n (%)\\tStudy N\\nNo Group\\t35 (94.5%)\\t2 (5.5%)\\t\\t32\\nOverall Fusion Rate (94.5%)\\tOverall Nonunion Rate (5.5%)\\n\\n\\n\\nTable Heading--Radiologic Outcome-Fusion Events\\nGroup\\tN Fusion Events n (%)\\tN Nonunion Events n (%)\\tStudy N\\nGroup A-1\\t16 (94.1%)\\t1 (5.9%)\\t\\t17\\nGroup A-2\\t14 (66.7%)\\t7 (33.3%)\\t\\t21\\nGroup B-1\\t18 (100%)\\t0 (0%)\\t\\t\\t18\\nGroup B-2\\t21 (95.5%)\\t1 (4.5%)\\t\\t22\\nOverall\\t69 (78.9%)\\t9 (21.1%)\\t\\n\\n\\nTable Heading--Radiologic Outcome-Fusion Events\\nGroup\\tN Fusion Events n (%)\\tN Nonunion Events n (%)\\tStudy N\\nNo Group\\t18 (72%)\\t6 (24%)\\t\\t25\\nOverall Fusion Rate (72%) Overall Nonunion Rate (28%)\\t\\t25\\n\\n\\n\\nTable Heading--Radiologic Outcome-Fusion Events\\nGroup\\tN Fusion Events n (%)\\tN Nonunion Events n (%)\\tStudy N\\nTitanium\\t32/37 (86.5%)\\t5/37 (13.5%)\\t53\\nPEEK\\t34/34 (100%)\\t0/34 (0%)\\t53\\nOverall\\t66/71 (93.0%)\\t5/71 (7.0%)\\t\\t\\t\\n\\n\\n\\n\\nTable Heading--Radiologic Outcome-Fusion Events\\nGroup\\tN Fusion Events n (%)\\tN Nonunion Events n (%)\\tStudy N\\nGroup A\\t27/28 (96.43%)\\t1/28 (3.57%)\\t28\\nGroup B\\t25/26 (96.15%)\\t1/26 (3.85%)\\t26\\nOverall\\t52/54 (96.30%)\\t2/54 (3.70%)\\t54\\n\\n\\n\\n\\nTable Heading--Radiologic Outcome-Fusion Events\\nN Fusion Events n (%)\\tN Nonunion Events n (%)\\tStudy N\\nGroup A\\t27/28 (96.43%)\\t1/28 (3.57%)\\t28\\nGroup B\\t25/26 (96.15%)\\t1/26 (3.85%)\\t26\\nOverall\\t52/54 (96.30%)\\t2/54 (3.70%)\\t54\\n\\n\\n\\nTable Heading--Radiologic Outcome-Fusion Events\\nFusion\\t\\tN Fusion Events n (%)\\tN Nonunion Events n (%)\\tStudy N\\nGrade I\\t\\t1 (3.3%)\\t0 (0%)\\t\\t\\t\\nGrade II\\t\\t4 (13.3%)\\t0 (0%)\\t\\t\\nGrade III\\t25 (83.3%)\\t0 (0%)\\t\\t\\nOverall\\t\\t30 (100%)\\t0 (0%)\\t30\\n\\n\\n\\n\\n\\nTable Heading--Radiologic Outcome-Fusion Events\\nGroup\\tN Fusion Events n (%)\\tN Nonunion Events n (%)\\tStudy N\\nNo Group\\t41 (97%)\\t1 (3%)\\t\\t31\\nOverall Fusion Rate (97%)\\tOverall Nonunion Rate (3%)\\t\\t']"
|
| 696 |
]
|
| 697 |
},
|
|
|
|
| 698 |
"metadata": {},
|
| 699 |
-
"output_type": "
|
| 700 |
}
|
| 701 |
],
|
| 702 |
"source": [
|
| 703 |
-
"
|
| 704 |
-
"
|
| 705 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 706 |
]
|
| 707 |
},
|
| 708 |
{
|
|
|
|
| 25 |
},
|
| 26 |
{
|
| 27 |
"cell_type": "code",
|
| 28 |
+
"execution_count": 1,
|
| 29 |
"metadata": {},
|
| 30 |
"outputs": [],
|
| 31 |
"source": [
|
|
|
|
| 68 |
},
|
| 69 |
{
|
| 70 |
"cell_type": "code",
|
| 71 |
+
"execution_count": 5,
|
| 72 |
"metadata": {},
|
| 73 |
"outputs": [],
|
| 74 |
"source": [
|
|
|
|
| 234 |
},
|
| 235 |
{
|
| 236 |
"cell_type": "code",
|
| 237 |
+
"execution_count": 28,
|
| 238 |
"metadata": {},
|
| 239 |
"outputs": [
|
| 240 |
{
|
| 241 |
"data": {
|
| 242 |
"text/plain": [
|
| 243 |
+
"dict_keys(['Checklist', 'Revision', 'terms', 'prompts', 'prompt_agg', 'prompt_sum', 'Overview', 'Overview Command', 'Overview Summary Com.', 'Clinical', 'Clinical Command', 'Clin Summary Com', 'Radiologic', 'Radiologic Command', 'parser_safety', 'Units', 'Notes', 'Rad Summary Com', 'Safety', 'Safety Command', 'Safety Summary Com', 'Other', 'Other Command', 'Oth Summary Com'])"
|
| 244 |
]
|
| 245 |
},
|
| 246 |
+
"execution_count": 28,
|
| 247 |
"metadata": {},
|
| 248 |
"output_type": "execute_result"
|
| 249 |
}
|
|
|
|
| 251 |
"source": [
|
| 252 |
"import pandas as pd\n",
|
| 253 |
"\n",
|
| 254 |
+
"raw = pd.read_excel(\"./.data/AMRA AI Reader_Search Term_V14l.xlsx\",sheet_name=None)\n",
|
| 255 |
"raw.keys()"
|
| 256 |
]
|
| 257 |
},
|
|
|
|
| 259 |
"cell_type": "markdown",
|
| 260 |
"metadata": {},
|
| 261 |
"source": [
|
| 262 |
+
"#### Reduced processing"
|
| 263 |
]
|
| 264 |
},
|
| 265 |
{
|
| 266 |
"cell_type": "code",
|
| 267 |
+
"execution_count": 18,
|
| 268 |
"metadata": {},
|
| 269 |
"outputs": [
|
| 270 |
{
|
| 271 |
"name": "stdout",
|
| 272 |
"output_type": "stream",
|
| 273 |
"text": [
|
| 274 |
+
"(3494, 7) (85, 10)\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 275 |
]
|
| 276 |
+
}
|
| 277 |
+
],
|
| 278 |
+
"source": [
|
| 279 |
+
"df_terms = raw[\"terms\"]\n",
|
| 280 |
+
"df_terms.fillna(\"\",inplace=True)\n",
|
| 281 |
+
"\n",
|
| 282 |
+
"# create a name for rows with assessment as overview and terms with the format of \"overview - {instruction}\"\n",
|
| 283 |
+
"df_terms.loc[df_terms.assessment == \"overview\",\"indication_terms\"] = df_terms.loc[df_terms.assessment == \"overview\",\"instruction\"].apply(lambda x: f\"overview - {x}\")\n",
|
| 284 |
+
"df_terms.instruction = df_terms.instruction.apply(lambda x: [t.strip() for t in x.split(\",\")])\n",
|
| 285 |
+
"\n",
|
| 286 |
+
"df_local_to_aws_dynamodb(\"terms\",df_terms)"
|
| 287 |
+
]
|
| 288 |
+
},
|
| 289 |
+
{
|
| 290 |
+
"cell_type": "code",
|
| 291 |
+
"execution_count": 29,
|
| 292 |
+
"metadata": {},
|
| 293 |
+
"outputs": [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 294 |
{
|
| 295 |
"name": "stdout",
|
| 296 |
"output_type": "stream",
|
| 297 |
"text": [
|
| 298 |
+
"85/85\n",
|
| 299 |
+
"upload erros count: 0\n"
|
| 300 |
]
|
| 301 |
},
|
| 302 |
{
|
| 303 |
"data": {
|
| 304 |
"text/plain": [
|
| 305 |
+
"[]"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 306 |
]
|
| 307 |
},
|
| 308 |
+
"execution_count": 29,
|
| 309 |
"metadata": {},
|
| 310 |
+
"output_type": "execute_result"
|
| 311 |
}
|
| 312 |
],
|
| 313 |
"source": [
|
| 314 |
+
"df_prompt = raw[\"prompts\"]\n",
|
| 315 |
+
"df_prompt.fillna(\"\",inplace=True)\n",
|
| 316 |
+
"\n",
|
| 317 |
+
"df_prompt[\"chain\"] = df_prompt.apply(lambda x: [x[\"root\"],x[\"group\"],x[\"outcome\"],x[\"preoperative\"],x[\"postoperative\"],x[\"study_n\"]],axis=1)\n",
|
| 318 |
+
"df_prompt.loc[df_prompt.assessment == \"overview\",\"chain\"] = df_prompt.loc[df_prompt.assessment == \"overview\",\"chain\"].apply(lambda x: [i for i in x if i])\n",
|
| 319 |
+
"df_prompt.inputs = df_prompt.inputs.apply(lambda x: [i.strip() for i in x.split(\",\")])\n",
|
| 320 |
+
"\n",
|
| 321 |
+
"df_prompt.drop([\"root\",\"group\",\"outcome\",\"preoperative\",\"postoperative\",\"study_n\"],axis=1,inplace=True)\n",
|
| 322 |
+
"\n",
|
| 323 |
+
"df_local_to_aws_dynamodb(\"prompts\",df_prompt)"
|
| 324 |
+
]
|
| 325 |
+
},
|
| 326 |
+
{
|
| 327 |
+
"cell_type": "markdown",
|
| 328 |
+
"metadata": {},
|
| 329 |
+
"source": [
|
| 330 |
+
"#### Processing Overview sheet"
|
| 331 |
]
|
| 332 |
},
|
| 333 |
{
|
chains.py
CHANGED
|
@@ -67,18 +67,30 @@ post_prompt_maping = {}
|
|
| 67 |
post_replace_term = lambda res,map=post_prompt_maping:replace_term(res,map=map)
|
| 68 |
|
| 69 |
def gen_task(prompt,article):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
input_text = "".join([article[s] for s in prompt["inputs"]])
|
| 71 |
|
| 72 |
messages = [
|
| 73 |
("system","You are a helpful AI that can answer questions about clinical trail and operation studies."),
|
| 74 |
("human",input_text)
|
| 75 |
]
|
| 76 |
-
for msg in prompt["chain"]:
|
| 77 |
-
messages.append(("human",msg))
|
| 78 |
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
input_variables = {}
|
| 83 |
if "term" in prompt:
|
| 84 |
app_data["current"]["term"] = prompt["term"][0]["prompting_term"]
|
|
@@ -86,9 +98,8 @@ def gen_task(prompt,article):
|
|
| 86 |
if "n_col" in chat_prompt.input_variables:
|
| 87 |
input_variables["n_col"] = len(prompt["chain"])
|
| 88 |
if "term" in chat_prompt.input_variables:
|
| 89 |
-
input_variables["term"] = app_data["current"]["term"]
|
| 90 |
-
|
| 91 |
-
return async_generate(article=article,name=prompt["name"],chain=chain,input_variables=input_variables)
|
| 92 |
|
| 93 |
if __name__ == "__main__":
|
| 94 |
# lets try the Blood Loss, Operation Time, and Need for ICU in other folder
|
|
|
|
| 67 |
post_replace_term = lambda res,map=post_prompt_maping:replace_term(res,map=map)
|
| 68 |
|
| 69 |
def gen_task(prompt,article):
|
| 70 |
+
chat_prompt = gen_chat_prompt(prompt,article)
|
| 71 |
+
chain = chat_prompt | llm | post_replace_term
|
| 72 |
+
input_variables = gen_input_variables (chat_prompt,prompt)
|
| 73 |
+
|
| 74 |
+
return async_generate(article=article,name=prompt["name"],chain=chain,input_variables=input_variables)
|
| 75 |
+
|
| 76 |
+
def gen_chat_prompt(prompt,article):
|
| 77 |
input_text = "".join([article[s] for s in prompt["inputs"]])
|
| 78 |
|
| 79 |
messages = [
|
| 80 |
("system","You are a helpful AI that can answer questions about clinical trail and operation studies."),
|
| 81 |
("human",input_text)
|
| 82 |
]
|
|
|
|
|
|
|
| 83 |
|
| 84 |
+
if len(prompt["chain"]) > 1:
|
| 85 |
+
for i in article["logic"]["chain id"]:
|
| 86 |
+
messages.append(("human",prompt["chain"][i]))
|
| 87 |
+
else:
|
| 88 |
+
messages.append(("human",prompt["chain"][0]))
|
| 89 |
+
messages.append(("system",reformat_inst))
|
| 90 |
+
|
| 91 |
+
return ChatPromptTemplate.from_messages(messages=messages)
|
| 92 |
+
|
| 93 |
+
def gen_input_variables(chat_prompt,prompt):
|
| 94 |
input_variables = {}
|
| 95 |
if "term" in prompt:
|
| 96 |
app_data["current"]["term"] = prompt["term"][0]["prompting_term"]
|
|
|
|
| 98 |
if "n_col" in chat_prompt.input_variables:
|
| 99 |
input_variables["n_col"] = len(prompt["chain"])
|
| 100 |
if "term" in chat_prompt.input_variables:
|
| 101 |
+
input_variables["term"] = app_data["current"]["term"]
|
| 102 |
+
return input_variables
|
|
|
|
| 103 |
|
| 104 |
if __name__ == "__main__":
|
| 105 |
# lets try the Blood Loss, Operation Time, and Need for ICU in other folder
|
features.py
CHANGED
|
@@ -5,9 +5,9 @@ from datetime import datetime
|
|
| 5 |
import gradio as gr
|
| 6 |
import asyncio
|
| 7 |
|
| 8 |
-
from langchain.llms import OpenAI
|
| 9 |
-
from langchain.prompts import PromptTemplate
|
| 10 |
-
from langchain.chains import LLMChain
|
| 11 |
|
| 12 |
# internal packages
|
| 13 |
from chains import *
|
|
@@ -153,7 +153,7 @@ def update_article_segment(article):
|
|
| 153 |
"key_content": article["Abstract"] + article["Material and Methods"] + article["Results"],
|
| 154 |
})
|
| 155 |
# add the recognized logic to the article
|
| 156 |
-
|
| 157 |
# one thing to notice here, due to the fact that update_article_segment function perform direct change on the article object,
|
| 158 |
# there is no need to re-assign the article object to the same variable name
|
| 159 |
|
|
@@ -207,24 +207,32 @@ def refresh():
|
|
| 207 |
|
| 208 |
@terminal_print
|
| 209 |
def create_overview(article):
|
| 210 |
-
# md_text = ""
|
| 211 |
-
assessment = "Overview"
|
| 212 |
-
|
| 213 |
md_text = f"## Overview\n\n"
|
| 214 |
-
overview_components = article["extraction"][
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
if component in article
|
| 218 |
-
|
| 219 |
-
else:
|
| 220 |
-
md_text += "No content found\n\n"
|
| 221 |
-
# md_text += article[component] + "\n\n"
|
| 222 |
return gr.update(value=md_text)
|
| 223 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 224 |
@terminal_print
|
| 225 |
def create_detail_views(article):
|
| 226 |
md_text = "## Performance\n\n"
|
| 227 |
-
assessments = ["
|
| 228 |
performance_tables = ["clin-perfFUtable-FIN","rad-perfFUtable-FIN","saf-Futable-FIN","oth-perfFUtable-FIN"]
|
| 229 |
|
| 230 |
# add performance
|
|
@@ -448,13 +456,17 @@ def select_overview_prompts(article):
|
|
| 448 |
valid_prompts = set()
|
| 449 |
for t in app_data["terms"]:
|
| 450 |
# select overview prompts
|
| 451 |
-
if validate_term(article,t,"
|
| 452 |
# add the prompts to the memory
|
| 453 |
valid_prompts.update(t["instruction"])
|
|
|
|
|
|
|
| 454 |
sorted_prompts = sorted(valid_prompts,key=lambda prompt:app_data["prompts"][prompt]["section_sequence"])
|
| 455 |
-
article["extraction"]["
|
| 456 |
return {p:app_data["prompts"][p] for p in valid_prompts}
|
| 457 |
|
|
|
|
|
|
|
| 458 |
@terminal_print
|
| 459 |
def select_performance_prompts(article,performance_assessment):
|
| 460 |
valid_terms = []
|
|
@@ -484,6 +496,17 @@ def select_performance_prompts(article,performance_assessment):
|
|
| 484 |
# print("valid performance prompts: ",valid_prompts)
|
| 485 |
return valid_prompts
|
| 486 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 487 |
@terminal_print
|
| 488 |
def process_prompts(article): # function overly complicated. need to be simplified.
|
| 489 |
'''
|
|
@@ -508,7 +531,7 @@ def process_prompts(article): # function overly complicated. need to be simplifi
|
|
| 508 |
article["extraction"] = {}
|
| 509 |
|
| 510 |
overview_prompts = select_overview_prompts(article)
|
| 511 |
-
performance_assessments = ["
|
| 512 |
|
| 513 |
performance_prompts = {}
|
| 514 |
for assessment in performance_assessments:
|
|
@@ -528,7 +551,7 @@ def validate_term(article,term,assessment):
|
|
| 528 |
if term["region"].lower() != "all" and term["region"].lower() != article["domain"].lower():
|
| 529 |
return False
|
| 530 |
|
| 531 |
-
if assessment == "
|
| 532 |
return True
|
| 533 |
|
| 534 |
# validate if the term is used for overview
|
|
@@ -559,7 +582,7 @@ def keyword_search(keywords,full_text):
|
|
| 559 |
def post_process(article):
|
| 560 |
post_inputs = {}
|
| 561 |
for assessment,segements in article["extraction"].items():
|
| 562 |
-
if assessment == "
|
| 563 |
continue
|
| 564 |
post_inputs[assessment] = "\n".join([article[s] for s in segements])
|
| 565 |
|
|
|
|
| 5 |
import gradio as gr
|
| 6 |
import asyncio
|
| 7 |
|
| 8 |
+
# from langchain.llms import OpenAI
|
| 9 |
+
# from langchain.prompts import PromptTemplate
|
| 10 |
+
# from langchain.chains import LLMChain
|
| 11 |
|
| 12 |
# internal packages
|
| 13 |
from chains import *
|
|
|
|
| 153 |
"key_content": article["Abstract"] + article["Material and Methods"] + article["Results"],
|
| 154 |
})
|
| 155 |
# add the recognized logic to the article
|
| 156 |
+
update_logic(article)
|
| 157 |
# one thing to notice here, due to the fact that update_article_segment function perform direct change on the article object,
|
| 158 |
# there is no need to re-assign the article object to the same variable name
|
| 159 |
|
|
|
|
| 207 |
|
| 208 |
@terminal_print
|
| 209 |
def create_overview(article):
|
|
|
|
|
|
|
|
|
|
| 210 |
md_text = f"## Overview\n\n"
|
| 211 |
+
overview_components = article["extraction"]["overview"]
|
| 212 |
+
|
| 213 |
+
for component in overview_components: # command name removed
|
| 214 |
+
md_text += article[component] + "\n\n" if component in article else "no content found\n\n"
|
| 215 |
+
|
|
|
|
|
|
|
|
|
|
| 216 |
return gr.update(value=md_text)
|
| 217 |
|
| 218 |
+
def pre_view(content):
|
| 219 |
+
|
| 220 |
+
if "Table Heading" in content: # remove table heading
|
| 221 |
+
content = content.replace("Table Heading","")
|
| 222 |
+
# remove the line with ariticle id
|
| 223 |
+
content = content.split("\n")
|
| 224 |
+
content = [c for c in content if "article id" not in c.lower()]
|
| 225 |
+
|
| 226 |
+
#get the first line and only keep the alphanumeric characters
|
| 227 |
+
text = content.split("\n")
|
| 228 |
+
text[0] = "###" + "".join([c for c in text[0] if c.isalnum()])
|
| 229 |
+
|
| 230 |
+
return "\n".join(text).replace('"', '')
|
| 231 |
+
|
| 232 |
@terminal_print
|
| 233 |
def create_detail_views(article):
|
| 234 |
md_text = "## Performance\n\n"
|
| 235 |
+
assessments = ["clinical","radiologic","safety","other"]
|
| 236 |
performance_tables = ["clin-perfFUtable-FIN","rad-perfFUtable-FIN","saf-Futable-FIN","oth-perfFUtable-FIN"]
|
| 237 |
|
| 238 |
# add performance
|
|
|
|
| 456 |
valid_prompts = set()
|
| 457 |
for t in app_data["terms"]:
|
| 458 |
# select overview prompts
|
| 459 |
+
if validate_term(article,t,"overview"):
|
| 460 |
# add the prompts to the memory
|
| 461 |
valid_prompts.update(t["instruction"])
|
| 462 |
+
|
| 463 |
+
print(valid_prompts)
|
| 464 |
sorted_prompts = sorted(valid_prompts,key=lambda prompt:app_data["prompts"][prompt]["section_sequence"])
|
| 465 |
+
article["extraction"]["overview"] = sorted_prompts
|
| 466 |
return {p:app_data["prompts"][p] for p in valid_prompts}
|
| 467 |
|
| 468 |
+
|
| 469 |
+
|
| 470 |
@terminal_print
|
| 471 |
def select_performance_prompts(article,performance_assessment):
|
| 472 |
valid_terms = []
|
|
|
|
| 496 |
# print("valid performance prompts: ",valid_prompts)
|
| 497 |
return valid_prompts
|
| 498 |
|
| 499 |
+
def update_logic(article):
|
| 500 |
+
article["logic"] = {
|
| 501 |
+
"group":article["key_content"].lower().count("group")>=3,
|
| 502 |
+
"preoperative":article["key_content"].lower().count("preoperative")>=2,
|
| 503 |
+
"chain id":[i for i in range(6)]
|
| 504 |
+
}
|
| 505 |
+
if not article["logic"]["group"]:
|
| 506 |
+
article["logic"]["chain id"].remove(1)
|
| 507 |
+
if not article["logic"]["preoperative"]:
|
| 508 |
+
article["logic"]["chain id"].remove(3)
|
| 509 |
+
|
| 510 |
@terminal_print
|
| 511 |
def process_prompts(article): # function overly complicated. need to be simplified.
|
| 512 |
'''
|
|
|
|
| 531 |
article["extraction"] = {}
|
| 532 |
|
| 533 |
overview_prompts = select_overview_prompts(article)
|
| 534 |
+
performance_assessments = ["clinical","radiologic","safety","other"]
|
| 535 |
|
| 536 |
performance_prompts = {}
|
| 537 |
for assessment in performance_assessments:
|
|
|
|
| 551 |
if term["region"].lower() != "all" and term["region"].lower() != article["domain"].lower():
|
| 552 |
return False
|
| 553 |
|
| 554 |
+
if assessment == "overview" and term["assessment"] == "overview":
|
| 555 |
return True
|
| 556 |
|
| 557 |
# validate if the term is used for overview
|
|
|
|
| 582 |
def post_process(article):
|
| 583 |
post_inputs = {}
|
| 584 |
for assessment,segements in article["extraction"].items():
|
| 585 |
+
if assessment == "overview":
|
| 586 |
continue
|
| 587 |
post_inputs[assessment] = "\n".join([article[s] for s in segements])
|
| 588 |
|