tdurzynski commited on
Commit
094dc67
·
verified ·
1 Parent(s): 347ca22

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -22
app.py CHANGED
@@ -5,13 +5,12 @@ import io
5
  import base64
6
  import boto3
7
  from PIL import Image
8
- from streamlit_tags import st_tags
9
  import firebase_admin
10
  from firebase_admin import credentials, auth
11
 
12
  # Load AWS credentials using correct HF Secrets
13
- AWS_ACCESS_KEY = os.getenv("AWS_ACCESS_KEY_ID")
14
- AWS_SECRET_KEY = os.getenv("AWS_SECRET_ACCESS_KEY")
15
  AWS_REGION = os.getenv("AWS_REGION", "us-east-1")
16
  S3_BUCKET_NAME = os.getenv("S3_BUCKET_NAME", "food-image-crowdsourcing")
17
  DYNAMODB_TABLE = os.getenv("DYNAMODB_TABLE", "image_metadata")
@@ -77,6 +76,15 @@ if "user_id" not in st.session_state:
77
  st.title("🍽️ Food Image Review & Annotation")
78
  col1, col2, col3 = st.columns([1, 1, 1])
79
 
 
 
 
 
 
 
 
 
 
80
  # Upload Image
81
  uploaded_file = st.file_uploader("Upload an image of your food", type=["jpg", "png", "jpeg"])
82
  if uploaded_file:
@@ -104,26 +112,27 @@ if "original_image" in st.session_state:
104
  st.subheader("🖼️ Processed Image")
105
  st.image(processed_img, caption=f"Processed ({processed_img.width}x{processed_img.height} pixels)", use_container_width=True)
106
 
107
- # ✏️ Panel 3: Food Annotations with Intellisense
108
  with col3:
109
  st.subheader("📝 Add Annotations")
110
-
111
- # Expanded food suggestions
112
- suggested_foods = [
113
- "Pizza", "Pasta", "Tacos", "Sushi", "Ramen", "Kimchi", "Bratwurst", "Jambalaya",
114
- "Chicken", "Rice", "Steak", "Bread", "Cheese", "Salmon", "Avocado", "Eggs",
115
- "Carrots", "Tomatoes", "Cucumber", "Yogurt", "Peanuts", "Lettuce", "Curry", "Dumplings",
116
- "Pho", "Lasagna", "Paella", "Peking Duck", "Borscht", "Pierogi", "Schnitzel", "Bulgogi"
117
- ]
118
-
119
- # User selects food items from suggestions
120
- food_items = st_tags(
121
- label="Enter food items",
122
- text="Add items...",
123
- value=[],
124
- suggestions=suggested_foods,
125
- maxtags=10,
126
- )
 
127
 
128
  if st.button("Save Annotations"):
129
  metadata_table.update_item(
@@ -134,7 +143,7 @@ if "original_image" in st.session_state:
134
  ":a": food_items,
135
  ":p": "processed",
136
  ":s": f"s3://{S3_BUCKET_NAME}/raw-uploads/{uploaded_file.name}",
137
- ":t": 1 if food_items else 0
138
  },
139
  )
140
  st.success("✅ Annotations saved successfully!")
 
5
  import base64
6
  import boto3
7
  from PIL import Image
 
8
  import firebase_admin
9
  from firebase_admin import credentials, auth
10
 
11
  # Load AWS credentials using correct HF Secrets
12
+ AWS_ACCESS_KEY = os.getenv("AWS_ACCESS_KEY")
13
+ AWS_SECRET_KEY = os.getenv("AWS_SECRET_KEY")
14
  AWS_REGION = os.getenv("AWS_REGION", "us-east-1")
15
  S3_BUCKET_NAME = os.getenv("S3_BUCKET_NAME", "food-image-crowdsourcing")
16
  DYNAMODB_TABLE = os.getenv("DYNAMODB_TABLE", "image_metadata")
 
76
  st.title("🍽️ Food Image Review & Annotation")
77
  col1, col2, col3 = st.columns([1, 1, 1])
78
 
79
+ # Compliance & Disclaimer Section
80
+ st.markdown("### **Terms & Conditions**")
81
+ st.write(
82
+ "By uploading an image, you agree to transfer full copyright to the research team for AI training purposes."
83
+ " You are responsible for ensuring you own the image and it does not violate any copyright laws."
84
+ " We do not guarantee when tokens will be redeemable. Keep track of your user ID."
85
+ )
86
+ st.checkbox("I agree to the terms and conditions", key="terms_accepted")
87
+
88
  # Upload Image
89
  uploaded_file = st.file_uploader("Upload an image of your food", type=["jpg", "png", "jpeg"])
90
  if uploaded_file:
 
112
  st.subheader("🖼️ Processed Image")
113
  st.image(processed_img, caption=f"Processed ({processed_img.width}x{processed_img.height} pixels)", use_container_width=True)
114
 
115
+ # ✏️ Panel 3: Food Annotations with Structured Input
116
  with col3:
117
  st.subheader("📝 Add Annotations")
118
+ food_items = []
119
+
120
+ # User enters food items one at a time
121
+ new_food = st.text_input("Enter food item")
122
+ if st.button("+ Add Food Item"):
123
+ if new_food:
124
+ food_items.append({"name": new_food, "ingredients": [], "weight": None})
125
+
126
+ # Display added food items
127
+ for idx, food in enumerate(food_items):
128
+ st.write(f"{idx+1}. {food['name']}")
129
+ sub_ingredient = st.text_input(f"Add ingredient for {food['name']}", key=f"sub_{idx}")
130
+ if st.button(f"+ Add Ingredient to {food['name']}", key=f"btn_{idx}"):
131
+ food["ingredients"].append(sub_ingredient)
132
+
133
+ weight = st.text_input(f"Enter weight for {food['name']} (grams)", key=f"wt_{idx}")
134
+ if weight:
135
+ food["weight"] = weight
136
 
137
  if st.button("Save Annotations"):
138
  metadata_table.update_item(
 
143
  ":a": food_items,
144
  ":p": "processed",
145
  ":s": f"s3://{S3_BUCKET_NAME}/raw-uploads/{uploaded_file.name}",
146
+ ":t": len(food_items)
147
  },
148
  )
149
  st.success("✅ Annotations saved successfully!")