AnishKumbhar commited on
Commit
c906ee7
1 Parent(s): 90ed124

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -0
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import json
3
+
4
+ def calculate_food(activity, weight):
5
+   if activity and weight:
6
+     calculated_amount = round(activity / weight, 2)
7
+     return {"recommendedFood": calculated_amount}
8
+   else:
9
+     return {"error": "Please provide both activity level and weight."}
10
+
11
+ # Define Streamlit app as a function
12
+ def app():
13
+   # Parse JSON data from the POST request
14
+   try:
15
+     data = st.json_request()
16
+     activity = data.get("activity")
17
+     weight = data.get("weight")
18
+     print("Activity and data recieved")
19
+   except:
20
+     st.json({"error": "Invalid JSON data"})
21
+     return
22
+    
23
+   # Calculate recommended food
24
+   result = calculate_food(activity, weight)
25
+    
26
+   # Respond with the result as JSON
27
+   st.json(result)
28
+
29
+ # Run the Streamlit app
30
+ if __name__ == "__main__":
31
+   app()