Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -113,56 +113,52 @@ if "original_image" in st.session_state:
|
|
113 |
original_img = st.session_state["original_image"]
|
114 |
processed_img = resize_image(original_img)
|
115 |
|
116 |
-
|
117 |
-
|
118 |
-
st.subheader("๐ท Original Image")
|
119 |
-
st.image(original_img, caption=f"Uploaded ({original_img.width}x{original_img.height} pixels)", use_column_width=True)
|
120 |
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
st.image(processed_img, caption=f"Processed ({processed_img.width}x{processed_img.height} pixels)", use_column_width=True)
|
125 |
|
126 |
-
|
127 |
-
st.subheader("
|
|
|
128 |
|
129 |
-
if "annotations" not in st.session_state:
|
130 |
-
st.session_state["annotations"] = []
|
131 |
|
132 |
-
# Create
|
133 |
-
|
134 |
|
135 |
-
#
|
136 |
-
|
137 |
-
if food_item == "Other":
|
138 |
-
food_item = st.text_input("Enter food item manually:")
|
139 |
|
140 |
-
|
141 |
-
|
142 |
|
143 |
-
#
|
144 |
-
|
145 |
-
ingredient_list = [i.strip() for i in ingredients.split("\n") if i.strip()]
|
146 |
|
147 |
-
|
148 |
-
|
149 |
-
st.session_state["annotations"].append([food_item, unit, quantity, ingredient_list])
|
150 |
-
st.success(f"โ
Added {food_item} successfully!")
|
151 |
|
152 |
-
#
|
153 |
-
|
|
|
|
|
|
|
|
|
|
|
154 |
|
155 |
-
#
|
156 |
if st.button("Save Annotations"):
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
|
|
113 |
original_img = st.session_state["original_image"]
|
114 |
processed_img = resize_image(original_img)
|
115 |
|
116 |
+
# Adjusting Layout: Original Image (2 Columns) | Processed Image (2 Columns)
|
117 |
+
col1, col2 = st.columns(2) # Two columns for images
|
|
|
|
|
118 |
|
119 |
+
with col1:
|
120 |
+
st.subheader("๐ท Original Image")
|
121 |
+
st.image(original_img, caption=f"Original ({original_img.width}x{original_img.height} pixels)", use_column_width=True)
|
|
|
122 |
|
123 |
+
with col2:
|
124 |
+
st.subheader("๐ผ๏ธ Processed Image")
|
125 |
+
st.image(processed_img, caption=f"Processed ({processed_img.width}x{processed_img.height} pixels)", use_column_width=True)
|
126 |
|
|
|
|
|
127 |
|
128 |
+
# Create a table-like structure for food annotation
|
129 |
+
st.subheader("๐ Add Annotations")
|
130 |
|
131 |
+
# Define columns for table structure
|
132 |
+
col_food, col_qty, col_unit, col_ing = st.columns([2, 1, 1, 2]) # Define column widths
|
|
|
|
|
133 |
|
134 |
+
# Food Item Dropdown (with Intellisense)
|
135 |
+
food_item = col_food.selectbox("Food Item", options=suggested_foods, index=None, placeholder="Select or enter food")
|
136 |
|
137 |
+
# Quantity Input
|
138 |
+
quantity = col_qty.number_input("Qty", min_value=0, step=1)
|
|
|
139 |
|
140 |
+
# Unit Dropdown (Grams, Ounces, etc.)
|
141 |
+
unit = col_unit.selectbox("Unit", ["g", "oz", "tsp", "tbsp", "cup", "slice", "piece"])
|
|
|
|
|
142 |
|
143 |
+
# Ingredients Section with Expandable Input
|
144 |
+
with col_ing:
|
145 |
+
ingredients = []
|
146 |
+
if st.button("+ Add Ingredients"):
|
147 |
+
ingredient = st.text_input("Enter ingredient")
|
148 |
+
if ingredient:
|
149 |
+
ingredients.append(ingredient)
|
150 |
|
151 |
+
# Display added annotations in a structured format
|
152 |
if st.button("Save Annotations"):
|
153 |
+
new_entry = {
|
154 |
+
"name": food_item,
|
155 |
+
"quantity": quantity,
|
156 |
+
"unit": unit,
|
157 |
+
"ingredients": ingredients,
|
158 |
+
}
|
159 |
+
st.session_state["annotations"].append(new_entry)
|
160 |
+
st.success("โ
Annotation saved!")
|
161 |
+
|
162 |
+
# Show existing annotations
|
163 |
+
st.write("### Current Annotations")
|
164 |
+
st.table(st.session_state["annotations"])
|