mirror of
https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
synced 2024-06-07 21:20:49 +00:00
inspiration finished
This commit is contained in:
parent
2797b2cbf2
commit
58ee008f0f
@ -2,44 +2,56 @@ import csv, os, shutil
|
|||||||
import modules.scripts as scripts
|
import modules.scripts as scripts
|
||||||
from modules import processing, shared, sd_samplers, images
|
from modules import processing, shared, sd_samplers, images
|
||||||
from modules.processing import Processed
|
from modules.processing import Processed
|
||||||
|
from modules.shared import opts
|
||||||
|
import gradio
|
||||||
class Script(scripts.Script):
|
class Script(scripts.Script):
|
||||||
def title(self):
|
def title(self):
|
||||||
return "Create artists style image"
|
return "Create inspiration images"
|
||||||
|
|
||||||
def show(self, is_img2img):
|
def show(self, is_img2img):
|
||||||
return not is_img2img
|
return True
|
||||||
|
|
||||||
def ui(self, is_img2img):
|
def ui(self, is_img2img):
|
||||||
return []
|
file = gradio.Files(label="Artist or styles name list. '.txt' files with one name per line",)
|
||||||
def show(self, is_img2img):
|
with gradio.Row():
|
||||||
return not is_img2img
|
prefix = gradio.Textbox("a painting in", label="Prompt words before artist or style name", file_count="multiple")
|
||||||
|
suffix= gradio.Textbox("style", label="Prompt words after artist or style name")
|
||||||
|
negative_prompt = gradio.Textbox("picture frame, portrait photo", label="Negative Prompt")
|
||||||
|
with gradio.Row():
|
||||||
|
batch_size = gradio.Number(1, label="Batch size")
|
||||||
|
batch_count = gradio.Number(2, label="Batch count")
|
||||||
|
return [batch_size, batch_count, prefix, suffix, negative_prompt, file]
|
||||||
|
|
||||||
def run(self, p): #, max_snapshoots_num):
|
def run(self, p, batch_size, batch_count, prefix, suffix, negative_prompt, files):
|
||||||
path = os.path.join("style_snapshoot", "artist")
|
p.batch_size = int(batch_size)
|
||||||
if not os.path.exists(path):
|
p.n_iterint = int(batch_count)
|
||||||
os.makedirs(path)
|
p.negative_prompt = negative_prompt
|
||||||
p.do_not_save_samples = True
|
p.do_not_save_samples = True
|
||||||
p.do_not_save_grid = True
|
p.do_not_save_grid = True
|
||||||
p.negative_prompt = "portrait photo"
|
for file in files:
|
||||||
f = open('artists.csv')
|
tp = file.orig_name.split(".")[0]
|
||||||
f_csv = csv.reader(f)
|
print(tp)
|
||||||
for row in f_csv:
|
path = os.path.join(opts.inspiration_dir, tp)
|
||||||
name = row[0]
|
if not os.path.exists(path):
|
||||||
artist_path = os.path.join(path, name)
|
os.makedirs(path)
|
||||||
if not os.path.exists(artist_path):
|
f = open(file.name, "r")
|
||||||
os.mkdir(artist_path)
|
line = f.readline()
|
||||||
if len(os.listdir(artist_path)) > 0:
|
while len(line) > 0:
|
||||||
continue
|
name = line.rstrip("\n").split(",")[0]
|
||||||
print(name)
|
line = f.readline()
|
||||||
p.prompt = name
|
artist_path = os.path.join(path, name)
|
||||||
processed = processing.process_images(p)
|
if not os.path.exists(artist_path):
|
||||||
for img in processed.images:
|
os.mkdir(artist_path)
|
||||||
i = 0
|
if len(os.listdir(artist_path)) >= opts.inspiration_max_samples:
|
||||||
filename = os.path.join(artist_path, format(0, "03d") + ".jpg")
|
continue
|
||||||
while os.path.exists(filename):
|
p.prompt = f"{prefix} {name} {suffix}"
|
||||||
i += 1
|
print(p.prompt)
|
||||||
filename = os.path.join(artist_path, format(i, "03d") + ".jpg")
|
processed = processing.process_images(p)
|
||||||
img.save(filename, quality=70)
|
for img in processed.images:
|
||||||
|
i = 0
|
||||||
|
filename = os.path.join(artist_path, format(0, "03d") + ".jpg")
|
||||||
|
while os.path.exists(filename):
|
||||||
|
i += 1
|
||||||
|
filename = os.path.join(artist_path, format(i, "03d") + ".jpg")
|
||||||
|
img.save(filename, quality=80)
|
||||||
return processed
|
return processed
|
||||||
|
Loading…
Reference in New Issue
Block a user