File size: 1,656 Bytes
48ed33d
 
d7b722e
 
 
 
 
 
 
 
 
b3745ee
48ed33d
b3745ee
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48ed33d
b3745ee
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from fastapi import FastAPI
from transformers import pipeline


# NOTE - we configure docs_url to serve the interactive Docs at the root path
# of the app. This way, we can use the docs as a landing page for the app on Spaces.
app = FastAPI(docs_url="/")

pipe = pipeline("text2text-generation", model="google/flan-t5-small")


def calculate_food(activity, weight):
    """
    Calculates the recommended amount of dog food based on activity level and weight.

    Args:
        activity: The dog's activity level, as a number from 1 to 5.
        weight: The dog's weight in kilograms.

    Returns:
        A dictionary containing the recommended amount of food in cups.
    """

    # Calculate the resting energy requirement (RER).
    rer = 70 * weight ** 0.75

    # Multiply the RER by the appropriate factor to account for the dog's activity level.
    activity_factor = {
        1: 1.2,
        2: 1.4,
        3: 1.6,
        4: 1.8,
        5: 2.0,
    }
    recommended_food = rer * activity_factor[activity] / weight

    return {"recommendedFood": round(recommended_food, 2)}


@app.get("/calculate-food")
def calculate_food_endpoint(activity: int, weight: int):
    """
    Calculates the recommended amount of dog food based on activity level and weight.

    Args:
        activity: The dog's activity level, as a number from 1 to 5.
        weight: The dog's weight in kilograms.

    Returns:
        A JSON object containing the recommended amount of food in cups.
    """

    result = calculate_food(activity, weight)
    return result


if __name__ == "__main__":
    import uvicorn

    uvicorn.run(app, host="0.0.0.0", port=8000)