Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -64,6 +64,13 @@ storage_context = StorageContext.from_defaults(persist_dir="VectorStore")
|
|
| 64 |
# load index
|
| 65 |
index_persisted = load_index_from_storage(storage_context, index_id="vector_index")
|
| 66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
async def run_function_on_text(top_k,study_obj,study_type,phase,purpose,allocation,intervention_model,Masking,conditions,interventions,location_countries,removed_location_countries):
|
| 69 |
|
|
@@ -155,6 +162,59 @@ async def run_function_on_text(top_k,study_obj,study_type,phase,purpose,allocati
|
|
| 155 |
"""
|
| 156 |
)
|
| 157 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 158 |
# # LLM.complete
|
| 159 |
# complete_response = await llm.acomplete(f"""
|
| 160 |
# Based on the provided instructions and clinical trial information, generate the new eligibility criteria by analyzing clinical trial information(### Clinical Trial Information).
|
|
@@ -252,7 +312,7 @@ async def run_function_on_text(top_k,study_obj,study_type,phase,purpose,allocati
|
|
| 252 |
# """
|
| 253 |
# )
|
| 254 |
|
| 255 |
-
return query_response
|
| 256 |
# return query_response,complete_response,combine_response
|
| 257 |
|
| 258 |
# Place holder
|
|
@@ -335,6 +395,24 @@ with gr.Blocks() as demo:
|
|
| 335 |
placeholder=prefilled_value,
|
| 336 |
# placeholder=objective_place_holder,
|
| 337 |
lines=10)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 338 |
# Study Design
|
| 339 |
with gr.Row():
|
| 340 |
gr.Markdown("# Study Design"),
|
|
@@ -363,24 +441,6 @@ with gr.Blocks() as demo:
|
|
| 363 |
["None (Open Label)", "Single", "Double", "Triple", "Quadruple"],
|
| 364 |
label="Masking"
|
| 365 |
)
|
| 366 |
-
# Conditions
|
| 367 |
-
with gr.Row():
|
| 368 |
-
gr.Markdown("# Conditions"),
|
| 369 |
-
with gr.Row():
|
| 370 |
-
conditions_box = gr.Textbox(
|
| 371 |
-
label="Conditions / Disease",
|
| 372 |
-
info="Primary Disease or Condition of Cancer Being Studied in the Trial, or the Focus of the Study",
|
| 373 |
-
placeholder=conditions_place_holder,
|
| 374 |
-
)
|
| 375 |
-
#Interventions
|
| 376 |
-
with gr.Row():
|
| 377 |
-
gr.Markdown("# Interventions / Drugs"),
|
| 378 |
-
with gr.Row():
|
| 379 |
-
intervention_box = gr.Textbox(
|
| 380 |
-
label="Intervention type",
|
| 381 |
-
placeholder=interventions_place_holder,
|
| 382 |
-
lines=10,
|
| 383 |
-
)
|
| 384 |
#Location
|
| 385 |
with gr.Row():
|
| 386 |
gr.Markdown("# Location"),
|
|
@@ -395,7 +455,7 @@ with gr.Blocks() as demo:
|
|
| 395 |
# Submit & Clear
|
| 396 |
with gr.Row():
|
| 397 |
submit_button = gr.Button("Submit")
|
| 398 |
-
|
| 399 |
|
| 400 |
# Output
|
| 401 |
with gr.Row():
|
|
@@ -406,6 +466,13 @@ with gr.Blocks() as demo:
|
|
| 406 |
# label="Response 1",
|
| 407 |
lines=15,
|
| 408 |
interactive=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 409 |
# with gr.Column():
|
| 410 |
# rag_box = gr.Textbox(
|
| 411 |
# label="Response 2",
|
|
@@ -416,9 +483,11 @@ with gr.Blocks() as demo:
|
|
| 416 |
# label="Response 3",
|
| 417 |
# lines=15,
|
| 418 |
# interactive=False)
|
| 419 |
-
|
|
|
|
|
|
|
| 420 |
inputs_information = [top_k_box, study_obj_box, study_type_box, phase_box, purpose_box, allocation_box, intervention_model_box, masking_box, conditions_box, intervention_box, location_box, removed_location_box]
|
| 421 |
-
outputs_information = [base_box]
|
| 422 |
# outputs_information = [base_box, rag_box,combine_box]
|
| 423 |
|
| 424 |
submit_button.click(
|
|
@@ -426,8 +495,14 @@ with gr.Blocks() as demo:
|
|
| 426 |
inputs=inputs_information,
|
| 427 |
outputs=outputs_information
|
| 428 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 429 |
|
| 430 |
-
|
| 431 |
|
| 432 |
# with gr.Row():
|
| 433 |
# selected_response = gr.Radio(
|
|
|
|
| 64 |
# load index
|
| 65 |
index_persisted = load_index_from_storage(storage_context, index_id="vector_index")
|
| 66 |
|
| 67 |
+
async def remove_ref(text):
|
| 68 |
+
split_text = re.split(r'\bReference Papers\b', text, flags=re.IGNORECASE)
|
| 69 |
+
|
| 70 |
+
if len(split_text) > 1:
|
| 71 |
+
return split_text[0].strip()
|
| 72 |
+
|
| 73 |
+
return text.strip()
|
| 74 |
|
| 75 |
async def run_function_on_text(top_k,study_obj,study_type,phase,purpose,allocation,intervention_model,Masking,conditions,interventions,location_countries,removed_location_countries):
|
| 76 |
|
|
|
|
| 162 |
"""
|
| 163 |
)
|
| 164 |
|
| 165 |
+
#Extract ref
|
| 166 |
+
if query_response.response != "Empty Response":
|
| 167 |
+
pattern = r'Reference Papers:?\s*(.*?)(?:\n\n.*$|$)'
|
| 168 |
+
match = re.search(pattern, query_response.response, re.DOTALL | re.IGNORECASE)
|
| 169 |
+
ext_ref = match.group(1) if match and match.group(1) else ''
|
| 170 |
+
split_ref = re.split(r'\d+\.\s+', ext_ref)[1:]
|
| 171 |
+
|
| 172 |
+
formatted_ref = []
|
| 173 |
+
n=0
|
| 174 |
+
for ref in split_ref:
|
| 175 |
+
nct_match = re.search(r'NCT[_ ]ID: (NCT\d+)', ref)
|
| 176 |
+
if nct_match:
|
| 177 |
+
nct_id = nct_match.group(1)
|
| 178 |
+
else:
|
| 179 |
+
nct_match = re.search(r'(NCT\d+)', ref)
|
| 180 |
+
if nct_match:
|
| 181 |
+
nct_id = nct_match.group(1)
|
| 182 |
+
else:
|
| 183 |
+
continue
|
| 184 |
+
n+=1
|
| 185 |
+
study_name = re.search(r'Study Name:?\s*(.*?)(?=\n|Condition:|Intervention/Treatment:|$)', ref, re.DOTALL).group(1).strip()
|
| 186 |
+
condition = re.search(r'Condition:?\s*(.*?)(?=\n|Intervention/Treatment:|$)', ref, re.DOTALL).group(1).strip()
|
| 187 |
+
intervention = re.search(r'Intervention/Treatment:?\s*(.*?)(?=\n|$)', ref, re.DOTALL).group(1).strip()
|
| 188 |
+
|
| 189 |
+
study_name = re.sub(r'\*+', '', study_name).strip()
|
| 190 |
+
condition = re.sub(r'\*+', '', condition).strip()
|
| 191 |
+
intervention = re.sub(r'\*+', '', intervention).strip()
|
| 192 |
+
|
| 193 |
+
formatted_trial = [
|
| 194 |
+
n,
|
| 195 |
+
f'<a href="https://clinicaltrials.gov/study/{nct_id}">{nct_id}</a>',
|
| 196 |
+
study_name,
|
| 197 |
+
condition,
|
| 198 |
+
intervention
|
| 199 |
+
]
|
| 200 |
+
|
| 201 |
+
formatted_ref.append(formatted_trial)
|
| 202 |
+
|
| 203 |
+
else:
|
| 204 |
+
formatted_ref = []
|
| 205 |
+
|
| 206 |
+
#Extract criteria
|
| 207 |
+
if query_response.response == "Empty Response":
|
| 208 |
+
return query_response,formatted_ref
|
| 209 |
+
else:
|
| 210 |
+
removed_ref = await remove_ref(query_response.response)
|
| 211 |
+
combine_criteira = re.sub(r'##\s*', '', removed_ref).strip()
|
| 212 |
+
combine_criteira = re.sub(r'#\s*', '', combine_criteira).strip()
|
| 213 |
+
combine_criteira = re.sub(r'\*\*', '', combine_criteira).strip()
|
| 214 |
+
combine_criteira = re.sub(r'(Criteria)\n\s*\n(\d+\.)', r'\1\n\2', combine_criteira).strip()
|
| 215 |
+
|
| 216 |
+
return combine_criteira,formatted_ref
|
| 217 |
+
|
| 218 |
# # LLM.complete
|
| 219 |
# complete_response = await llm.acomplete(f"""
|
| 220 |
# Based on the provided instructions and clinical trial information, generate the new eligibility criteria by analyzing clinical trial information(### Clinical Trial Information).
|
|
|
|
| 312 |
# """
|
| 313 |
# )
|
| 314 |
|
| 315 |
+
# return query_response
|
| 316 |
# return query_response,complete_response,combine_response
|
| 317 |
|
| 318 |
# Place holder
|
|
|
|
| 395 |
placeholder=prefilled_value,
|
| 396 |
# placeholder=objective_place_holder,
|
| 397 |
lines=10)
|
| 398 |
+
# Conditions
|
| 399 |
+
with gr.Row():
|
| 400 |
+
gr.Markdown("# Conditions"),
|
| 401 |
+
with gr.Row():
|
| 402 |
+
conditions_box = gr.Textbox(
|
| 403 |
+
label="Conditions / Disease",
|
| 404 |
+
info="Primary Disease or Condition of Cancer Being Studied in the Trial, or the Focus of the Study",
|
| 405 |
+
placeholder=conditions_place_holder,
|
| 406 |
+
)
|
| 407 |
+
#Interventions
|
| 408 |
+
with gr.Row():
|
| 409 |
+
gr.Markdown("# Interventions / Drugs"),
|
| 410 |
+
with gr.Row():
|
| 411 |
+
intervention_box = gr.Textbox(
|
| 412 |
+
label="Intervention type",
|
| 413 |
+
placeholder=interventions_place_holder,
|
| 414 |
+
lines=10,
|
| 415 |
+
)
|
| 416 |
# Study Design
|
| 417 |
with gr.Row():
|
| 418 |
gr.Markdown("# Study Design"),
|
|
|
|
| 441 |
["None (Open Label)", "Single", "Double", "Triple", "Quadruple"],
|
| 442 |
label="Masking"
|
| 443 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 444 |
#Location
|
| 445 |
with gr.Row():
|
| 446 |
gr.Markdown("# Location"),
|
|
|
|
| 455 |
# Submit & Clear
|
| 456 |
with gr.Row():
|
| 457 |
submit_button = gr.Button("Submit")
|
| 458 |
+
clear_button = gr.Button("Clear")
|
| 459 |
|
| 460 |
# Output
|
| 461 |
with gr.Row():
|
|
|
|
| 466 |
# label="Response 1",
|
| 467 |
lines=15,
|
| 468 |
interactive=False)
|
| 469 |
+
with gr.Row():
|
| 470 |
+
ref_table = gr.Dataframe(
|
| 471 |
+
label="Reference",
|
| 472 |
+
headers=["No.",'Link', 'Study name', 'Condition', 'Intervention'],
|
| 473 |
+
datatype=["markdown","html","markdown", "markdown","markdown"],
|
| 474 |
+
wrap=True,
|
| 475 |
+
interactive=False)
|
| 476 |
# with gr.Column():
|
| 477 |
# rag_box = gr.Textbox(
|
| 478 |
# label="Response 2",
|
|
|
|
| 483 |
# label="Response 3",
|
| 484 |
# lines=15,
|
| 485 |
# interactive=False)
|
| 486 |
+
with gr.Row():
|
| 487 |
+
regenerate_button = gr.Button("Regenerate")
|
| 488 |
+
|
| 489 |
inputs_information = [top_k_box, study_obj_box, study_type_box, phase_box, purpose_box, allocation_box, intervention_model_box, masking_box, conditions_box, intervention_box, location_box, removed_location_box]
|
| 490 |
+
outputs_information = [base_box,ref_table]
|
| 491 |
# outputs_information = [base_box, rag_box,combine_box]
|
| 492 |
|
| 493 |
submit_button.click(
|
|
|
|
| 495 |
inputs=inputs_information,
|
| 496 |
outputs=outputs_information
|
| 497 |
)
|
| 498 |
+
|
| 499 |
+
regenerate_button.click(
|
| 500 |
+
run_function_on_text,
|
| 501 |
+
inputs=inputs_information,
|
| 502 |
+
outputs=outputs_information
|
| 503 |
+
)
|
| 504 |
|
| 505 |
+
clear_button.click(lambda : [None] * len(inputs_information), outputs=inputs_information)
|
| 506 |
|
| 507 |
# with gr.Row():
|
| 508 |
# selected_response = gr.Radio(
|