Spaces:
Building
on
CPU Upgrade
Building
on
CPU Upgrade
feat: change form
Browse files
app.py
CHANGED
@@ -3,6 +3,8 @@ import numpy as np
|
|
3 |
import gradio as gr
|
4 |
import requests
|
5 |
import json
|
|
|
|
|
6 |
|
7 |
# Store the server's URL
|
8 |
SERVER_URL = "https://ppaihack-match.azurewebsites.net/"
|
@@ -25,7 +27,7 @@ additional_categories = {
|
|
25 |
"Ethnicity": ["White", "Black or African American", "Asian", "American Indian or Alaska Native", "Native Hawaiian or Other Pacific Islander", "Other"],
|
26 |
"Geographic_Location": ["North America", "South America", "Europe", "Asia", "Africa", "Australia", "Antarctica"],
|
27 |
"Smoking_Status": ["Never", "Former", "Current"],
|
28 |
-
"Diagnoses_ICD10": ["
|
29 |
"Medications": ["Metformin", "Lisinopril", "Atorvastatin", "Amlodipine", "Omeprazole", "Simvastatin", "Levothyroxine", "None"],
|
30 |
"Allergies": ["Penicillin", "Peanuts", "Shellfish", "Latex", "Bee stings", "None"],
|
31 |
"Previous_Treatments": ["Chemotherapy", "Radiation Therapy", "Surgery", "Physical Therapy", "Immunotherapy", "None"],
|
@@ -41,7 +43,6 @@ age_input = gr.Slider(minimum=18, maximum=100, label="Age ", step=1)
|
|
41 |
gender_input = gr.Radio(choices=additional_categories["Gender"], label="Gender")
|
42 |
ethnicity_input = gr.Radio(choices=additional_categories["Ethnicity"], label="Ethnicity")
|
43 |
geographic_location_input = gr.Radio(choices=additional_categories["Geographic_Location"], label="Geographic Location")
|
44 |
-
diagnoses_icd10_input = gr.CheckboxGroup(choices=additional_categories["Diagnoses_ICD10"], label="Diagnoses (ICD-10)")
|
45 |
medications_input = gr.CheckboxGroup(choices=additional_categories["Medications"], label="Medications")
|
46 |
allergies_input = gr.CheckboxGroup(choices=additional_categories["Allergies"], label="Allergies")
|
47 |
previous_treatments_input = gr.CheckboxGroup(choices=additional_categories["Previous_Treatments"], label="Previous Treatments")
|
@@ -213,17 +214,54 @@ def process_patient_data(age, gender, ethnicity, geographic_location, diagnoses_
|
|
213 |
# f"Encrypted data: {encrypted_array}",
|
214 |
f"Decrypted result: {response.json()}"
|
215 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
216 |
|
217 |
# Create the Gradio interface
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
227 |
|
228 |
# Launch the app
|
229 |
demo.launch()
|
|
|
3 |
import gradio as gr
|
4 |
import requests
|
5 |
import json
|
6 |
+
from transformers import ViTImageProcessor, ViTModel
|
7 |
+
from PIL import Image
|
8 |
|
9 |
# Store the server's URL
|
10 |
SERVER_URL = "https://ppaihack-match.azurewebsites.net/"
|
|
|
27 |
"Ethnicity": ["White", "Black or African American", "Asian", "American Indian or Alaska Native", "Native Hawaiian or Other Pacific Islander", "Other"],
|
28 |
"Geographic_Location": ["North America", "South America", "Europe", "Asia", "Africa", "Australia", "Antarctica"],
|
29 |
"Smoking_Status": ["Never", "Former", "Current"],
|
30 |
+
"Diagnoses_ICD10": ["Actinic keratosis", "Melanoma", "Dermatofibroma", "Vascular lesion","None"],
|
31 |
"Medications": ["Metformin", "Lisinopril", "Atorvastatin", "Amlodipine", "Omeprazole", "Simvastatin", "Levothyroxine", "None"],
|
32 |
"Allergies": ["Penicillin", "Peanuts", "Shellfish", "Latex", "Bee stings", "None"],
|
33 |
"Previous_Treatments": ["Chemotherapy", "Radiation Therapy", "Surgery", "Physical Therapy", "Immunotherapy", "None"],
|
|
|
43 |
gender_input = gr.Radio(choices=additional_categories["Gender"], label="Gender")
|
44 |
ethnicity_input = gr.Radio(choices=additional_categories["Ethnicity"], label="Ethnicity")
|
45 |
geographic_location_input = gr.Radio(choices=additional_categories["Geographic_Location"], label="Geographic Location")
|
|
|
46 |
medications_input = gr.CheckboxGroup(choices=additional_categories["Medications"], label="Medications")
|
47 |
allergies_input = gr.CheckboxGroup(choices=additional_categories["Allergies"], label="Allergies")
|
48 |
previous_treatments_input = gr.CheckboxGroup(choices=additional_categories["Previous_Treatments"], label="Previous Treatments")
|
|
|
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'
|
220 |
+
image = Image.open(requests.get(url, stream=True).raw)
|
221 |
+
|
222 |
+
processor = ViTImageProcessor.from_pretrained('google/vit-base-patch16-224-in21k')
|
223 |
+
model = ViTModel.from_pretrained('google/vit-base-patch16-224-in21k')
|
224 |
+
inputs = processor(images=image, return_tensors="pt")
|
225 |
+
|
226 |
+
outputs = model(**inputs)
|
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
|
233 |
+
with gr.Blocks() as demo:
|
234 |
+
gr.Markdown("# Patient Data Criteria Form\nPlease fill in the criteria for the type of patients you are looking for.")
|
235 |
+
with gr.Column():
|
236 |
+
with gr.Group():
|
237 |
+
age_input.render()
|
238 |
+
gender_input.render()
|
239 |
+
ethnicity_input.render()
|
240 |
+
geographic_location_input.render()
|
241 |
+
medications_input.render()
|
242 |
+
allergies_input.render()
|
243 |
+
previous_treatments_input.render()
|
244 |
+
blood_glucose_level_input.render()
|
245 |
+
blood_pressure_systolic_input.render()
|
246 |
+
blood_pressure_diastolic_input.render()
|
247 |
+
bmi_input.render()
|
248 |
+
smoking_status_input.render()
|
249 |
+
alcohol_consumption_input.render()
|
250 |
+
exercise_habits_input.render()
|
251 |
+
diet_input.render()
|
252 |
+
condition_severity_input.render()
|
253 |
+
functional_status_input.render()
|
254 |
+
previous_trial_participation_input.render()
|
255 |
+
with gr.Group():
|
256 |
+
diagnoses_icd10_input = gr.CheckboxGroup(choices=additional_categories["Diagnoses_ICD10"], label="Skin Diagnosis", interactive=False)
|
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)
|
264 |
+
|
265 |
|
266 |
# Launch the app
|
267 |
demo.launch()
|