Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

History and Troubleshooting Panels #132

Merged
merged 6 commits into from
Sep 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,16 @@
"author": "Carson Katri, Greg Richardson, Kevin C. Burke",
"description": "Use Stable Diffusion to generate unique textures straight from the shader editor.",
"warning": "Requires installation of Stable Diffusion model weights",
"blender": (2, 80, 0),
"version": (0, 0, 5),
"blender": (3, 0, 0),
"version": (0, 0, 6),
"location": "",
"warning": "",
"category": "Node"
"category": "Paint"
}

import bpy
from bpy.props import IntProperty, PointerProperty, EnumProperty
import sys
import importlib

from .help_section import register_section_props

Expand Down
12 changes: 5 additions & 7 deletions classes.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
from .operators.install_dependencies import InstallDependencies
from .operators.open_latest_version import OpenLatestVersion
from .operators.dream_texture import DreamTexture, ReleaseGenerator
from .operators.help_panel import HelpPanel
from .operators.view_history import RecallHistoryEntry, SCENE_UL_HistoryList, ViewHistory
from .operators.view_history import RecallHistoryEntry, SCENE_UL_HistoryList
from .operators.inpaint_area_brush import InpaintAreaStroke
from .property_groups.dream_prompt import DreamPrompt
from .ui.panel import DREAM_PT_dream_panel, DREAM_PT_dream_node_panel
from .ui.panel import panels, history_panels, troubleshooting_panels
from .preferences import OpenGitDownloads, OpenHuggingFace, OpenWeightsDirectory, OpenRustInstaller, ValidateInstallation, StableDiffusionPreferences

CLASSES = (
DreamTexture,
ReleaseGenerator,
HelpPanel,
OpenLatestVersion,
ViewHistory,
RecallHistoryEntry,
InpaintAreaStroke,
SCENE_UL_HistoryList,
DREAM_PT_dream_panel,
DREAM_PT_dream_node_panel,
*panels(),
*history_panels(),
*troubleshooting_panels(),
)

PREFERENCE_CLASSES = (
Expand Down
4 changes: 2 additions & 2 deletions generator_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ def view_step(samples, step):
return # stdin closed
args = json.loads(stdin.read(json_len))

if generator is None or generator.full_precision != args['full_precision']:
writeInfo("Initializing Generator")
if generator is None or (generator.full_precision != args['full_precision'] and sys.platform != 'darwin'):
writeInfo("Loading Model")
try:
generator = Generate(
conf=models_config,
Expand Down
9 changes: 1 addition & 8 deletions operators/dream_texture.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@
last_data_block = None
timer = None

def image_has_alpha(img):
b = 32 if img.is_float else 8
return (
img.depth == 2*b or # Grayscale+Alpha
img.depth == 4*b # RGB+Alpha
)

class DreamTexture(bpy.types.Operator):
bl_idname = "shade.dream_texture"
bl_label = "Dream Texture"
Expand Down Expand Up @@ -162,7 +155,7 @@ def save_temp_image(img, path=None):
if scene.dream_textures_prompt.use_inpainting:
for area in screen.areas:
if area.type == 'IMAGE_EDITOR':
if area.spaces.active.image is not None and image_has_alpha(area.spaces.active.image):
if area.spaces.active.image is not None:
init_img = area.spaces.active.image
init_img_path = None
if init_img is not None:
Expand Down
21 changes: 0 additions & 21 deletions operators/help_panel.py

This file was deleted.

46 changes: 11 additions & 35 deletions operators/view_history.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,20 @@
import bpy
from ..property_groups.dream_prompt import sampler_options
from ..preferences import StableDiffusionPreferences

class ViewHistory(bpy.types.Operator):
bl_idname = "shade.dream_textures_history"
bl_label = "History"
bl_description = "View and reload previous prompts"
bl_options = {'REGISTER'}

selection: bpy.props.IntProperty(name="Selection")

@classmethod
def poll(self, context):
return True

def invoke(self, context, event):
return context.window_manager.invoke_props_dialog(self, width=500)

def draw(self, context):
# split = self.layout.split(factor=0.95)
# header = split.row()
header = self.layout.row()
header.label(text="Subject")
header.label(text="Size")
header.label(text="Steps")
header.label(text="Sampler")
self.layout.template_list("SCENE_UL_HistoryList", "", context.preferences.addons[StableDiffusionPreferences.bl_idname].preferences, "history", context.scene, "dream_textures_history_selection")
self.layout.operator(RecallHistoryEntry.bl_idname)

def execute(self, context):
return {"FINISHED"}

class SCENE_UL_HistoryList(bpy.types.UIList):
def draw_item(self, context, layout, data, item, icon, active_data, active_propname):
if self.layout_type in {'DEFAULT', 'COMPACT'}:
layout.label(text=item.get_prompt_subject(), translate=False, icon_value=icon)
layout.label(text=f"{item.width}x{item.height}", translate=False)
layout.label(text=f"{item.steps} steps", translate=False)
layout.label(text=next(x for x in sampler_options if x[0] == item.sampler)[1], translate=False)
if item.prompt_structure_token_subject == "SCENE_UL_HistoryList_header":
layout.label(text="Subject")
layout.label(text="Size")
layout.label(text="Steps")
layout.label(text="Sampler")
else:
layout.label(text=item.get_prompt_subject(), translate=False, icon_value=icon)
layout.label(text=f"{item.width}x{item.height}", translate=False)
layout.label(text=f"{item.steps} steps", translate=False)
layout.label(text=next(x for x in sampler_options if x[0] == item.sampler)[1], translate=False)
elif self.layout_type == 'GRID':
layout.alignment = 'CENTER'
layout.label(text="", icon_value=icon)
Expand All @@ -50,13 +27,12 @@ class RecallHistoryEntry(bpy.types.Operator):

@classmethod
def poll(self, context):
return context.scene.dream_textures_history_selection is not None
return context.scene.dream_textures_history_selection is not None and context.scene.dream_textures_history_selection > 0

def execute(self, context):
selection = context.preferences.addons[StableDiffusionPreferences.bl_idname].preferences.history[context.scene.dream_textures_history_selection]
for prop in selection.__annotations__.keys():
if hasattr(context.scene.dream_textures_prompt, prop):
setattr(context.scene.dream_textures_prompt, prop, getattr(selection, prop))
bpy.ops.shade.dream_texture('INVOKE_DEFAULT')

return {"FINISHED"}
14 changes: 2 additions & 12 deletions prompt_engineering.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,6 @@ def photography_prompt(tokens):
('vehicle', 'Vehicle'),
))

