Spaces:
Sleeping
Sleeping
Commit
·
60b84fb
1
Parent(s):
ec0bd2d
Update app.py
Browse files
app.py
CHANGED
@@ -2,46 +2,36 @@ from fastapi import FastAPI
|
|
2 |
from transformers import pipeline
|
3 |
app = FastAPI(docs_url="/")
|
4 |
@app.get("/calculate-human-years")
|
5 |
-
def calculate_human_years_endpoint(
|
6 |
size_to_years = {
|
7 |
-
"
|
8 |
1: 15, 2: 24, 3: 28, 4: 32, 5: 36, 6: 40,
|
9 |
7: 44, 8: 48, 9: 52, 10: 56, 11: 60, 12: 64
|
10 |
},
|
11 |
-
"
|
12 |
1: 15, 2: 24, 3: 28, 4: 32, 5: 36, 6: 42,
|
13 |
7: 47, 8: 51, 9: 56, 10: 60, 11: 65, 12: 69
|
14 |
},
|
15 |
-
"
|
16 |
1: 15, 2: 24, 3: 28, 4: 32, 5: 36, 6: 45,
|
17 |
7: 50, 8: 55, 9: 61, 10: 66, 11: 72, 12: 77
|
18 |
},
|
19 |
-
"
|
20 |
1: 15, 2: 22, 3: 28, 4: 31, 5: 36, 6: 45,
|
21 |
7: 49, 8: 55, 9: 61, 10: 66, 11: 72, 12: 77
|
22 |
}
|
23 |
}
|
24 |
|
25 |
-
if
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
|
|
30 |
else:
|
31 |
-
|
32 |
-
|
33 |
-
if weight is None or dogyears is None:
|
34 |
-
return {"error": "Please provide both activity level and weight."}
|
35 |
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
result = calculate_human_years("Medium",dogyears)
|
41 |
-
elif weight > 50 and weight < 101 :
|
42 |
-
result = calculate_human_years("Large",dogyears)
|
43 |
-
else :
|
44 |
-
result = calculate_human_years("Giant",dogyears)
|
45 |
-
|
46 |
-
# Respond with the result as JSON.
|
47 |
-
return result
|
|
|
2 |
from transformers import pipeline
|
3 |
app = FastAPI(docs_url="/")
|
4 |
@app.get("/calculate-human-years")
|
5 |
+
def calculate_human_years_endpoint(weight: int, dogyears: int):
|
6 |
size_to_years = {
|
7 |
+
"Less than 20": {
|
8 |
1: 15, 2: 24, 3: 28, 4: 32, 5: 36, 6: 40,
|
9 |
7: 44, 8: 48, 9: 52, 10: 56, 11: 60, 12: 64
|
10 |
},
|
11 |
+
"20 to 50": {
|
12 |
1: 15, 2: 24, 3: 28, 4: 32, 5: 36, 6: 42,
|
13 |
7: 47, 8: 51, 9: 56, 10: 60, 11: 65, 12: 69
|
14 |
},
|
15 |
+
"50 to 100": {
|
16 |
1: 15, 2: 24, 3: 28, 4: 32, 5: 36, 6: 45,
|
17 |
7: 50, 8: 55, 9: 61, 10: 66, 11: 72, 12: 77
|
18 |
},
|
19 |
+
"Above 100": {
|
20 |
1: 15, 2: 22, 3: 28, 4: 31, 5: 36, 6: 45,
|
21 |
7: 49, 8: 55, 9: 61, 10: 66, 11: 72, 12: 77
|
22 |
}
|
23 |
}
|
24 |
|
25 |
+
if weight < 20:
|
26 |
+
category = "Less than 20"
|
27 |
+
elif 20 <= weight <= 50:
|
28 |
+
category = "20 to 50"
|
29 |
+
elif 50 < weight <= 100:
|
30 |
+
category = "50 to 100"
|
31 |
else:
|
32 |
+
category = "Above 100"
|
|
|
|
|
|
|
33 |
|
34 |
+
if dogyears in size_to_years[category]:
|
35 |
+
return size_to_years[category][dogyears]
|
36 |
+
else:
|
37 |
+
return 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|