nttwt1597 commited on
Commit
ccb2b2f
·
verified ·
1 Parent(s): 8850113

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +230 -138
app.py CHANGED
@@ -314,186 +314,278 @@ interventions_place_holder = f"""Example:
314
 
315
  prefilled_value = f"""Study Objectives The purpose of this study is to find out if the combination of docetaxel and capecitabine can shrink the size of breast tumors and preserve the breast. Conditions: Breast Cancer Intervention / Treatment: DRUG: Docetaxel, DRUG: Capecitabine Location: United States Study Design and Phases Study Type: INTERVENTIONAL Phase: PHASE2 Primary Purpose: TREATMENT Allocation: RANDOMIZED Interventional Model: PARALLEL Masking: NONE"""
316
 
317
- # custom_css = """
318
- # .gradio-container {
319
- # font-family: 'Roboto', sans-serif;
320
- # }
321
- # .main-header {
322
- # text-align: center;
323
- # color: #4a4a4a;
324
- # margin-bottom: 2rem;
325
- # }
326
- # .tab-header {
327
- # font-size: 1.2rem;
328
- # font-weight: bold;
329
- # margin-bottom: 1rem;
330
- # }
331
- # .custom-chatbot {
332
- # border-radius: 10px;
333
- # box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
334
- # }
335
- # .custom-button {
336
- # background-color: #3498db;
337
- # color: white;
338
- # border: none;
339
- # padding: 10px 20px;
340
- # border-radius: 5px;
341
- # cursor: pointer;
342
- # transition: background-color 0.3s ease;
343
- # }
344
- # .custom-button:hover {
345
- # background-color: #2980b9;
346
- # }
347
- # """
348
-
349
- # # Define Gradio theme
350
- # theme = gr.themes.Default(
351
- # primary_hue="zinc",
352
- # secondary_hue="red",
353
- # neutral_hue="neutral",
354
- # font=[gr.themes.GoogleFont('Roboto'), "sans-serif"]
355
- # )
356
-
357
- with gr.Blocks() as demo:
358
-
359
- with gr.Row():
360
- gr.Markdown("# Reference paper"),
361
- with gr.Row():
362
- top_k_box = gr.Slider(
363
  label="Amount of reference paper",
364
  value=5,
365
  minimum=0,
366
  maximum=30,
367
  step=1,
368
  )
369
- # Study description
370
- with gr.Row():
371
- gr.Markdown("# Research Information"),
372
- with gr.Row():
373
- study_obj_box = gr.Textbox(
374
  label="Study Objective / Study Description", # Study description
375
  placeholder=objective_place_holder,
376
  lines=10)
377
- # Study Design
378
- with gr.Row():
379
- gr.Markdown("# Study Design"),
380
- with gr.Column():
381
- study_type_box = gr.Radio(
382
  ["Expanded Access", "Interventional", "Observational"],
383
  label="Study Type",
384
  )
385
- phase_box= gr.Radio(
386
  ["Not Applicable", "Early Phase 1", "Phase 1", "Phase 2", "Phase 3", "Phase 4"],
387
  label="Phase"
388
  )
389
- purpose_box = gr.Radio(
390
  ["Treatment", "Prevention", "Diagnostic", "Educational/Counseling/Training", "Supportive Care", "Screening", "Health Services Research", "Basic Science", "Device Feasibility", "Other"],
391
  label="Primary Purpose"
392
  )
393
- allocation_box = gr.Radio(
394
  ["Randomized", "Non-Randomized", "N/A"],
395
  label="Allocation"
396
  )
397
- intervention_model_box = gr.Radio(
398
  ["Parallel", "Single-Group", "Crossover", "Factorial", "Sequential"],
399
  label="Interventional Model"
400
  )
401
- masking_box = gr.Radio(
402
  ["None (Open Label)", "Single", "Double", "Triple", "Quadruple"],
403
  label="Masking"
404
  )
405
- # Conditions
406
- with gr.Row():
407
- gr.Markdown("# Conditions"),
408
- with gr.Row():
409
- conditions_box = gr.Textbox(
410
  label="Conditions / Disease",
411
- info="Primary Disease or Condition of Cancer Being Studied in the Trial, or the Focus of the Study",
412
- placeholder=conditions_place_holder,
413
  )
414
- #Interventions
415
- with gr.Row():
416
- gr.Markdown("# Interventions / Drugs"),
417
- with gr.Row():
418
- intervention_box = gr.Textbox(
419
  label="Intervention type",
420
  placeholder=interventions_place_holder,
421
- lines=10,
422
  )
