ibrahim yıldız commited on
Commit
65b3dbc
·
verified ·
1 Parent(s): b91cf21

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -30
app.py CHANGED
@@ -9,7 +9,8 @@ genai.configure(api_key="AIzaSyB6z5crVaKSj1ct_gVsq6nrHtSGme_JmoY")
9
  # API configurations for Dobby
10
  DOBBY_API_URL = "https://api.fireworks.ai/inference/v1/chat/completions"
11
  DOBBY_API_KEY = "fw_3ZjtsywUGddwa1wGY4VvB3eW"
12
- DOBBY_UNLEASHED_MODEL = "accounts/sentientfoundation/models/dobby-mini-unhinged-llama-3-1-8b#accounts/sentientfoundation/deployments/81e155fc"
 
13
 
14
  # Initialize session state for tracking meals and user info
15
  if "meal_data" not in st.session_state:
@@ -19,46 +20,62 @@ if "daily_totals" not in st.session_state:
19
  if "user_info" not in st.session_state:
20
  st.session_state.user_info = {}
21
 
22
- # Custom Streamlit UI Styling
23
- st.markdown(
24
- """
25
  <style>
26
  .stApp {
27
- background-color: #f9f9f9;
 
 
 
 
 
 
 
 
28
  }
29
- .block-container {
30
- padding-top: 2rem;
 
 
 
 
31
  }
32
- .css-1q8dd3e {
33
- font-size: 18px;
 
 
 
 
 
 
 
 
 
 
34
  }
35
  </style>
36
- """,
37
- unsafe_allow_html=True,
38
- )
39
 
40
- # App setup
41
- st.title("Calorie Bro")
42
- st.write("Calorie Bro is your AI image calorie tracker. Dare to get meal feedback from Dobby based on your goals!")
43
 
44
- # Sidebar for User Preferences
45
- st.sidebar.header("Set Your Preferences")
46
  if not st.session_state.user_info:
47
- default_weight = 70
48
- weight = st.sidebar.number_input("Enter your weight (kg):", value=default_weight, min_value=30, max_value=300, step=1)
49
- goal = st.sidebar.selectbox("Select your goal:", ["Lose Weight", "Maintain Weight", "Gain Weight"])
50
- tone = st.sidebar.radio("Select Dobby's tone:", ["Motivational (Leashed)", "Sarcastic (Unhinged)"])
51
- if st.sidebar.button("Save Preferences"):
52
  st.session_state.user_info = {
53
  "Weight": weight,
54
  "Goal": goal,
55
  "Tone": tone
56
  }
57
- st.sidebar.success("Preferences saved! Proceed to meal tracking.")
58
 
59
- # Step 2: Meal Tracking
60
  if st.session_state.user_info:
61
- st.subheader("Step 2: Meal Tracking")
62
  meal = st.selectbox("Select Meal:", ["Breakfast", "Lunch", "Dinner"])
63
  uploaded_file = st.file_uploader(f"Upload your {meal} image", type=["jpg", "jpeg", "png"])
64
 
@@ -72,7 +89,8 @@ if st.session_state.user_info:
72
  bytes_data = uploaded_file.getvalue()
73
  return [{"mime_type": uploaded_file.type, "data": bytes_data}]
74
 
75
- def get_dobby_comment(food_name, total_calories, total_protein, total_carbs, total_fat, meal, goal):
 
76
  dobby_prompt = f"""
77
  The user had {meal}: {food_name}.
78
  Nutritional data: {total_calories} kcal, {total_protein} g protein, {total_carbs} g carbs, {total_fat} g fat.
@@ -85,7 +103,7 @@ if st.session_state.user_info:
85
  "Content-Type": "application/json",
86
  },
87
  json={
88
- "model": DOBBY_UNLEASHED_MODEL,
89
  "messages": [{"role": "user", "content": dobby_prompt}],
90
  },
91
  )
@@ -93,7 +111,7 @@ if st.session_state.user_info:
93
 
94
  # Process uploaded meal image
95
  if uploaded_file:
96
- st.image(uploaded_file, caption=f"Uploaded {meal} Image", use_column_width=True)
97
  with st.spinner("Analyzing the image..."):
98
  try:
99
  # Prepare image data and analyze with Gemini
@@ -137,7 +155,7 @@ if st.session_state.user_info:
137
  # Get Dobby's feedback
138
  dobby_comment = get_dobby_comment(
139
  food_name, total_calories, total_protein, total_carbs, total_fat, meal,
140
- st.session_state.user_info["Goal"]
141
  )
142
 
143
  # Display results in the desired format
@@ -171,6 +189,6 @@ if st.session_state.user_info:
171
  final_comment = get_dobby_comment(
172
  "", st.session_state.daily_totals["Calories"], st.session_state.daily_totals["Protein"],
173
  st.session_state.daily_totals["Carbs"], st.session_state.daily_totals["Fat"], "Daily Summary",
174
- st.session_state.user_info["Goal"]
175
  )
176
  st.write(final_comment)
 
9
  # API configurations for Dobby
10
  DOBBY_API_URL = "https://api.fireworks.ai/inference/v1/chat/completions"
11
  DOBBY_API_KEY = "fw_3ZjtsywUGddwa1wGY4VvB3eW"
12
+ DOBBY_LEASHED_MODEL = "accounts/sentientfoundation/models/dobby-mini-leashed-llama-3-1-8b#accounts/sentientfoundation/deployments/22e7b3fd"
13
+ DOBBY_UNHINGED_MODEL = "accounts/sentientfoundation/models/dobby-mini-unhinged-llama-3-1-8b#accounts/sentientfoundation/deployments/81e155fc"
14
 
15
  # Initialize session state for tracking meals and user info
16
  if "meal_data" not in st.session_state:
 
20
  if "user_info" not in st.session_state:
21
  st.session_state.user_info = {}
22
 
23
+ # App setup
24
+ st.markdown("""
 
25
  <style>
26
  .stApp {
27
+ background-color: #f4f4f8;
28
+ font-family: Arial, sans-serif;
29
+ }
30
+ .title {
31
+ font-size: 36px;
32
+ font-weight: bold;
33
+ color: #444;
34
+ text-align: center;
35
+ margin-bottom: 20px;
36
  }
37
+ .subtitle {
38
+ font-size: 20px;
39
+ font-weight: 400;
40
+ color: #666;
41
+ text-align: center;
42
+ margin-bottom: 40px;
43
  }
44
+ .header {
45
+ font-size: 24px;
46
+ font-weight: bold;
47
+ color: #333;
48
+ margin-bottom: 10px;
49
+ }
50
+ .button {
51
+ background-color: #4CAF50;
52
+ color: white;
53
+ font-size: 16px;
54
+ padding: 10px 20px;
55
+ border-radius: 5px;
56
  }
57
  </style>
58
+ """, unsafe_allow_html=True)
 
 
59
 
60
+ st.markdown('<div class="title">Calorie Bro</div>', unsafe_allow_html=True)
61
+ st.markdown('<div class="subtitle">Your AI image calorie tracker, powered by Dobby. Dare to get feedback!</div>', unsafe_allow_html=True)
 
62
 
63
+ # Step 1: User inputs weight, goal, and Dobby tone
 
64
  if not st.session_state.user_info:
65
+ st.markdown('<div class="header">Step 1: Set Your Preferences</div>', unsafe_allow_html=True)
66
+ weight = st.number_input("Enter your weight (kg):", min_value=30, max_value=300, step=1, value=70)
67
+ goal = st.selectbox("Select your goal:", ["Lose Weight", "Maintain Weight", "Gain Weight"])
68
+ tone = "Sarcastic (Unhinged)" # Default tone
69
+ if st.button("Submit", help="Save your preferences to start tracking meals."):
70
  st.session_state.user_info = {
71
  "Weight": weight,
72
  "Goal": goal,
73
  "Tone": tone
74
  }
75
+ st.success("Your preferences have been saved! Proceed to meal tracking.")
76
 
77
+ # Step 2: Meal tracking
78
  if st.session_state.user_info:
 
79
  meal = st.selectbox("Select Meal:", ["Breakfast", "Lunch", "Dinner"])
80
  uploaded_file = st.file_uploader(f"Upload your {meal} image", type=["jpg", "jpeg", "png"])
81
 
 
89
  bytes_data = uploaded_file.getvalue()
90
  return [{"mime_type": uploaded_file.type, "data": bytes_data}]
91
 
92
+ def get_dobby_comment(food_name, total_calories, total_protein, total_carbs, total_fat, meal, goal, tone):
93
+ selected_model = DOBBY_UNHINGED_MODEL # Default tone is sarcastic
94
  dobby_prompt = f"""
95
  The user had {meal}: {food_name}.
96
  Nutritional data: {total_calories} kcal, {total_protein} g protein, {total_carbs} g carbs, {total_fat} g fat.
 
103
  "Content-Type": "application/json",
104
  },
105
  json={
106
+ "model": selected_model,
107
  "messages": [{"role": "user", "content": dobby_prompt}],
108
  },
109
  )
 
111
 
112
  # Process uploaded meal image
113
  if uploaded_file:
114
+ st.image(uploaded_file, caption=f"Uploaded {meal} Image", use_container_width=True)
115
  with st.spinner("Analyzing the image..."):
116
  try:
117
  # Prepare image data and analyze with Gemini
 
155
  # Get Dobby's feedback
156
  dobby_comment = get_dobby_comment(
157
  food_name, total_calories, total_protein, total_carbs, total_fat, meal,
158
+ st.session_state.user_info["Goal"], st.session_state.user_info["Tone"]
159
  )
160
 
161
  # Display results in the desired format
 
189
  final_comment = get_dobby_comment(
190
  "", st.session_state.daily_totals["Calories"], st.session_state.daily_totals["Protein"],
191
  st.session_state.daily_totals["Carbs"], st.session_state.daily_totals["Fat"], "Daily Summary",
192
+ st.session_state.user_info["Goal"], st.session_state.user_info["Tone"]
193
  )
194
  st.write(final_comment)