home · contact · privacy
In Browser, improve metadata translation.
authorChristian Heller <c.heller@plomlompom.de>
Sat, 24 Aug 2024 00:15:47 +0000 (02:15 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Sat, 24 Aug 2024 00:15:47 +0000 (02:15 +0200)
browser.py

index 10fecfb95df3ff20fb615980f1029de6d9e065ec..6f13d7ee2f1dc23264038f43047257ba4363081b 100755 (executable)
@@ -19,16 +19,22 @@ class FileItem(GObject.GObject):
         super().__init__()
         self.name = info.get_name()
         self.last_mod_time = info.get_modification_date_time().format_iso8601()
-        self.seed = ''
         self.full_path = path_join(path, self.name)
-        self.metadata = ''
+        self.seed = ''
+        self.guidance = 0.0
+        self.n_steps = 0
+        self.height = 0
+        self.width = 0
+        self.scheduler = ''
+        self.model = ''
+        self.prompt = ''
         if self.full_path in cache:
             if self.last_mod_time in cache[self.full_path]:
                 cached = cache[self.full_path][self.last_mod_time]
-                self.seed = cached[0]
-                self.metadata = cached[1]
+                for k in cached.keys():
+                    setattr(self, k, cached[k])
 
-    def set_metadata(self, et):
+    def set_metadata(self, et, cache):
         self.metadata = 'no SD comment'
         for d in et.get_tags([self.name], ['Comment']):
             for k, v in d.items():
@@ -36,9 +42,12 @@ class FileItem(GObject.GObject):
                     self.metadata = ''
                     gen_params = GenParams.from_str(v)
                     for k, v_ in gen_params.as_dict.items():
-                        if k == 'seed':
-                            self.seed = v_
-                        self.metadata += f'\n{k}: {v_}'
+                        setattr(self, k, v_)
+        cached = {}
+        for k in ('seed', 'guidance', 'n_steps', 'height',
+                  'width', 'scheduler', 'model', 'prompt'):
+            cached[k] = getattr(self, k)
+        cache[self.full_path] = {self.last_mod_time: cached}
 
 
 class Window(Gtk.ApplicationWindow):
@@ -106,9 +115,8 @@ class Window(Gtk.ApplicationWindow):
             item = FileItem(img_dir_absolute, info, cache)
             self.unsorted += [item]
         with ExifToolHelper() as et:
-            for item in [item for item in self.unsorted if not item.metadata]:
-                item.set_metadata(et)
-                cache[item.full_path] = {item.last_mod_time: [item.seed, item.metadata]}
+            for item in [item for item in self.unsorted if item.seed == '']:
+                item.set_metadata(et, cache)
         self.max_index = len(self.unsorted) - 1
         self.sort('last_mod_time')
         with open('cache.json', 'w') as f:
@@ -129,7 +137,11 @@ class Window(Gtk.ApplicationWindow):
     def reload(self):
         self.viewer.remove(self.viewer.get_last_child())
         if self.item:
-            metadata = f'{self.item.full_path}: {self.item.metadata}'
+            metadata = f'{self.item.full_path}: PROMPT: {self.item.prompt}\n' +\
+                    f'SEED: {self.item.seed} / MODEL: {self.item.model} / ' +\
+                    f'SCHEDULER: {self.item.scheduler}\nGUIDANCE: {self.item.guidance}\n' +\
+                    f'N_STEPS: {self.item.n_steps}\nHEIGHT: {self.item.height} / ' +\
+                    f'WIDTH: {self.item.width}'
             self.metadata.props.label = metadata
             pic = Gtk.Picture.new_for_filename(self.item.name)
             self.viewer.append(pic)