Modify string output
Browse files
app.py
CHANGED
|
@@ -71,7 +71,22 @@ def predict_bone_age(Radiograph, Sex):
|
|
| 71 |
img = torch.cat([img, torch.zeros_like(img) - 1], dim=1)
|
| 72 |
with torch.no_grad():
|
| 73 |
bone_age = ensemble(img.float())[0].item()
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
|
| 77 |
image = gr.Image(shape=(512, 512), image_mode="L")
|
|
|
|
| 71 |
img = torch.cat([img, torch.zeros_like(img) - 1], dim=1)
|
| 72 |
with torch.no_grad():
|
| 73 |
bone_age = ensemble(img.float())[0].item()
|
| 74 |
+
total_months = bone_age * 12
|
| 75 |
+
years = total_months // 12
|
| 76 |
+
months = total_months - years * 12
|
| 77 |
+
months = round(months)
|
| 78 |
+
if months == 12:
|
| 79 |
+
years += 1
|
| 80 |
+
months = 0
|
| 81 |
+
if years == 0:
|
| 82 |
+
str_output = f"{months} months" if months != 1 else "1 month"
|
| 83 |
+
else:
|
| 84 |
+
months = round(months)
|
| 85 |
+
if months == 0:
|
| 86 |
+
str_output = f"{years} years" if years != 1 else "1 year"
|
| 87 |
+
else:
|
| 88 |
+
str_output = f"{years} years, {months} months" if months != 1 else f"{years} years, 1 month"
|
| 89 |
+
return f"Estimated Bone Age: {str_output}"
|
| 90 |
|
| 91 |
|
| 92 |
image = gr.Image(shape=(512, 512), image_mode="L")
|