postprocessing_caption.py 971 B

123456789101112131415161718192021222324252627282930
  1. from modules import scripts_postprocessing, ui_components, deepbooru, shared
  2. import gradio as gr
  3. class ScriptPostprocessingCeption(scripts_postprocessing.ScriptPostprocessing):
  4. name = "Caption"
  5. order = 4040
  6. def ui(self):
  7. with ui_components.InputAccordion(False, label="Caption") as enable:
  8. option = gr.CheckboxGroup(value=["Deepbooru"], choices=["Deepbooru", "BLIP"], show_label=False)
  9. return {
  10. "enable": enable,
  11. "option": option,
  12. }
  13. def process(self, pp: scripts_postprocessing.PostprocessedImage, enable, option):
  14. if not enable:
  15. return
  16. captions = [pp.caption]
  17. if "Deepbooru" in option:
  18. captions.append(deepbooru.model.tag(pp.image))
  19. if "BLIP" in option:
  20. captions.append(shared.interrogator.interrogate(pp.image.convert("RGB")))
  21. pp.caption = ", ".join([x for x in captions if x])