AnishKumbhar commited on
Commit
60b84fb
1 Parent(s): ec0bd2d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -26
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(size: str, dogyears: int):
6
  size_to_years = {
7
- "Small": {
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
- "Medium": {
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
- "Large": {
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
- "Giant": {
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 size in size_to_years:
26
- if weight in size_to_years[size]:
27
- return size_to_years[size][weight]
28
- else:
29
- return 0 # Weight not in the table, return 0 as an error code
 
30
  else:
31
- return 0
32
-
33
- if weight is None or dogyears is None:
34
- return {"error": "Please provide both activity level and weight."}
35
 
36
- # Calculate the recommended amount of food.
37
- if weight < 21 :
38
- result = calculate_human_years("Small", dogyears)
39
- elif weight > 20 and weight < 51 :
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