kenlkehl commited on
Commit
edd9b01
Β·
verified Β·
1 Parent(s): 784ed65

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -11
app.py CHANGED
@@ -370,8 +370,8 @@ def load_llm_model(model_path: str) -> Tuple[str, str]:
370
  state.llm_model = LLM(
371
  model=model_path,
372
  tensor_parallel_size=tp_size,
373
- gpu_memory_utilization=0.75,
374
- max_model_len=12000
375
  )
376
  state.llm_tokenizer = state.llm_model.get_tokenizer()
377
  return f"βœ“ LLM loaded from {model_path} (vLLM, tp={tp_size})", ""
@@ -1042,6 +1042,23 @@ def get_trial_details(df: pd.DataFrame, evt: gr.SelectData) -> str:
1042
 
1043
  def create_interface():
1044
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1045
  # Custom theme and CSS for a cleaner, modern look
1046
  theme = gr.themes.Soft(
1047
  primary_hue="blue",
@@ -1080,7 +1097,8 @@ def create_interface():
1080
  gr.Markdown("### πŸ“„ Upload Records")
1081
  notes_file = gr.File(
1082
  label="Upload Patient Notes (CSV or Excel)",
1083
- file_types=[".csv", ".xlsx", ".xls"]
 
1084
  )
1085
 
1086
  # Hidden advanced option
@@ -1102,8 +1120,7 @@ def create_interface():
1102
  long_note_output = gr.Textbox(
1103
  label="Extracted Patient History (Long Note)",
1104
  lines=10,
1105
- interactive=False,
1106
- #show_copy_button=True # doesn't work on HF space
1107
  )
1108
 
1109
  process_notes_btn.click(
@@ -1127,15 +1144,13 @@ def create_interface():
1127
  label="Patient Summary",
1128
  lines=12,
1129
  placeholder="Enter or generate patient summary here...",
1130
- info="Age, sex, Cancer type, histology, extent, biomarkers, treatment history",
1131
- #show_copy_button=True
1132
  )
1133
  patient_boilerplate = gr.Textbox(
1134
  label="Patient Boilerplate Text",
1135
  lines=12,
1136
  placeholder="Mentions of exclusion criteria (brain mets, etc.)",
1137
- info="Evidence of potential boilerplate exclusions",
1138
- #show_copy_button=True
1139
  )
1140
 
1141
  # Wire up summarization to output to BOTH textboxes
@@ -1304,8 +1319,7 @@ def create_interface():
1304
  trial_spaces_output = gr.Textbox(
1305
  label="Extracted Results",
1306
  lines=15,
1307
- interactive=False,
1308
- #show_copy_button=True
1309
  )
1310
 
1311
  extract_btn.click(
@@ -1337,5 +1351,6 @@ if __name__ == "__main__":
1337
  demo = create_interface()
1338
  demo.launch(
1339
  server_name="0.0.0.0",
 
1340
  share=False
1341
  )
 
370
  state.llm_model = LLM(
371
  model=model_path,
372
  tensor_parallel_size=tp_size,
373
+ gpu_memory_utilization=0.60,
374
+ max_model_len=15000
375
  )
376
  state.llm_tokenizer = state.llm_model.get_tokenizer()
377
  return f"βœ“ LLM loaded from {model_path} (vLLM, tp={tp_size})", ""
 
1042
 
1043
  def create_interface():
1044
 
1045
+ # Attempt to load sample patient notes for pre-population
1046
+ sample_notes_path = None
1047
+ try:
1048
+ gr.Info("Loading sample patient notes...")
1049
+ # Correct raw URL for the CSV file
1050
+ sample_url = "https://huggingface.co/datasets/ksg-dfci/mmai-synthetic/raw/main/sample_patient_notes.csv"
1051
+ sample_df = pd.read_csv(sample_url)
1052
+
1053
+ # Create a temporary file to hold the sample notes
1054
+ with tempfile.NamedTemporaryFile(delete=False, mode='w', suffix='.csv', newline='') as tmpfile:
1055
+ sample_df.to_csv(tmpfile, index=False)
1056
+ sample_notes_path = tmpfile.name
1057
+ print(f"βœ“ Sample patient notes loaded and saved to temp file: {sample_notes_path}")
1058
+ except Exception as e:
1059
+ gr.Warning(f"Could not pre-load sample patient notes: {e}")
1060
+ print(f"βœ— Warning: Could not pre-load sample patient notes: {e}")
1061
+
1062
  # Custom theme and CSS for a cleaner, modern look
1063
  theme = gr.themes.Soft(
1064
  primary_hue="blue",
 
1097
  gr.Markdown("### πŸ“„ Upload Records")
1098
  notes_file = gr.File(
1099
  label="Upload Patient Notes (CSV or Excel)",
1100
+ file_types=[".csv", ".xlsx", ".xls"],
1101
+ value=sample_notes_path
1102
  )
1103
 
1104
  # Hidden advanced option
 
1120
  long_note_output = gr.Textbox(
1121
  label="Extracted Patient History (Long Note)",
1122
  lines=10,
1123
+ interactive=False
 
1124
  )
1125
 
1126
  process_notes_btn.click(
 
1144
  label="Patient Summary",
1145
  lines=12,
1146
  placeholder="Enter or generate patient summary here...",
1147
+ info="Age, sex, Cancer type, histology, extent, biomarkers, treatment history"
 
1148
  )
1149
  patient_boilerplate = gr.Textbox(
1150
  label="Patient Boilerplate Text",
1151
  lines=12,
1152
  placeholder="Mentions of exclusion criteria (brain mets, etc.)",
1153
+ info="Evidence of potential boilerplate exclusions"
 
1154
  )
1155
 
1156
  # Wire up summarization to output to BOTH textboxes
 
1319
  trial_spaces_output = gr.Textbox(
1320
  label="Extracted Results",
1321
  lines=15,
1322
+ interactive=False
 
1323
  )
1324
 
1325
  extract_btn.click(
 
1351
  demo = create_interface()
1352
  demo.launch(
1353
  server_name="0.0.0.0",
1354
+ server_port=7860,
1355
  share=False
1356
  )