AnishKumbhar commited on
Commit
2c5f9f9
1 Parent(s): b3745ee

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -45
app.py CHANGED
@@ -1,42 +1,3 @@
1
- from fastapi import FastAPI
2
- from transformers import pipeline
3
-
4
-
5
- # NOTE - we configure docs_url to serve the interactive Docs at the root path
6
- # of the app. This way, we can use the docs as a landing page for the app on Spaces.
7
- app = FastAPI(docs_url="/")
8
-
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
  """
@@ -50,11 +11,12 @@ def calculate_food_endpoint(activity: int, weight: int):
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)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  @app.get("/calculate-food")
2
  def calculate_food_endpoint(activity: int, weight: int):
3
  """
 
11
  A JSON object containing the recommended amount of food in cups.
12
  """
13
 
14
+ # Check if the activity and weight parameters are present in the API request.
15
+ if activity is None or weight is None:
16
+ return {"error": "Please provide both activity level and weight."}
17
 
18
+ # Calculate the recommended amount of food.
19
+ result = calculate_food(activity, weight)
20
 
21
+ # Respond with the result as JSON.
22
+ return result