AnishKumbhar commited on
Commit
b1a78e8
·
1 Parent(s): 5c04eb1

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -0
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 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 && weight < 51 :
40
+ result = calculate_human_years("Medium",dogyears)
41
+ elif weight > 50 && 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