AnishKumbhar commited on
Commit
b3745ee
1 Parent(s): 65743b0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -7
app.py CHANGED
@@ -9,12 +9,52 @@ app = FastAPI(docs_url="/")
9
  pipe = pipeline("text2text-generation", model="google/flan-t5-small")
10
 
11
 
12
- @app.get("/generate")
13
- def generate(text: str):
14
  """
15
- Using the text2text-generation pipeline from `transformers`, generate text
16
- from the given input text. The model used is `google/flan-t5-small`, which
17
- can be found [here](https://huggingface.co/google/flan-t5-small).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  """
19
- output = pipe(text)
20
- return {"output": output[0]["generated_text"]}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  pipe = pipeline("text2text-generation", model="google/flan-t5-small")
10
 
11
 
12
+ def calculate_food(activity, weight):
 
13
  """
14
+ Calculates the recommended amount of dog food based on activity level and weight.
15
+
16
+ Args:
17
+ activity: The dog's activity level, as a number from 1 to 5.
18
+ weight: The dog's weight in kilograms.
19
+
20
+ Returns:
21
+ A dictionary containing the recommended amount of food in cups.
22
+ """
23
+
24
+ # Calculate the resting energy requirement (RER).
25
+ rer = 70 * weight ** 0.75
26
+
27
+ # Multiply the RER by the appropriate factor to account for the dog's activity level.
28
+ activity_factor = {
29
+ 1: 1.2,
30
+ 2: 1.4,
31
+ 3: 1.6,
32
+ 4: 1.8,
33
+ 5: 2.0,
34
+ }
35
+ recommended_food = rer * activity_factor[activity] / weight
36
+
37
+ return {"recommendedFood": round(recommended_food, 2)}
38
+
39
+
40
+ @app.get("/calculate-food")
41
+ def calculate_food_endpoint(activity: int, weight: int):
42
  """
43
+ Calculates the recommended amount of dog food based on activity level and weight.
44
+
45
+ Args:
46
+ activity: The dog's activity level, as a number from 1 to 5.
47
+ weight: The dog's weight in kilograms.
48
+
49
+ Returns:
50
+ A JSON object containing the recommended amount of food in cups.
51
+ """
52
+
53
+ result = calculate_food(activity, weight)
54
+ return result
55
+
56
+
57
+ if __name__ == "__main__":
58
+ import uvicorn
59
+
60
+ uvicorn.run(app, host="0.0.0.0", port=8000)