Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
CHANGED
@@ -23,6 +23,14 @@ checker_pipe = pipeline('text-classification', 'ksg-dfci/TrialChecker', tokenize
|
|
23 |
truncation=True, padding='max_length', max_length=512)
|
24 |
|
25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
# We assume the following objects have already been loaded:
|
28 |
# trial_spaces (DataFrame), embedding_model (SentenceTransformer),
|
@@ -54,7 +62,11 @@ def match_clinical_trials(patient_summary: str):
|
|
54 |
'trial_eligibility_criteria': relevant_eligibility_criteria
|
55 |
}).reset_index(drop=True)
|
56 |
|
57 |
-
analysis['pt_trial_pair'] =
|
|
|
|
|
|
|
|
|
58 |
|
59 |
# Run checker pipeline
|
60 |
classifier_results = checker_pipe(analysis.pt_trial_pair.tolist())
|
@@ -62,16 +74,7 @@ def match_clinical_trials(patient_summary: str):
|
|
62 |
analysis['trial_checker_score'] = [x['score'] for x in classifier_results]
|
63 |
|
64 |
# Return the final subset of columns including patient_summary_query as first column
|
65 |
-
|
66 |
-
'patient_summary_query',
|
67 |
-
'nct_id',
|
68 |
-
'trial_title',
|
69 |
-
'trial_brief_summary',
|
70 |
-
'trial_eligibility_criteria',
|
71 |
-
'this_space',
|
72 |
-
'trial_checker_result',
|
73 |
-
'trial_checker_score'
|
74 |
-
]], analysis[[
|
75 |
'patient_summary_query',
|
76 |
'nct_id',
|
77 |
'trial_title',
|
@@ -81,6 +84,7 @@ def match_clinical_trials(patient_summary: str):
|
|
81 |
'trial_checker_result',
|
82 |
'trial_checker_score'
|
83 |
]]
|
|
|
84 |
|
85 |
def export_results(df: pd.DataFrame):
|
86 |
# Save the dataframe to a temporary CSV file and return its path
|
@@ -102,9 +106,9 @@ custom_css = """
|
|
102 |
|
103 |
#output_df table td, #output_df table th {
|
104 |
min-width: 100px;
|
105 |
-
|
106 |
-
|
107 |
-
white-space:
|
108 |
border: 1px solid #ccc;
|
109 |
padding: 4px;
|
110 |
}
|
@@ -142,14 +146,18 @@ with gr.Blocks(css=custom_css) as demo:
|
|
142 |
export_btn = gr.Button("Export Results")
|
143 |
|
144 |
# On "Find Matches", show the DataFrame and store it in state
|
145 |
-
submit_btn.click(
|
146 |
-
|
147 |
-
|
|
|
|
|
148 |
|
149 |
# On "Export Results", use the state to create and return a CSV file
|
150 |
-
export_btn.click(
|
151 |
-
|
152 |
-
|
|
|
|
|
153 |
|
154 |
if __name__ == '__main__':
|
155 |
demo.launch()
|
|
|
23 |
truncation=True, padding='max_length', max_length=512)
|
24 |
|
25 |
|
26 |
+
import gradio as gr
|
27 |
+
import pandas as pd
|
28 |
+
import torch
|
29 |
+
import torch.nn.functional as F
|
30 |
+
from sentence_transformers import SentenceTransformer
|
31 |
+
from safetensors import safe_open
|
32 |
+
from transformers import pipeline, AutoTokenizer
|
33 |
+
import tempfile
|
34 |
|
35 |
# We assume the following objects have already been loaded:
|
36 |
# trial_spaces (DataFrame), embedding_model (SentenceTransformer),
|
|
|
62 |
'trial_eligibility_criteria': relevant_eligibility_criteria
|
63 |
}).reset_index(drop=True)
|
64 |
|
65 |
+
analysis['pt_trial_pair'] = (
|
66 |
+
analysis['this_space']
|
67 |
+
+ "\nNow here is the patient summary:"
|
68 |
+
+ analysis['patient_summary_query']
|
69 |
+
)
|
70 |
|
71 |
# Run checker pipeline
|
72 |
classifier_results = checker_pipe(analysis.pt_trial_pair.tolist())
|
|
|
74 |
analysis['trial_checker_score'] = [x['score'] for x in classifier_results]
|
75 |
|
76 |
# Return the final subset of columns including patient_summary_query as first column
|
77 |
+
out_df = analysis[[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
'patient_summary_query',
|
79 |
'nct_id',
|
80 |
'trial_title',
|
|
|
84 |
'trial_checker_result',
|
85 |
'trial_checker_score'
|
86 |
]]
|
87 |
+
return out_df, out_df
|
88 |
|
89 |
def export_results(df: pd.DataFrame):
|
90 |
# Save the dataframe to a temporary CSV file and return its path
|
|
|
106 |
|
107 |
#output_df table td, #output_df table th {
|
108 |
min-width: 100px;
|
109 |
+
max-width: 300px;
|
110 |
+
overflow-wrap: anywhere; /* or 'word-wrap: break-word;' */
|
111 |
+
white-space: pre-wrap; /* or 'white-space: normal;' */
|
112 |
border: 1px solid #ccc;
|
113 |
padding: 4px;
|
114 |
}
|
|
|
146 |
export_btn = gr.Button("Export Results")
|
147 |
|
148 |
# On "Find Matches", show the DataFrame and store it in state
|
149 |
+
submit_btn.click(
|
150 |
+
fn=match_clinical_trials,
|
151 |
+
inputs=patient_summary_input,
|
152 |
+
outputs=[output_df, results_state]
|
153 |
+
)
|
154 |
|
155 |
# On "Export Results", use the state to create and return a CSV file
|
156 |
+
export_btn.click(
|
157 |
+
fn=export_results,
|
158 |
+
inputs=results_state,
|
159 |
+
outputs=gr.File(label="Download CSV")
|
160 |
+
)
|
161 |
|
162 |
if __name__ == '__main__':
|
163 |
demo.launch()
|