File size: 840 Bytes
c906ee7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import json

def calculate_food(activity, weight):
  if activity and weight:
    calculated_amount = round(activity / weight, 2)
    return {"recommendedFood": calculated_amount}
  else:
    return {"error": "Please provide both activity level and weight."}

# Define Streamlit app as a function
def app():
  # Parse JSON data from the POST request
  try:
    data = st.json_request()
    activity = data.get("activity")
    weight = data.get("weight")
    print("Activity and data recieved")
  except:
    st.json({"error": "Invalid JSON data"})
    return
   
  # Calculate recommended food
  result = calculate_food(activity, weight)
   
  # Respond with the result as JSON
  st.json(result)

# Run the Streamlit app
if __name__ == "__main__":
  app()