TomSmail commited on
Commit
a7455e5
·
1 Parent(s): a504a58

fix: that god damn bug

Browse files
Files changed (1) hide show
  1. app.py +31 -18
app.py CHANGED
@@ -56,7 +56,7 @@ exercise_habits_input = gr.Radio(choices=additional_categories["Exercise_Habits"
56
  diet_input = gr.Radio(choices=additional_categories["Diet"], label="Diet", value="Omnivore")
57
  condition_severity_input = gr.Slider(minimum=1, maximum=10, label="Condition Severity", step=1, value=5)
58
  functional_status_input = gr.Radio(choices=additional_categories["Functional_Status"], label="Functional Status", value="Independent")
59
- previous_trial_participation_input = gr.Radio(choices=additional_categories["Previous_Trial_Participation"], label="Previous Trial Participation", value="No")
60
 
61
 
62
  # def encrypt_array(user_symptoms: np.ndarray, user_id: str) -> bytes:
@@ -132,7 +132,7 @@ def encode_categorical_data(data):
132
  def clear_data_to_json(data):
133
  print(data)
134
  patient_data = {
135
- "model_names": ["my_model"],
136
  "patient": {
137
  "Age": data.get("age", 30),
138
  "Blood_Glucose_Level": data.get("blood_glucose_level", 0),
@@ -155,7 +155,7 @@ def clear_data_to_json(data):
155
  "Previous_Trial_Participation": data.get("Previous_Trial_Participation", 0)
156
  }
157
  }
158
- return json.dumps(patient_data, indent=4)
159
 
160
 
161
  def process_patient_data(age, gender, ethnicity, geographic_location, diagnoses_icd10, medications, allergies, previous_treatments, blood_glucose_level, blood_pressure_systolic, blood_pressure_diastolic, bmi, smoking_status, alcohol_consumption, exercise_habits, diet, condition_severity, functional_status, previous_trial_participation):
@@ -190,30 +190,42 @@ def process_patient_data(age, gender, ethnicity, geographic_location, diagnoses_
190
  # encrypted_array = encrypt_array(combined_data, "user_id")
191
 
192
  # Send the data to the server
193
- url = SERVER_URL + "clear-match"
194
- response = requests.post(url, data=json_data)
 
195
 
196
  # Check if the data was sent successfully
197
  if response.status_code == 200:
198
  print("Data sent successfully.")
199
  else:
200
- print("Error sending data.")
201
 
 
202
  # Decrypt the result
203
  # decrypted_result = decrypt_result(response.content, USER_ID)
204
- print()
205
- decrypted_result = response.json()
206
- # If the answer is True, return the link
 
 
 
 
 
 
 
 
 
 
 
 
 
 
207
  if decrypted_result:
208
- return (
209
- # f"Encrypted data: {encrypted_array}",
210
- f"Decrypted result: {response.json()}"
211
- )
212
  else:
213
- return (
214
- # f"Encrypted data: {encrypted_array}",
215
- f"Decrypted result: {response.json()}"
216
- )
217
  # Define the function to handle image upload
218
  def handle_image_upload(image):
219
  url = 'http://images.cocodataset.org/val2017/000000039769.jpg'
@@ -227,6 +239,7 @@ def handle_image_upload(image):
227
  pooler_output = outputs.pooler_output[0]
228
  sclaed_output = 127 + 127 * pooler_output / pooler_output.abs().max()
229
  sclaed_output = sclaed_output.to(int)
 
230
  return ["Melanoma", "Vascular lesion"]
231
 
232
  # Create the Gradio interface
@@ -257,7 +270,7 @@ with gr.Blocks() as demo:
257
  image_input = gr.Image(label="Upload an Image")
258
  gr.Button("Upload").click(handle_image_upload, inputs=image_input, outputs=diagnoses_icd10_input)
259
  with gr.Group():
260
- output = gr.JSON(label="Patient Data JSON")
261
  gr.Button("Submit").click(process_patient_data, inputs=[
262
  age_input, gender_input, ethnicity_input, geographic_location_input, diagnoses_icd10_input, medications_input, allergies_input, previous_treatments_input, blood_glucose_level_input, blood_pressure_systolic_input, blood_pressure_diastolic_input, bmi_input, smoking_status_input, alcohol_consumption_input, exercise_habits_input, diet_input, condition_severity_input, functional_status_input, previous_trial_participation_input
263
  ], outputs=output)
 
56
  diet_input = gr.Radio(choices=additional_categories["Diet"], label="Diet", value="Omnivore")
57
  condition_severity_input = gr.Slider(minimum=1, maximum=10, label="Condition Severity", step=1, value=5)
58
  functional_status_input = gr.Radio(choices=additional_categories["Functional_Status"], label="Functional Status", value="Independent")
59
+ previous_trial_participation_input = gr.Radio(choices=additional_categories["Previous_Trial_Participation"], label="Previous Trial Participation", value="Yes")
60
 
61
 
62
  # def encrypt_array(user_symptoms: np.ndarray, user_id: str) -> bytes:
 
132
  def clear_data_to_json(data):
133
  print(data)
134
  patient_data = {
135
+ "model_names": ["second_model"],
136
  "patient": {
137
  "Age": data.get("age", 30),
138
  "Blood_Glucose_Level": data.get("blood_glucose_level", 0),
 
155
  "Previous_Trial_Participation": data.get("Previous_Trial_Participation", 0)
156
  }
157
  }
158
+ return patient_data
159
 
160
 
161
  def process_patient_data(age, gender, ethnicity, geographic_location, diagnoses_icd10, medications, allergies, previous_treatments, blood_glucose_level, blood_pressure_systolic, blood_pressure_diastolic, bmi, smoking_status, alcohol_consumption, exercise_habits, diet, condition_severity, functional_status, previous_trial_participation):
 
190
  # encrypted_array = encrypt_array(combined_data, "user_id")
191
 
192
  # Send the data to the server
193
+ url = SERVER_URL + "inference/clear-match"
194
+ headers = {"Content-Type": "application/json", "X-API-KEY": "secret"}
195
+ response = requests.post(url, data=json_data, headers=headers)
196
 
197
  # Check if the data was sent successfully
198
  if response.status_code == 200:
199
  print("Data sent successfully.")
200
  else:
201
+ print(f"Error sending data. Status code: {response.status_code}")
202
 
203
+ # return f"**[Possible Trial Link]({EXAMPLE_CLINICAL_TRIAL_LINK})**"
204
  # Decrypt the result
205
  # decrypted_result = decrypt_result(response.content, USER_ID)
206
+ # decrypted_result = None
207
+ try:
208
+ decrypted_result = response.json()
209
+ print(f"Decrypted result: {decrypted_result}")
210
+ except json.JSONDecodeError as e:
211
+ print(f"Error decrypting result: Invalid JSON. {e}")
212
+ decrypted_result = False
213
+ return "There was an error processing the data."
214
+ except Exception as e:
215
+ print(f"An error occurred: {e}")
216
+ decrypted_result = False
217
+ return "There was an error processing the data."
218
+ else:
219
+ print("Json parsed successfully.")
220
+
221
+
222
+ # If the answer is True, return the link
223
  if decrypted_result:
224
+ return f"**[Possible Trial Link]({EXAMPLE_CLINICAL_TRIAL_LINK})**"
 
 
 
225
  else:
226
+ return "There was an error processing the data."
227
+
228
+
 
229
  # Define the function to handle image upload
230
  def handle_image_upload(image):
231
  url = 'http://images.cocodataset.org/val2017/000000039769.jpg'
 
239
  pooler_output = outputs.pooler_output[0]
240
  sclaed_output = 127 + 127 * pooler_output / pooler_output.abs().max()
241
  sclaed_output = sclaed_output.to(int)
242
+ url = "/inference/clear-diagnosis"
243
  return ["Melanoma", "Vascular lesion"]
244
 
245
  # Create the Gradio interface
 
270
  image_input = gr.Image(label="Upload an Image")
271
  gr.Button("Upload").click(handle_image_upload, inputs=image_input, outputs=diagnoses_icd10_input)
272
  with gr.Group():
273
+ output = gr.Markdown("**Server response**")
274
  gr.Button("Submit").click(process_patient_data, inputs=[
275
  age_input, gender_input, ethnicity_input, geographic_location_input, diagnoses_icd10_input, medications_input, allergies_input, previous_treatments_input, blood_glucose_level_input, blood_pressure_systolic_input, blood_pressure_diastolic_input, bmi_input, smoking_status_input, alcohol_consumption_input, exercise_habits_input, diet_input, condition_severity_input, functional_status_input, previous_trial_participation_input
276
  ], outputs=output)