tdurzynski commited on
Commit
572428a
ยท
verified ยท
1 Parent(s): 9d30b87

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -42
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
- # ๐Ÿ–ผ๏ธ Panel 1: Original Image
117
- with col1:
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
- # ๐Ÿ–ผ๏ธ Panel 2: Resized Image (512x512 Maintaining Aspect Ratio)
122
- with col2:
123
- st.subheader("๐Ÿ–ผ๏ธ Processed Image")
124
- st.image(processed_img, caption=f"Processed ({processed_img.width}x{processed_img.height} pixels)", use_column_width=True)
125
 
126
- # ๐Ÿ“ Annotation Table
127
- st.subheader("๐Ÿ“ Add Annotations")
 
128
 
129
- if "annotations" not in st.session_state:
130
- st.session_state["annotations"] = []
131
 
132
- # Create dataframe for annotations
133
- annotation_df = pd.DataFrame(st.session_state["annotations"], columns=["Food Item", "Unit", "Quantity", "Ingredients"])
134
 
135
- # Food input with intellisense
136
- food_item = st.selectbox("Select food item or type custom:", FOOD_SUGGESTIONS + ["Other"])
137
- if food_item == "Other":
138
- food_item = st.text_input("Enter food item manually:")
139
 
140
- unit = st.selectbox("Select unit:", UNIT_OPTIONS)
141
- quantity = st.number_input("Enter quantity:", min_value=0.1, step=0.1)
142
 
143
- # Dynamic ingredient input
144
- ingredients = st.text_area("Enter ingredients (one per line):")
145
- ingredient_list = [i.strip() for i in ingredients.split("\n") if i.strip()]
146
 
147
- if st.button("Add Food Item"):
148
- if food_item and unit and quantity:
149
- st.session_state["annotations"].append([food_item, unit, quantity, ingredient_list])
150
- st.success(f"โœ… Added {food_item} successfully!")
151
 
152
- # Display annotation table
153
- st.dataframe(pd.DataFrame(st.session_state["annotations"], columns=["Food Item", "Unit", "Quantity", "Ingredients"]))
 
 
 
 
 
154
 
155
- # Save Annotations to DynamoDB
156
  if st.button("Save Annotations"):
157
- metadata_table.update_item(
158
- Key={"image_id": uploaded_file.name},
159
- UpdateExpression="SET user_id = :u, annotations = :a, processing_status = :p, s3_url = :s, tokens_earned = :t",
160
- ExpressionAttributeValues={
161
- ":u": st.session_state["user_id"],
162
- ":a": st.session_state["annotations"],
163
- ":p": "processed",
164
- ":s": f"s3://{S3_BUCKET_NAME}/raw-uploads/{uploaded_file.name}",
165
- ":t": len(st.session_state["annotations"])
166
- },
167
- )
168
- st.success("โœ… Annotations saved successfully!")
 
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"])