-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui.py
More file actions
89 lines (81 loc) · 3.43 KB
/
ui.py
File metadata and controls
89 lines (81 loc) · 3.43 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
"""
UI components and styles for the Amazon Fresh Fetch Agent.
"""
import json
import pandas as pd
import streamlit as st
STREAMLIT_STYLE = """
<style>
.meal-card {
background-color: #ffffff; border: 1px solid #e0e0e0; border-radius: 10px;
padding: 20px; margin-bottom: 15px; box-shadow: 0 4px 6px rgba(0,0,0,0.05);
border-left: 8px solid #ff4b4b; height: 100%;
}
.meal-header {
font-size: 1.2rem; font-weight: 700; color: #1f1f1f; margin-bottom: 8px;
display: flex; align-items: center;
}
.meal-body { font-size: 1rem; color: #4f4f4f; line-height: 1.5; }
.icon { margin-right: 8px; }
[data-testid="stSidebar"] {
min-width: 250px;
max-width: 500px;
}
</style>
"""
def render_plan_ui(plan_json):
"""
Render the meal plan in the Streamlit UI.
Args:
plan_json (str): The JSON string of the meal plan.
"""
try:
plan_data = json.loads(plan_json)
schedule = plan_data.get("schedule", [])
if schedule:
nutri_data = []
for day in schedule:
n = day.get("nutrition", {})
nutri_data.append(
{
"Day": day["day"],
"Calories": n.get("calories", 0),
"Protein": n.get("protein_g", 0),
"Carbs": n.get("carbs_g", 0),
"Fat": n.get("fat_g", 0),
}
)
if nutri_data:
df_nutri = pd.DataFrame(nutri_data)
st.subheader("📊 Nutritional Analysis")
c1, c2 = st.columns(2)
with c1:
st.bar_chart(df_nutri.set_index("Day")["Calories"], color="#ff4b4b")
with c2:
st.bar_chart(df_nutri.set_index("Day")[["Protein", "Carbs", "Fat"]])
st.subheader("📅 Weekly Plan")
tabs = st.tabs([day["day"] for day in schedule])
for tab, day_info in zip(tabs, schedule):
with tab:
col1, col2, col3 = st.columns(3)
def get_title(m):
return m.get("title", str(m)) if isinstance(m, dict) else str(m)
with col1:
st.markdown(
f"""<div class="meal-card"><div class="meal-header"><span class="icon">🥞</span> Breakfast</div><div class="meal-body">{get_title(day_info.get('breakfast'))}</div></div>""",
unsafe_allow_html=True,
)
with col2:
st.markdown(
f"""<div class="meal-card"><div class="meal-header"><span class="icon">🥗</span> Lunch</div><div class="meal-body">{get_title(day_info.get('lunch'))}</div></div>""",
unsafe_allow_html=True,
)
with col3:
st.markdown(
f"""<div class="meal-card"><div class="meal-header"><span class="icon">🍳</span> Dinner</div><div class="meal-body">{get_title(day_info.get('dinner'))}</div></div>""",
unsafe_allow_html=True,
)
with st.expander("👨🍳 View Cooking Instructions"):
st.json(day_info)
except Exception as e:
st.error(f"Error rendering plan: {e}")