423
- #Location
424
- with gr.Row():
425
- gr.Markdown("# Location"),
426
- with gr.Column():
427
- location_box = gr.Textbox(
428
  label="Location (Countries)",
429
  )
430
- removed_location_box = gr.Textbox(
431
  label="Removed Location (Countries)",
432
  )
433
-
434
- # Submit & Clear
435
- with gr.Row():
436
- submit_button = gr.Button("Submit")
437
- clear_button = gr.Button("Clear")
438
-
439
- # Output
440
- with gr.Row():
441
- gr.Markdown("# Eligibility Criteria Generation"),
442
- with gr.Row():
443
- with gr.Column():
444
- base_box = gr.Textbox(
445
- label="Response 1",
446
- lines=15,
447
- interactive=False)
448
- with gr.Column():
449
- rag_box = gr.Textbox(
450
- label="Response 2",
451
- lines=15,
452
- interactive=False)
453
- with gr.Column():
454
- combine_box = gr.Textbox(
455
- label="Response 3",
456
- lines=15,
457
- interactive=False)
458
-
459
- 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]
460
- outputs_information = [base_box, rag_box,combine_box]
461
-
462
- submit_button.click(
463
- run_function_on_text,
464
- inputs=inputs_information,
465
- outputs=outputs_information
466
- )
467
-
468
- clear_button.click(lambda : [None] * len(inputs_information), outputs=inputs_information)
469
-
470
- with gr.Row():
471
- selected_response = gr.Radio(
472
- choices=[
473
  "Response 1",
474
  "Response 2",
475
  "Response 3",
476
  "All responses are equally good",
477
  "Neither response is satisfactory"
478
  ],
479
- label="Select the best response"
480
- )
481
- with gr.Row():
482
- flag_button = gr.Button("Flag Selected Response")
483
-
484
- #Flagging
485
- token_w = os.environ['token_w']
486
- hf_writer = gr.HuggingFaceDatasetSaver(hf_token=token_w, dataset_name="ravistech/feedback-demo", private=True)
487
- hf_writer.setup([selected_response, 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, top_k_box, base_box, rag_box, combine_box],"ravistech/feedback-demo")
488
-
489
- flag_button.click(lambda *args: callback.flag(list(args)), [selected_response, 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, top_k_box, base_box, rag_box, combine_box], None, preprocess=False)
490
 
491
- with gr.Row():
492
- clear_all_button = gr.Button("Clear All")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
493
 
494
- flag_response = [selected_response]
495
- all_information = inputs_information + outputs_information + flag_response
496
- clear_all_button.click(lambda : [None] * len(all_information), outputs=all_information)
 
 
 
 
497
 
