Spaces:
Sleeping
Sleeping
File size: 1,400 Bytes
a5519f2 d637e6d b3745ee 146278f 4c5cb7a 146278f 4c5cb7a 146278f 4c5cb7a 146278f 4c5cb7a 146278f 4c5cb7a 146278f 4c5cb7a 146278f 4c5cb7a 146278f 3d04546 146278f 48ed33d b3745ee 2c5f9f9 b3745ee 2c5f9f9 b3745ee 2c5f9f9 |
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 |
from fastapi import FastAPI
from transformers import pipeline
app = FastAPI(docs_url="/")
@app.get("/calculate-food")
def calculate_food_endpoint(activity: str, weight: int):
score = 0
if activity == "Typical" :
score = 110
elif activity == "Active" :
score = 125
elif activity == "Overweight" :
score = 70
elif activity == "Highly Active" :
score = 175
elif activity == "Senior, neutered, inactive" :
score = 90
elif activity == "Working Dog (light duty)" :
score = 130
elif activity == "Working Dog (moderate duty)" :
score = 150
elif activity == "Working Dog (heavy duty)" :
score = 175
else :
score = 110
return round( score / weight, 2)
"""
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.
"""
# Check if the activity and weight parameters are present in the API request.
if activity is None or weight is None:
return {"error": "Please provide both activity level and weight."}
# Calculate the recommended amount of food.
result = calculate_food(activity, weight)
# Respond with the result as JSON.
return result |