concept_artist_token = PromptToken('concept_artist', 'Concept Artist', (
('blevins', 'Neil Blevins'),
('grimmer', 'Jordan Grimmer'),
('mullins', 'Craig Mullins'),
('rutkowski', 'Greg Rutkowski'),
('shinkai', 'Makoto Shinkai'),
('simonetti', 'Mark Simonetti'),
('stalenhag', 'Simon Stalenhag'),
))

genre_token = PromptToken('genre', 'Genre', (
('scifi', 'Sci-Fi'),
('fantasy', 'Fantasy'),
Expand All @@ -116,12 +106,12 @@ def photography_prompt(tokens):
))

def concept_art_prompt(tokens):
return f"{tokens.subject}, {tokens.subject_type} concept art, {tokens.genre} digital painting, by {tokens.concept_artist}, trending on ArtStation"
return f"{tokens.subject}, {tokens.subject_type} concept art, {tokens.genre} digital painting, trending on ArtStation"

concept_art_structure = PromptStructure(
'concept_art',
'Concept Art',
(subject_token, subject_type_token, genre_token, concept_artist_token),
(subject_token, subject_type_token, genre_token),
concept_art_prompt
)

Expand Down
3 changes: 2 additions & 1 deletion property_groups/dream_prompt.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import bpy
from bpy.props import FloatProperty, IntProperty, EnumProperty, BoolProperty, StringProperty, PointerProperty
from ..prompt_engineering import *
import sys

sampler_options = [
("ddim", "DDIM", "", 1),
Expand Down Expand Up @@ -37,7 +38,7 @@ def seed_clamp(self, ctx):
"show_advanced": BoolProperty(name="", default=False),
"random_seed": BoolProperty(name="Random Seed", default=True, description="Randomly pick a seed"),
"seed": StringProperty(name="Seed", default="0", description="Manually pick a seed", update=seed_clamp),
"full_precision": BoolProperty(name="Full Precision", default=False, description="Whether to use full precision or half precision floats. Full precision is slower, but required by some GPUs"),
"full_precision": BoolProperty(name="Full Precision", default=True if sys.platform == 'darwin' else False, description="Whether to use full precision or half precision floats. Full precision is slower, but required by some GPUs"),
"iterations": IntProperty(name="Iterations", default=1, min=1, description="How many images to generate"),
"steps": IntProperty(name="Steps", default=25, min=1),
"cfg_scale": FloatProperty(name="CFG Scale", default=7.5, min=1, description="How strongly the prompt influences the image"),
Expand Down
Loading