498
- if __name__ == "__main__":
499
- demo.launch(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
314
 
315
  prefilled_value = f"""Study Objectives The purpose of this study is to find out if the combination of docetaxel and capecitabine can shrink the size of breast tumors and preserve the breast. Conditions: Breast Cancer Intervention / Treatment: DRUG: Docetaxel, DRUG: Capecitabine Location: United States Study Design and Phases Study Type: INTERVENTIONAL Phase: PHASE2 Primary Purpose: TREATMENT Allocation: RANDOMIZED Interventional Model: PARALLEL Masking: NONE"""
316
 
317
+ hf_writer = gr.HuggingFaceDatasetSaver(hf_token=token_w, dataset_name="ravistech/feedback-demo", private=True)
318
+ top_k_box = gr.Slider(
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
319
  label="Amount of reference paper",
320
  value=5,
321
  minimum=0,
322
  maximum=30,
323
  step=1,
324
  )
325
+ study_obj_box = gr.Textbox(
 
 
 
 
326
  label="Study Objective / Study Description", # Study description
327
  placeholder=objective_place_holder,
328
  lines=10)
329
+
330
+ study_type_box = gr.Radio(
 
 
 
331
  ["Expanded Access", "Interventional", "Observational"],
332
  label="Study Type",
333
  )
334
+ phase_box= gr.Radio(
335
  ["Not Applicable", "Early Phase 1", "Phase 1", "Phase 2", "Phase 3", "Phase 4"],
336
  label="Phase"
337
  )
338
+ purpose_box = gr.Radio(
339
  ["Treatment", "Prevention", "Diagnostic", "Educational/Counseling/Training", "Supportive Care", "Screening", "Health Services Research", "Basic Science", "Device Feasibility", "Other"],
340
  label="Primary Purpose"
341
  )
342
+ allocation_box = gr.Radio(
343
  ["Randomized", "Non-Randomized", "N/A"],
344
  label="Allocation"
345
  )
346
+ intervention_model_box = gr.Radio(
347
  ["Parallel", "Single-Group", "Crossover", "Factorial", "Sequential"],
348
  label="Interventional Model"
349
  )
350
+ masking_box = gr.Radio(
351
  ["None (Open Label)", "Single", "Double", "Triple", "Quadruple"],
352
  label="Masking"
353
  )
354
+ conditions_box = gr.Textbox(
 
 
 
 
355
  label="Conditions / Disease",
 
 
356
  )
357
+ intervention_box = gr.Textbox(
 
 
 
 
358
  label="Intervention type",
359
  placeholder=interventions_place_holder,
 
360
  )
361
+ location_box = gr.Textbox(
 
 
 
 
362
  label="Location (Countries)",
363
  )
364
+ removed_location_box = gr.Textbox(
365
  label="Removed Location (Countries)",
366
  )
367
+ base_box = gr.Textbox(
368
+ label="Response 1",
369
+ lines=10,
370
+ interactive=False)
371
+ rag_box = gr.Textbox(
372
+ label="Response 2",
373
+ lines=10,
374
+ interactive=False)
375
+
376
+
377
+ demo = gr.Interface(
378
+ fn= run_function_on_text,
379
+ inputs=[
380
+ top_k_box,
381
+ study_obj_box,
382
+ study_type_box,
383
+ phase_box,
384
+ purpose_box,
385
+ allocation_box,
386
+ intervention_model_box,
387
+ masking_box,
388
+ conditions_box,
389
+ intervention_box,
390
+ location_box,
391
+ removed_location_box],
392
+ outputs=[
393
+ base_box,
394
+ rag_box],
395
+ title='Eligibility Criteria Generation',
396
+ # description='',
397
+ allow_flagging="manual",
398
+ flagging_options=[
 
 
 
 
 
 
 
 
399
  "Response 1",
400
  "Response 2",
401
  "Response 3",
402
  "All responses are equally good",
403
  "Neither response is satisfactory"
404
  ],
405
+ flagging_callback=hf_writer,
406
+ )
 
 
 
 
 
 
 
 
 
407
 
408
+ demo.launch(debug=True)
409
+ # custom_css = """
410
+ # .gradio-container {
411
+ # font-family: 'Roboto', sans-serif;
412
+ # }
413
+ # .main-header {
414
+ # text-align: center;
415
+ # color: #4a4a4a;
416
+ # margin-bottom: 2rem;
417
+ # }
418
+ # .tab-header {
419
+ # font-size: 1.2rem;
420
+ # font-weight: bold;
421
+ # margin-bottom: 1rem;
422
+ # }
423
+ # .custom-chatbot {
424
+ # border-radius: 10px;
425
+ # box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
426
+ # }
427
+ # .custom-button {
428
+ # background-color: #3498db;
429
+ # color: white;
430
+ # border: none;
431
+ # padding: 10px 20px;
432
+ # border-radius: 5px;
433
+ # cursor: pointer;
434
+ # transition: background-color 0.3s ease;
435
+ # }
436
+ # .custom-button:hover {
437
+ # background-color: #2980b9;
438
+ # }
439
+ # """
440
 
441
+ # # Define Gradio theme
442
+ # theme = gr.themes.Default(
443
+ # primary_hue="zinc",
444
+ # secondary_hue="red",
445
+ # neutral_hue="neutral",
446
+ # font=[gr.themes.GoogleFont('Roboto'), "sans-serif"]
447
+ # )
448
 
449
+ # with gr.Blocks() as demo:
450
+
451
+ # with gr.Row():
452
+ # gr.Markdown("# Reference paper"),
453
+ # with gr.Row():
454
+ # top_k_box = gr.Slider(
455
+ # label="Amount of reference paper",
456
+ # value=5,
457
+ # minimum=0,
458
+ # maximum=30,
459
+ # step=1,
460
+ # )
461
+ # # Study description
462
+ # with gr.Row():
463
+ # gr.Markdown("# Research Information"),
464
+ # with gr.Row():
465
+ # study_obj_box = gr.Textbox(
466
+ # label="Study Objective / Study Description", # Study description
467
+ # placeholder=objective_place_holder,
468
+ # lines=10)
469
+ # # Study Design
470
+ # with gr.Row():
471
+ # gr.Markdown("# Study Design"),
472
+ # with gr.Column():
473
+ # study_type_box = gr.Radio(
474
+ # ["Expanded Access", "Interventional", "Observational"],
475
+ # label="Study Type",
476
+ # )
477
+ # phase_box= gr.Radio(
478
+ # ["Not Applicable", "Early Phase 1", "Phase 1", "Phase 2", "Phase 3", "Phase 4"],
479
+ # label="Phase"
480
+ # )
481
+ # purpose_box = gr.Radio(
482
+ # ["Treatment", "Prevention", "Diagnostic", "Educational/Counseling/Training", "Supportive Care", "Screening", "Health Services Research", "Basic Science", "Device Feasibility", "Other"],
483
+ # label="Primary Purpose"
484
+ # )
485
+ # allocation_box = gr.Radio(
486
+ # ["Randomized", "Non-Randomized", "N/A"],
487
+ # label="Allocation"
488
+ # )
489
+ # intervention_model_box = gr.Radio(
490
+ # ["Parallel", "Single-Group", "Crossover", "Factorial", "Sequential"],
491
+ # label="Interventional Model"
492
+ # )
493
+ # masking_box = gr.Radio(
494
+ # ["None (Open Label)", "Single", "Double", "Triple", "Quadruple"],
495
+ # label="Masking"
496
+ # )
497
+ # # Conditions
498
+ # with gr.Row():
499
+ # gr.Markdown("# Conditions"),
500
+ # with gr.Row():
501
+ # conditions_box = gr.Textbox(
502
+ # label="Conditions / Disease",
503
+ # info="Primary Disease or Condition of Cancer Being Studied in the Trial, or the Focus of the Study",
504
+ # placeholder=conditions_place_holder,
505
+ # )
506
+ # #Interventions
507
+ # with gr.Row():
508
+ # gr.Markdown("# Interventions / Drugs"),
509
+ # with gr.Row():
510
+ # intervention_box = gr.Textbox(
511
+ # label="Intervention type",
512
+ # placeholder=interventions_place_holder,
513
+ # lines=10,
514
+ # )
515
+ # #Location
516
+ # with gr.Row():
517
+ # gr.Markdown("# Location"),
518
+ # with gr.Column():
519
+ # location_box = gr.Textbox(
520
+ # label="Location (Countries)",
521
+ # )
522
+ # removed_location_box = gr.Textbox(
523
+ # label="Removed Location (Countries)",
524
+ # )
525
+
526
+ # # Submit & Clear
527
+ # with gr.Row():
528
+ # submit_button = gr.Button("Submit")
529
+ # clear_button = gr.Button("Clear")
530
+
531
+ # # Output
532
+ # with gr.Row():
533
+ # gr.Markdown("# Eligibility Criteria Generation"),
534
+ # with gr.Row():
535
+ # with gr.Column():
536
+ # base_box = gr.Textbox(
537
+ # label="Response 1",
538
+ # lines=15,
539
+ # interactive=False)
540
+ # with gr.Column():
541
+ # rag_box = gr.Textbox(
542
+ # label="Response 2",
543
+ # lines=15,
544
+ # interactive=False)
545
+ # with gr.Column():
546
+ # combine_box = gr.Textbox(
547
+ # label="Response 3",
548
+ # lines=15,
549
+ # interactive=False)
550
+
551
+ # 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]
552
+ # outputs_information = [base_box, rag_box,combine_box]
553
+
554
+ # submit_button.click(
555
+ # run_function_on_text,
556
+ # inputs=inputs_information,
557
+ # outputs=outputs_information
558
+ # )
559
+
560
+ # clear_button.click(lambda : [None] * len(inputs_information), outputs=inputs_information)
561
+
562
+ # with gr.Row():
563
+ # selected_response = gr.Radio(
564
+ # choices=[
565
+ # "Response 1",
566
+ # "Response 2",
567
+ # "Response 3",
568
+ # "All responses are equally good",
569
+ # "Neither response is satisfactory"
570
+ # ],
571
+ # label="Select the best response"
572
+ # )
573
+ # with gr.Row():
574
+ # flag_button = gr.Button("Flag Selected Response")
575
+
576
+ # #Flagging
577
+ # token_w = os.environ['token_w']
578
+ # hf_writer = gr.HuggingFaceDatasetSaver(hf_token=token_w, dataset_name="ravistech/feedback-demo", private=True)
579
+ # hf_writer.setup([selected_response, 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, top_k_box, base_box, rag_box, combine_box],"ravistech/feedback-demo")
580
+
581
+ # flag_button.click(lambda *args: callback.flag(list(args)), [selected_response, 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, top_k_box, base_box, rag_box, combine_box], None, preprocess=False)
582
+
583
+ # with gr.Row():
584
+ # clear_all_button = gr.Button("Clear All")
585
+
586
+ # flag_response = [selected_response]
587
+ # all_information = inputs_information + outputs_information + flag_response
588
+ # clear_all_button.click(lambda : [None] * len(all_information), outputs=all_information)
589
+
590
+ # if __name__ == "__main__":
591
+ # demo.launch(debug=True)