Update app.py
Browse files
app.py
CHANGED
@@ -152,14 +152,19 @@ def run_showui(image, query, session_id, iterations=2):
|
|
152 |
|
153 |
return images_during_iterations, str(click_xy)
|
154 |
|
155 |
-
def save_and_upload_data(
|
156 |
"""Save the data to a JSON file and upload to S3."""
|
157 |
if is_example_image == "True":
|
158 |
return
|
159 |
|
160 |
votes = votes or {"upvotes": 0, "downvotes": 0}
|
|
|
|
|
|
|
|
|
|
|
161 |
data = {
|
162 |
-
"image_path":
|
163 |
"query": query,
|
164 |
"votes": votes,
|
165 |
"timestamp": datetime.now().isoformat()
|
@@ -170,8 +175,9 @@ def save_and_upload_data(image_path, query, session_id, is_example_image, votes=
|
|
170 |
with open(local_file_name, "w") as f:
|
171 |
json.dump(data, f)
|
172 |
|
|
|
173 |
upload_to_s3(local_file_name, 'altair.storage', object_name=f"ootb/{local_file_name}")
|
174 |
-
upload_to_s3(
|
175 |
|
176 |
return data
|
177 |
|
|
|
152 |
|
153 |
return images_during_iterations, str(click_xy)
|
154 |
|
155 |
+
def save_and_upload_data(image, query, session_id, is_example_image, votes=None):
|
156 |
"""Save the data to a JSON file and upload to S3."""
|
157 |
if is_example_image == "True":
|
158 |
return
|
159 |
|
160 |
votes = votes or {"upvotes": 0, "downvotes": 0}
|
161 |
+
|
162 |
+
# Save image locally
|
163 |
+
image_file_name = f"{session_id}.png"
|
164 |
+
image.save(image_file_name)
|
165 |
+
|
166 |
data = {
|
167 |
+
"image_path": image_file_name,
|
168 |
"query": query,
|
169 |
"votes": votes,
|
170 |
"timestamp": datetime.now().isoformat()
|
|
|
175 |
with open(local_file_name, "w") as f:
|
176 |
json.dump(data, f)
|
177 |
|
178 |
+
# Upload JSON and image to S3
|
179 |
upload_to_s3(local_file_name, 'altair.storage', object_name=f"ootb/{local_file_name}")
|
180 |
+
upload_to_s3(image_file_name, 'altair.storage', object_name=f"ootb/{image_file_name}")
|
181 |
|
182 |
return data
|
183 |
|