Spaces:
Runtime error
Runtime error
Adding checkbox for male and female inputs
Browse files- predict.py +8 -8
predict.py
CHANGED
@@ -27,16 +27,21 @@ transform = A.Compose([
|
|
27 |
|
28 |
|
29 |
def predict(image, gender):
|
|
|
|
|
|
|
|
|
|
|
30 |
model = initialize_model()
|
31 |
|
32 |
processed_image = transform(image=np.array(image, dtype=np.uint8))['image']
|
33 |
processed_image = processed_image.unsqueeze(0)
|
34 |
processed_image = processed_image.to(device)
|
35 |
-
|
36 |
|
37 |
scans = {
|
38 |
'image': processed_image,
|
39 |
-
'gender':
|
40 |
}
|
41 |
preds = model(scans)
|
42 |
return int(preds)
|
@@ -47,14 +52,9 @@ def run():
|
|
47 |
gender_input = gr.Checkbox(label="Is Female?", info="Is the scan of a female?", default=True),
|
48 |
output = gr.outputs.Textbox(label="Predicted Age")
|
49 |
|
50 |
-
if gender_input:
|
51 |
-
is_female = 1
|
52 |
-
else:
|
53 |
-
is_female = 0
|
54 |
-
|
55 |
BAE = gr.Interface(
|
56 |
fn=predict,
|
57 |
-
inputs=[image_input,
|
58 |
outputs=output,
|
59 |
)
|
60 |
|
|
|
27 |
|
28 |
|
29 |
def predict(image, gender):
|
30 |
+
if gender:
|
31 |
+
is_female = 1
|
32 |
+
else:
|
33 |
+
is_female = 0
|
34 |
+
|
35 |
model = initialize_model()
|
36 |
|
37 |
processed_image = transform(image=np.array(image, dtype=np.uint8))['image']
|
38 |
processed_image = processed_image.unsqueeze(0)
|
39 |
processed_image = processed_image.to(device)
|
40 |
+
is_female = torch.tensor(is_female).unsqueeze(0).unsqueeze(1).to(device)
|
41 |
|
42 |
scans = {
|
43 |
'image': processed_image,
|
44 |
+
'gender': is_female
|
45 |
}
|
46 |
preds = model(scans)
|
47 |
return int(preds)
|
|
|
52 |
gender_input = gr.Checkbox(label="Is Female?", info="Is the scan of a female?", default=True),
|
53 |
output = gr.outputs.Textbox(label="Predicted Age")
|
54 |
|
|
|
|
|
|
|
|
|
|
|
55 |
BAE = gr.Interface(
|
56 |
fn=predict,
|
57 |
+
inputs=[image_input, gender_input],
|
58 |
outputs=output,
|
59 |
)
|
60 |
|