Advertisement
Lethargus

MagicPrompt script for AUTOMATIC1111's Stable Diffusion GUI v1.2

Oct 4th, 2022 (edited)
2,284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | Source Code | 0 0
  1. import math
  2. import os
  3. import sys
  4. import traceback
  5.  
  6. import modules.scripts as scripts
  7. import gradio as gr
  8.  
  9. from modules.processing import Processed, process_images
  10. from PIL import Image
  11. from modules.shared import opts, cmd_opts, state
  12.  
  13. from aitextgen import aitextgen
  14.  
  15.  
  16. class Script(scripts.Script):
  17. def title(self):
  18. return "Prompts from Gustavosta MagicPrompt"
  19.  
  20. def ui(self, is_img2img):
  21. gpt2model = gr.Textbox(label='GPT-2 Model Directory', value="MagicPrompt-Stable-Diffusion")
  22. prompt_length = gr.Slider(label='Max Length', value=100, minimum=1, maximum=150, step=1)
  23. temperature_value = gr.Slider(label='Temperature', value=0.7, minimum=0.1, maximum=2, step=0.05)
  24. return [gpt2model, prompt_length, temperature_value]
  25.  
  26. def run(self, p, gpt2model, prompt_length, temperature_value):
  27. ai = aitextgen(model_folder=gpt2model, tokenizer_file=gpt2model + "/tokenizer.json")
  28. p.prompt = ai.generate_one(prompt=p.prompt, max_length=prompt_length, temperature=temperature_value)
  29. p.prompt = p.prompt.translate({ord(i): None for i in '[:](){}\/'})
  30. print(f"Generated prompt: {p.prompt}")
  31. p.do_not_save_grid = True
  32. proc = process_images(p)
  33. return proc
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement