Skip to content

Commit

Permalink
design updates and changes to database
Browse files Browse the repository at this point in the history
  • Loading branch information
w4ffl35 committed Jan 2, 2024
1 parent f56522d commit fd28856
Show file tree
Hide file tree
Showing 30 changed files with 2,057 additions and 2,544 deletions.
18 changes: 12 additions & 6 deletions src/airunner/aihandler/settings_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,22 +201,28 @@ def generator(self):
def llm_generator_setting(self):
llm_generator = session.query(LLMGenerator).filter(LLMGenerator.name == self.current_llm_generator).first()
return llm_generator.generator_settings[0]

_generator = None

def find_generator(self, generator_section, generator_name):
# using sqlalchemy, query the document.settings.generator_settings column
# and find any with GeneratorSettings.section == self.generator_section and GeneratorSettings.generator_name == self.generator_name
# return the first result
generator_settings = session.query(GeneratorSetting).filter_by(
section=generator_section,
generator_name=generator_name
).join(Settings).first()
if self.generator_settings_override_id:
generator_settings = session.query(GeneratorSetting).filter_by(
id=self.generator_settings_override_id
).join(Settings).first()
else:
generator_settings = session.query(GeneratorSetting).filter_by(
section=generator_section,
generator_name=generator_name
).join(Settings).first()
if generator_settings is None:
if not generator_section or generator_section == "" or not generator_name or generator_name == "":
return None
generator_settings = GeneratorSetting(
section=generator_section,
generator_name=generator_name,
settings_id=document.settings.id,
generator_name=generator_name
)
session.add(generator_settings)
session.commit()
Expand Down
30 changes: 30 additions & 0 deletions src/airunner/alembic/versions/1bbf5fc3748c_added_brushes_tabel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""added brushes tabel
Revision ID: 1bbf5fc3748c
Revises: 08fb52568b41
Create Date: 2023-12-31 10:23:02.460956
"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = '1bbf5fc3748c'
down_revision: Union[str, None] = '08fb52568b41'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
pass
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
pass
# ### end Alembic commands ###
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""Added generator_settings_override_id to settings
Revision ID: 28d612bd908c
Revises: 1bbf5fc3748c
Create Date: 2024-01-01 15:34:54.674668
"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = '28d612bd908c'
down_revision: Union[str, None] = '1bbf5fc3748c'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
with op.batch_alter_table("brushes") as batch_op:
#batch_op.drop_constraint('generator_setting_id', type_='foreignkey')
batch_op.drop_column('generator_setting_id')

with op.batch_alter_table("generator_settings") as batch_op:
#batch_op.drop_constraint('settings_id', type_='foreignkey')
batch_op.drop_column('settings_id')

with op.batch_alter_table("settings") as batch_op:
batch_op.create_foreign_key('settings_id', 'generator_settings', ['generator_settings_override_id'], ['id'])
batch_op.drop_column('current_section_shape')
batch_op.drop_column('current_version_kandinsky')
batch_op.drop_column('current_section_kandinsky')


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('settings', sa.Column('current_section_kandinsky', sa.VARCHAR(), nullable=True))
op.add_column('settings', sa.Column('current_version_kandinsky', sa.VARCHAR(), nullable=True))
op.add_column('settings', sa.Column('current_section_shape', sa.VARCHAR(), nullable=True))
op.drop_constraint(None, 'settings', type_='foreignkey')
op.add_column('generator_settings', sa.Column('settings_id', sa.INTEGER(), nullable=True))
op.create_foreign_key(None, 'generator_settings', 'settings', ['settings_id'], ['id'])
op.add_column('brushes', sa.Column('generator_setting_id', sa.INTEGER(), nullable=True))
op.create_foreign_key(None, 'brushes', 'prompt_generator_settings', ['generator_setting_id'], ['id'])
# ### end Alembic commands ###
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""Fixes brush link to generator settings
Revision ID: 6f4472b84071
Revises: d25b0e141c27
Create Date: 2024-01-01 15:49:27.635195
"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = '6f4472b84071'
down_revision: Union[str, None] = 'd25b0e141c27'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
pass
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
pass
# ### end Alembic commands ###
32 changes: 32 additions & 0 deletions src/airunner/alembic/versions/d25b0e141c27_added_ids.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""Added ids
Revision ID: d25b0e141c27
Revises: 28d612bd908c
Create Date: 2024-01-01 15:45:14.216904
"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = 'd25b0e141c27'
down_revision: Union[str, None] = '28d612bd908c'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
with op.batch_alter_table("brushes") as batch_op:
batch_op.add_column(sa.Column('generator_setting_id', sa.Integer(), nullable=True))
batch_op.create_foreign_key('fk_brushes_generator_setting_id', 'generator_settings', ['generator_setting_id'], ['id'])

