schuldt-ogre commited on
Commit ·
be8150a
1
Parent(s): 67244f5
Update schema
Browse files
app.py
CHANGED
|
@@ -1,12 +1,30 @@
|
|
| 1 |
-
from concrete.ml.deployment import FHEModelClient
|
| 2 |
-
from pathlib import Path
|
| 3 |
-
import numpy as np
|
| 4 |
import gradio as gr
|
| 5 |
import requests
|
| 6 |
-
import json
|
| 7 |
-
|
| 8 |
from typing import List
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
# Define possible categories for fields without predefined categories
|
| 11 |
additional_categories = {
|
| 12 |
"Gender": ["Male", "Female", "Other"],
|
|
@@ -24,9 +42,10 @@ additional_categories = {
|
|
| 24 |
"Previous_Trial_Participation": ["Yes", "No"]
|
| 25 |
}
|
| 26 |
|
| 27 |
-
# Define the input components for the researcher form
|
| 28 |
-
min_age_input = gr.Number(label="Minimum Age", value=18)
|
| 29 |
-
max_age_input = gr.Number(label="Maximum Age", value=100)
|
|
|
|
| 30 |
gender_input = gr.CheckboxGroup(choices=additional_categories["Gender"], label="Gender")
|
| 31 |
ethnicity_input = gr.CheckboxGroup(choices=additional_categories["Ethnicity"], label="Ethnicity")
|
| 32 |
geographic_location_input = gr.CheckboxGroup(choices=additional_categories["Geographic_Location"], label="Geographic Location")
|
|
@@ -34,23 +53,32 @@ diagnoses_icd10_input = gr.CheckboxGroup(choices=additional_categories["Diagnose
|
|
| 34 |
medications_input = gr.CheckboxGroup(choices=additional_categories["Medications"], label="Medications")
|
| 35 |
allergies_input = gr.CheckboxGroup(choices=additional_categories["Allergies"], label="Allergies")
|
| 36 |
previous_treatments_input = gr.CheckboxGroup(choices=additional_categories["Previous_Treatments"], label="Previous Treatments")
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
smoking_status_input = gr.CheckboxGroup(choices=additional_categories["Smoking_Status"], label="Smoking Status")
|
| 46 |
alcohol_consumption_input = gr.CheckboxGroup(choices=additional_categories["Alcohol_Consumption"], label="Alcohol Consumption")
|
| 47 |
exercise_habits_input = gr.CheckboxGroup(choices=additional_categories["Exercise_Habits"], label="Exercise Habits")
|
| 48 |
diet_input = gr.CheckboxGroup(choices=additional_categories["Diet"], label="Diet")
|
| 49 |
-
|
| 50 |
-
|
|
|
|
|
|
|
| 51 |
functional_status_input = gr.CheckboxGroup(choices=additional_categories["Functional_Status"], label="Functional Status")
|
| 52 |
previous_trial_participation_input = gr.CheckboxGroup(choices=additional_categories["Previous_Trial_Participation"], label="Previous Trial Participation")
|
| 53 |
|
|
|
|
|
|
|
| 54 |
|
| 55 |
def encode_categorical_data(data: List[str], category_name: str) -> List[int]:
|
| 56 |
"""Encodes a list of categorical values into their corresponding indices based on additional_categories."""
|
|
@@ -58,12 +86,19 @@ def encode_categorical_data(data: List[str], category_name: str) -> List[int]:
|
|
| 58 |
encoded_data = []
|
| 59 |
for value in data:
|
| 60 |
if value in sub_cats:
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
else:
|
| 63 |
-
|
|
|
|
| 64 |
return encoded_data
|
| 65 |
|
| 66 |
-
|
| 67 |
def process_researcher_data(
|
| 68 |
min_age, max_age, gender, ethnicity, geographic_location, diagnoses_icd10, medications, allergies, previous_treatments,
|
| 69 |
min_blood_glucose_level, max_blood_glucose_level, min_blood_pressure_systolic, max_blood_pressure_systolic,
|
|
@@ -75,6 +110,9 @@ def process_researcher_data(
|
|
| 75 |
encoded_ethnicity = encode_categorical_data(ethnicity, "Ethnicity")
|
| 76 |
encoded_geographic_location = encode_categorical_data(geographic_location, "Geographic_Location")
|
| 77 |
encoded_diagnoses_icd10 = encode_categorical_data(diagnoses_icd10, "Diagnoses_ICD10")
|
|
|
|
|
|
|
|
|
|
| 78 |
encoded_smoking_status = encode_categorical_data(smoking_status, "Smoking_Status")
|
| 79 |
encoded_alcohol_consumption = encode_categorical_data(alcohol_consumption, "Alcohol_Consumption")
|
| 80 |
encoded_exercise_habits = encode_categorical_data(exercise_habits, "Exercise_Habits")
|
|
@@ -86,195 +124,66 @@ def process_researcher_data(
|
|
| 86 |
requirements = []
|
| 87 |
|
| 88 |
# Add numerical requirements
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
"comparison_type": "less_than"
|
| 113 |
-
})
|
| 114 |
-
|
| 115 |
-
if min_blood_pressure_systolic is not None:
|
| 116 |
-
requirements.append({
|
| 117 |
-
"column_name": "Blood_Pressure_Systolic",
|
| 118 |
-
"value": int(min_blood_pressure_systolic),
|
| 119 |
-
"comparison_type": "greater_than"
|
| 120 |
-
})
|
| 121 |
-
if max_blood_pressure_systolic is not None:
|
| 122 |
-
requirements.append({
|
| 123 |
-
"column_name": "Blood_Pressure_Systolic",
|
| 124 |
-
"value": int(max_blood_pressure_systolic),
|
| 125 |
-
"comparison_type": "less_than"
|
| 126 |
-
})
|
| 127 |
-
|
| 128 |
-
if min_blood_pressure_diastolic is not None:
|
| 129 |
-
requirements.append({
|
| 130 |
-
"column_name": "Blood_Pressure_Diastolic",
|
| 131 |
-
"value": int(min_blood_pressure_diastolic),
|
| 132 |
-
"comparison_type": "greater_than"
|
| 133 |
-
})
|
| 134 |
-
if max_blood_pressure_diastolic is not None:
|
| 135 |
-
requirements.append({
|
| 136 |
-
"column_name": "Blood_Pressure_Diastolic",
|
| 137 |
-
"value": int(max_blood_pressure_diastolic),
|
| 138 |
-
"comparison_type": "less_than"
|
| 139 |
-
})
|
| 140 |
-
|
| 141 |
-
if min_bmi is not None:
|
| 142 |
-
requirements.append({
|
| 143 |
-
"column_name": "BMI",
|
| 144 |
-
"value": float(min_bmi),
|
| 145 |
-
"comparison_type": "greater_than"
|
| 146 |
-
})
|
| 147 |
-
if max_bmi is not None:
|
| 148 |
-
requirements.append({
|
| 149 |
-
"column_name": "BMI",
|
| 150 |
-
"value": float(max_bmi),
|
| 151 |
-
"comparison_type": "less_than"
|
| 152 |
-
})
|
| 153 |
-
|
| 154 |
-
if min_condition_severity is not None:
|
| 155 |
-
requirements.append({
|
| 156 |
-
"column_name": "Condition_Severity",
|
| 157 |
-
"value": int(min_condition_severity),
|
| 158 |
-
"comparison_type": "greater_than"
|
| 159 |
-
})
|
| 160 |
-
if max_condition_severity is not None:
|
| 161 |
-
requirements.append({
|
| 162 |
-
"column_name": "Condition_Severity",
|
| 163 |
-
"value": int(max_condition_severity),
|
| 164 |
-
"comparison_type": "less_than"
|
| 165 |
-
})
|
| 166 |
-
|
| 167 |
-
# Add categorical requirements
|
| 168 |
-
for gender_value in encoded_gender:
|
| 169 |
-
if gender_value > 0:
|
| 170 |
-
requirements.append({
|
| 171 |
-
"column_name": "Gender",
|
| 172 |
-
"value": gender_value,
|
| 173 |
-
"comparison_type": "equal"
|
| 174 |
-
})
|
| 175 |
-
|
| 176 |
-
for ethnicity_value in encoded_ethnicity:
|
| 177 |
-
if ethnicity_value > 0:
|
| 178 |
requirements.append({
|
| 179 |
-
"column_name":
|
| 180 |
-
"value":
|
| 181 |
-
"comparison_type":
|
| 182 |
})
|
| 183 |
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
"comparison_type": "equal"
|
| 206 |
-
})
|
| 207 |
-
|
| 208 |
-
for alcohol_value in encoded_alcohol_consumption:
|
| 209 |
-
if alcohol_value > 0:
|
| 210 |
-
requirements.append({
|
| 211 |
-
"column_name": "Alcohol_Consumption",
|
| 212 |
-
"value": alcohol_value,
|
| 213 |
-
"comparison_type": "equal"
|
| 214 |
-
})
|
| 215 |
-
|
| 216 |
-
for exercise_value in encoded_exercise_habits:
|
| 217 |
-
if exercise_value > 0:
|
| 218 |
-
requirements.append({
|
| 219 |
-
"column_name": "Exercise_Habits",
|
| 220 |
-
"value": exercise_value,
|
| 221 |
-
"comparison_type": "equal"
|
| 222 |
-
})
|
| 223 |
-
|
| 224 |
-
for diet_value in encoded_diet:
|
| 225 |
-
if diet_value > 0:
|
| 226 |
-
requirements.append({
|
| 227 |
-
"column_name": "Diet",
|
| 228 |
-
"value": diet_value,
|
| 229 |
-
"comparison_type": "equal"
|
| 230 |
-
})
|
| 231 |
-
|
| 232 |
-
for status in encoded_functional_status:
|
| 233 |
-
if status > 0:
|
| 234 |
-
requirements.append({
|
| 235 |
-
"column_name": "Functional_Status",
|
| 236 |
-
"value": status,
|
| 237 |
-
"comparison_type": "equal"
|
| 238 |
-
})
|
| 239 |
-
|
| 240 |
-
for participation in encoded_previous_trial_participation:
|
| 241 |
-
if participation > 0:
|
| 242 |
-
requirements.append({
|
| 243 |
-
"column_name": "Previous_Trial_Participation",
|
| 244 |
-
"value": participation,
|
| 245 |
-
"comparison_type": "equal"
|
| 246 |
-
})
|
| 247 |
-
|
| 248 |
-
# Encode and add non-categorical fields like medications, allergies, previous treatments
|
| 249 |
-
for medication in medications:
|
| 250 |
-
encoded_medications = encode_categorical_data([medication], "Medications")
|
| 251 |
-
for med_value in encoded_medications:
|
| 252 |
-
if med_value > 0:
|
| 253 |
-
requirements.append({
|
| 254 |
-
"column_name": "Medications",
|
| 255 |
-
"value": med_value,
|
| 256 |
-
"comparison_type": "equal"
|
| 257 |
-
})
|
| 258 |
-
|
| 259 |
-
for allergy in allergies:
|
| 260 |
-
encoded_allergies = encode_categorical_data([allergy], "Allergies")
|
| 261 |
-
for allergy_value in encoded_allergies:
|
| 262 |
-
if allergy_value > 0:
|
| 263 |
requirements.append({
|
| 264 |
-
"column_name":
|
| 265 |
-
"value":
|
| 266 |
-
"comparison_type":
|
| 267 |
})
|
|
|
|
|
|
|
| 268 |
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
for treatment_value in encoded_treatments:
|
| 272 |
-
if treatment_value > 0:
|
| 273 |
-
requirements.append({
|
| 274 |
-
"column_name": "Previous_Treatments",
|
| 275 |
-
"value": treatment_value,
|
| 276 |
-
"comparison_type": "equal"
|
| 277 |
-
})
|
| 278 |
|
| 279 |
# Construct the payload as a regular dictionary
|
| 280 |
payload = {
|
|
@@ -282,13 +191,7 @@ def process_researcher_data(
|
|
| 282 |
"requirements": requirements
|
| 283 |
}
|
| 284 |
|
| 285 |
-
|
| 286 |
-
payload = json.dumps(payload)
|
| 287 |
-
|
| 288 |
-
print("Payload:", payload)
|
| 289 |
-
|
| 290 |
-
# Store the server's URL
|
| 291 |
-
SERVER_URL = "https://ppaihack-match.azurewebsites.net/requirements/create"
|
| 292 |
|
| 293 |
# Make the request to the server
|
| 294 |
try:
|
|
@@ -311,7 +214,6 @@ def process_researcher_data(
|
|
| 311 |
|
| 312 |
return response.get("message", "No message received from server")
|
| 313 |
|
| 314 |
-
|
| 315 |
# Create the Gradio interface for researchers
|
| 316 |
researcher_demo = gr.Interface(
|
| 317 |
fn=process_researcher_data,
|
|
@@ -330,4 +232,4 @@ researcher_demo = gr.Interface(
|
|
| 330 |
|
| 331 |
# Launch the researcher interface with a public link
|
| 332 |
if __name__ == "__main__":
|
| 333 |
-
researcher_demo.launch(share=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
|
|
|
|
|
|
| 3 |
from typing import List
|
| 4 |
|
| 5 |
+
# Define the COLUMN_MIN_MAX as provided
|
| 6 |
+
COLUMN_MIN_MAX = {
|
| 7 |
+
"Age": (18, 100),
|
| 8 |
+
"Blood_Glucose_Level": (0, 3),
|
| 9 |
+
"Blood_Pressure_Systolic": (0, 3),
|
| 10 |
+
"Blood_Pressure_Diastolic": (0, 3),
|
| 11 |
+
"BMI": (0, 3),
|
| 12 |
+
"Condition_Severity": (0, 3),
|
| 13 |
+
"Gender": (0, 2),
|
| 14 |
+
"Ethnicity": (0, 5),
|
| 15 |
+
"Geographic_Location": (0, 6),
|
| 16 |
+
"Smoking_Status": (0, 2),
|
| 17 |
+
"Diagnoses_ICD10": (0, 5),
|
| 18 |
+
"Medications": (0, 7),
|
| 19 |
+
"Allergies": (0, 5),
|
| 20 |
+
"Previous_Treatments": (0, 5),
|
| 21 |
+
"Alcohol_Consumption": (0, 3),
|
| 22 |
+
"Exercise_Habits": (0, 4),
|
| 23 |
+
"Diet": (0, 5),
|
| 24 |
+
"Functional_Status": (0, 2),
|
| 25 |
+
"Previous_Trial_Participation": (0, 1),
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
# Define possible categories for fields without predefined categories
|
| 29 |
additional_categories = {
|
| 30 |
"Gender": ["Male", "Female", "Other"],
|
|
|
|
| 42 |
"Previous_Trial_Participation": ["Yes", "No"]
|
| 43 |
}
|
| 44 |
|
| 45 |
+
# Define the input components for the researcher form with constraints
|
| 46 |
+
min_age_input = gr.Number(label="Minimum Age", value=18, minimum=COLUMN_MIN_MAX["Age"][0], maximum=COLUMN_MIN_MAX["Age"][1])
|
| 47 |
+
max_age_input = gr.Number(label="Maximum Age", value=100, minimum=COLUMN_MIN_MAX["Age"][0], maximum=COLUMN_MIN_MAX["Age"][1])
|
| 48 |
+
|
| 49 |
gender_input = gr.CheckboxGroup(choices=additional_categories["Gender"], label="Gender")
|
| 50 |
ethnicity_input = gr.CheckboxGroup(choices=additional_categories["Ethnicity"], label="Ethnicity")
|
| 51 |
geographic_location_input = gr.CheckboxGroup(choices=additional_categories["Geographic_Location"], label="Geographic Location")
|
|
|
|
| 53 |
medications_input = gr.CheckboxGroup(choices=additional_categories["Medications"], label="Medications")
|
| 54 |
allergies_input = gr.CheckboxGroup(choices=additional_categories["Allergies"], label="Allergies")
|
| 55 |
previous_treatments_input = gr.CheckboxGroup(choices=additional_categories["Previous_Treatments"], label="Previous Treatments")
|
| 56 |
+
|
| 57 |
+
min_blood_glucose_level_input = gr.Number(label="Minimum Blood Glucose Level", value=0, minimum=COLUMN_MIN_MAX["Blood_Glucose_Level"][0], maximum=COLUMN_MIN_MAX["Blood_Glucose_Level"][1])
|
| 58 |
+
max_blood_glucose_level_input = gr.Number(label="Maximum Blood Glucose Level", value=3, minimum=COLUMN_MIN_MAX["Blood_Glucose_Level"][0], maximum=COLUMN_MIN_MAX["Blood_Glucose_Level"][1])
|
| 59 |
+
|
| 60 |
+
min_blood_pressure_systolic_input = gr.Number(label="Minimum Blood Pressure (Systolic)", value=0, minimum=COLUMN_MIN_MAX["Blood_Pressure_Systolic"][0], maximum=COLUMN_MIN_MAX["Blood_Pressure_Systolic"][1])
|
| 61 |
+
max_blood_pressure_systolic_input = gr.Number(label="Maximum Blood Pressure (Systolic)", value=3, minimum=COLUMN_MIN_MAX["Blood_Pressure_Systolic"][0], maximum=COLUMN_MIN_MAX["Blood_Pressure_Systolic"][1])
|
| 62 |
+
|
| 63 |
+
min_blood_pressure_diastolic_input = gr.Number(label="Minimum Blood Pressure (Diastolic)", value=0, minimum=COLUMN_MIN_MAX["Blood_Pressure_Diastolic"][0], maximum=COLUMN_MIN_MAX["Blood_Pressure_Diastolic"][1])
|
| 64 |
+
max_blood_pressure_diastolic_input = gr.Number(label="Maximum Blood Pressure (Diastolic)", value=3, minimum=COLUMN_MIN_MAX["Blood_Pressure_Diastolic"][0], maximum=COLUMN_MIN_MAX["Blood_Pressure_Diastolic"][1])
|
| 65 |
+
|
| 66 |
+
min_bmi_input = gr.Number(label="Minimum BMI", value=0, minimum=COLUMN_MIN_MAX["BMI"][0], maximum=COLUMN_MIN_MAX["BMI"][1])
|
| 67 |
+
max_bmi_input = gr.Number(label="Maximum BMI", value=3, minimum=COLUMN_MIN_MAX["BMI"][0], maximum=COLUMN_MIN_MAX["BMI"][1])
|
| 68 |
+
|
| 69 |
smoking_status_input = gr.CheckboxGroup(choices=additional_categories["Smoking_Status"], label="Smoking Status")
|
| 70 |
alcohol_consumption_input = gr.CheckboxGroup(choices=additional_categories["Alcohol_Consumption"], label="Alcohol Consumption")
|
| 71 |
exercise_habits_input = gr.CheckboxGroup(choices=additional_categories["Exercise_Habits"], label="Exercise Habits")
|
| 72 |
diet_input = gr.CheckboxGroup(choices=additional_categories["Diet"], label="Diet")
|
| 73 |
+
|
| 74 |
+
min_condition_severity_input = gr.Number(label="Minimum Condition Severity", value=0, minimum=COLUMN_MIN_MAX["Condition_Severity"][0], maximum=COLUMN_MIN_MAX["Condition_Severity"][1])
|
| 75 |
+
max_condition_severity_input = gr.Number(label="Maximum Condition Severity", value=3, minimum=COLUMN_MIN_MAX["Condition_Severity"][0], maximum=COLUMN_MIN_MAX["Condition_Severity"][1])
|
| 76 |
+
|
| 77 |
functional_status_input = gr.CheckboxGroup(choices=additional_categories["Functional_Status"], label="Functional Status")
|
| 78 |
previous_trial_participation_input = gr.CheckboxGroup(choices=additional_categories["Previous_Trial_Participation"], label="Previous Trial Participation")
|
| 79 |
|
| 80 |
+
# Define the server's URL
|
| 81 |
+
SERVER_URL = "http://127.0.0.1:7860/api/predict" # Ensure this is the correct endpoint
|
| 82 |
|
| 83 |
def encode_categorical_data(data: List[str], category_name: str) -> List[int]:
|
| 84 |
"""Encodes a list of categorical values into their corresponding indices based on additional_categories."""
|
|
|
|
| 86 |
encoded_data = []
|
| 87 |
for value in data:
|
| 88 |
if value in sub_cats:
|
| 89 |
+
encoded_index = sub_cats.index(value)
|
| 90 |
+
# Validate that the encoded index is within the specified range
|
| 91 |
+
min_val, max_val = COLUMN_MIN_MAX.get(category_name, (0, len(sub_cats)-1))
|
| 92 |
+
if min_val <= encoded_index <= max_val:
|
| 93 |
+
encoded_data.append(encoded_index)
|
| 94 |
+
else:
|
| 95 |
+
print(f"Encoded value for {category_name}='{value}' is out of range. Setting to 0.")
|
| 96 |
+
encoded_data.append(0)
|
| 97 |
else:
|
| 98 |
+
print(f"Value '{value}' not recognized in category '{category_name}'. Setting to 0.")
|
| 99 |
+
encoded_data.append(0)
|
| 100 |
return encoded_data
|
| 101 |
|
|
|
|
| 102 |
def process_researcher_data(
|
| 103 |
min_age, max_age, gender, ethnicity, geographic_location, diagnoses_icd10, medications, allergies, previous_treatments,
|
| 104 |
min_blood_glucose_level, max_blood_glucose_level, min_blood_pressure_systolic, max_blood_pressure_systolic,
|
|
|
|
| 110 |
encoded_ethnicity = encode_categorical_data(ethnicity, "Ethnicity")
|
| 111 |
encoded_geographic_location = encode_categorical_data(geographic_location, "Geographic_Location")
|
| 112 |
encoded_diagnoses_icd10 = encode_categorical_data(diagnoses_icd10, "Diagnoses_ICD10")
|
| 113 |
+
encoded_medications = encode_categorical_data(medications, "Medications")
|
| 114 |
+
encoded_allergies = encode_categorical_data(allergies, "Allergies")
|
| 115 |
+
encoded_previous_treatments = encode_categorical_data(previous_treatments, "Previous_Treatments")
|
| 116 |
encoded_smoking_status = encode_categorical_data(smoking_status, "Smoking_Status")
|
| 117 |
encoded_alcohol_consumption = encode_categorical_data(alcohol_consumption, "Alcohol_Consumption")
|
| 118 |
encoded_exercise_habits = encode_categorical_data(exercise_habits, "Exercise_Habits")
|
|
|
|
| 124 |
requirements = []
|
| 125 |
|
| 126 |
# Add numerical requirements
|
| 127 |
+
numerical_fields = [
|
| 128 |
+
("Age", min_age, "greater_than"),
|
| 129 |
+
("Age", max_age, "less_than"),
|
| 130 |
+
("Blood_Glucose_Level", min_blood_glucose_level, "greater_than"),
|
| 131 |
+
("Blood_Glucose_Level", max_blood_glucose_level, "less_than"),
|
| 132 |
+
("Blood_Pressure_Systolic", min_blood_pressure_systolic, "greater_than"),
|
| 133 |
+
("Blood_Pressure_Systolic", max_blood_pressure_systolic, "less_than"),
|
| 134 |
+
("Blood_Pressure_Diastolic", min_blood_pressure_diastolic, "greater_than"),
|
| 135 |
+
("Blood_Pressure_Diastolic", max_blood_pressure_diastolic, "less_than"),
|
| 136 |
+
("BMI", min_bmi, "greater_than"),
|
| 137 |
+
("BMI", max_bmi, "less_than"),
|
| 138 |
+
("Condition_Severity", min_condition_severity, "greater_than"),
|
| 139 |
+
("Condition_Severity", max_condition_severity, "less_than"),
|
| 140 |
+
]
|
| 141 |
+
|
| 142 |
+
for field, value, comparison in numerical_fields:
|
| 143 |
+
if value is not None:
|
| 144 |
+
# Ensure the value is within the specified range
|
| 145 |
+
min_val, max_val = COLUMN_MIN_MAX.get(field, (None, None))
|
| 146 |
+
if min_val is not None and max_val is not None:
|
| 147 |
+
if not (min_val <= value <= max_val):
|
| 148 |
+
print(f"Value for {field}={value} is out of range ({min_val}, {max_val}). Adjusting to fit within range.")
|
| 149 |
+
value = max(min(value, max_val), min_val)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
requirements.append({
|
| 151 |
+
"column_name": field,
|
| 152 |
+
"value": value,
|
| 153 |
+
"comparison_type": comparison
|
| 154 |
})
|
| 155 |
|
| 156 |
+
# Add categorical requirements
|
| 157 |
+
categorical_fields = [
|
| 158 |
+
("Gender", encoded_gender, "equal"),
|
| 159 |
+
("Ethnicity", encoded_ethnicity, "equal"),
|
| 160 |
+
("Geographic_Location", encoded_geographic_location, "equal"),
|
| 161 |
+
("Diagnoses_ICD10", encoded_diagnoses_icd10, "equal"),
|
| 162 |
+
("Medications", encoded_medications, "equal"),
|
| 163 |
+
("Allergies", encoded_allergies, "equal"),
|
| 164 |
+
("Previous_Treatments", encoded_previous_treatments, "equal"),
|
| 165 |
+
("Smoking_Status", encoded_smoking_status, "equal"),
|
| 166 |
+
("Alcohol_Consumption", encoded_alcohol_consumption, "equal"),
|
| 167 |
+
("Exercise_Habits", encoded_exercise_habits, "equal"),
|
| 168 |
+
("Diet", encoded_diet, "equal"),
|
| 169 |
+
("Functional_Status", encoded_functional_status, "equal"),
|
| 170 |
+
("Previous_Trial_Participation", encoded_previous_trial_participation, "equal"),
|
| 171 |
+
]
|
| 172 |
+
|
| 173 |
+
for field, encoded_values, comparison in categorical_fields:
|
| 174 |
+
min_val, max_val = COLUMN_MIN_MAX.get(field, (0, len(additional_categories[field])-1))
|
| 175 |
+
for encoded in encoded_values:
|
| 176 |
+
if min_val <= encoded <= max_val:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 177 |
requirements.append({
|
| 178 |
+
"column_name": field,
|
| 179 |
+
"value": encoded,
|
| 180 |
+
"comparison_type": comparison
|
| 181 |
})
|
| 182 |
+
else:
|
| 183 |
+
print(f"Encoded value {encoded} for {field} is out of range ({min_val}, {max_val}). Skipping.")
|
| 184 |
|
| 185 |
+
# Encode and add non-categorical fields like medications, allergies, previous treatments
|
| 186 |
+
# Already handled above in categorical_fields
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 187 |
|
| 188 |
# Construct the payload as a regular dictionary
|
| 189 |
payload = {
|
|
|
|
| 191 |
"requirements": requirements
|
| 192 |
}
|
| 193 |
|
| 194 |
+
print("Payload to send:", payload) # For debugging
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 195 |
|
| 196 |
# Make the request to the server
|
| 197 |
try:
|
|
|
|
| 214 |
|
| 215 |
return response.get("message", "No message received from server")
|
| 216 |
|
|
|
|
| 217 |
# Create the Gradio interface for researchers
|
| 218 |
researcher_demo = gr.Interface(
|
| 219 |
fn=process_researcher_data,
|
|
|
|
| 232 |
|
| 233 |
# Launch the researcher interface with a public link
|
| 234 |
if __name__ == "__main__":
|
| 235 |
+
researcher_demo.launch(share=True)
|