Skip to content

Commit

Permalink
Ensure jsons are saved
Browse files Browse the repository at this point in the history
  • Loading branch information
derneuere committed Dec 11, 2023
1 parent c3f1ed8 commit 3639c37
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions api/models/photo.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,20 +198,19 @@ def _generate_captions_im2txt(self, commit=True):

def _save_captions(self, commit=True, caption=None):
image_path = self.thumbnail_big.path
captions = self.captions_json
search_captions = self.search_captions
try:
caption = (
caption.replace("<start>", "").replace("<end>", "").strip().lower()
)
captions["user_caption"] = caption
self.captions_json = captions
# todo: handle duplicate captions
self.search_captions = search_captions + caption
self.captions_json["user_caption"] = caption
self.search_captions = caption
if commit:
self.save()
self.save(update_fields=["captions_json", "search_captions"])

util.logger.info(
"saved captions for image %s. caption: %s" % (image_path, caption)
"saved captions for image %s. caption: %s. search_captions: %s. captions_json: %s."
% (image_path, caption, search_captions, self.captions_json)
)
return True
except Exception:
Expand Down

0 comments on commit 3639c37

Please sign in to comment.