# rest of your code


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
pass
# ### end Alembic commands ###
17 changes: 16 additions & 1 deletion src/airunner/data/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,6 @@ class GeneratorSetting(BaseModel):
id = Column(Integer, primary_key=True)
section = Column(String)
generator_name = Column(String)
settings_id = Column(Integer, ForeignKey('settings.id'))
prompt = Column(String, default="")
negative_prompt = Column(String, default="")
steps = Column(Integer, default=20)
Expand Down Expand Up @@ -356,6 +355,18 @@ class GeneratorSetting(BaseModel):
use_prompt_builder = Column(Boolean, default=False)
active_grid_border_color = Column(String, default="#00FF00")
active_grid_fill_color = Column(String, default="#FF0000")
brushes = relationship("Brush", back_populates='generator_setting') # modified line


class Brush(BaseModel):
__tablename__ = 'brushes'

id = Column(Integer, primary_key=True)
name = Column(String, nullable=False)
thumbnail = Column(String, nullable=False)
generator_setting_id = Column(Integer, ForeignKey('generator_settings.id')) # new line
generator_setting = relationship('GeneratorSetting', back_populates='brushes') # modified line



class PromptGeneratorSetting(BaseModel):
Expand Down Expand Up @@ -648,6 +659,8 @@ class Settings(BaseModel):

enable_tts = Column(Boolean, default=True)

generator_settings_override_id = Column(Integer, ForeignKey('generator_settings.id'))


class StandardImageWidgetSettings(BaseModel):
__tablename__ = 'standard_image_widget_settings'
Expand Down Expand Up @@ -812,3 +825,5 @@ class Message(BaseModel):
message = Column(String)
conversation_id = Column(Integer, ForeignKey('conversation.id'))
conversation = relationship('Conversation', back_populates='messages')


18 changes: 10 additions & 8 deletions src/airunner/widgets/base_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@ def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.app = get_main_window()
self.settings_manager = SettingsManager()
self.ui = self.widget_class_()
self.ui.setupUi(self)
if self.qss_filename:
theme_name = "dark_theme"
here = os.path.dirname(os.path.realpath(__file__))
with open(os.path.join(here, "..", "styles", theme_name, self.qss_filename), "r") as f:
stylesheet = f.read()
self.setStyleSheet(stylesheet)
if self.widget_class_:
self.ui = self.widget_class_()
if self.ui:
self.ui.setupUi(self)
if self.qss_filename:
theme_name = "dark_theme"
here = os.path.dirname(os.path.realpath(__file__))
with open(os.path.join(here, "..", "styles", theme_name, self.qss_filename), "r") as f:
stylesheet = f.read()
self.setStyleSheet(stylesheet)

def set_stylesheet(self, is_dark=None, button_name=None, icon=None):
is_dark = self.is_dark if is_dark is None else is_dark
Expand Down
1 change: 0 additions & 1 deletion src/airunner/widgets/brush/brush_container_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ class BrushContainerWidget(BaseWidget):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
print(self.settings_manager.brush_settings.size)
self.ui.brush_size_slider.setProperty("current_value", self.settings_manager.brush_settings.size)
self.ui.brush_size_slider.initialize()
Loading

0 comments on commit fd28856

Please sign in to comment.