Skip to content

Commit

Permalink
Merge pull request #359 from Capsize-Games/develop
Browse files Browse the repository at this point in the history
Adds version to embedding and lora files fixes #358
  • Loading branch information
w4ffl35 authored Jan 9, 2024
2 parents 170770b + bbd5764 commit 8f94753
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""Adds version to embedding and lora tables
Revision ID: 6d98d892995f
Revises: 55c1dff62eba
Create Date: 2024-01-09 14:40:48.810380
"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = '6d98d892995f'
down_revision: Union[str, None] = '55c1dff62eba'
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! ###
op.add_column('embeddings', sa.Column('version', sa.String(), nullable=True))
op.add_column('loras', sa.Column('version', sa.String(), nullable=True))
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('loras', 'version')
op.drop_column('embeddings', 'version')
# ### end Alembic commands ###
2 changes: 2 additions & 0 deletions src/airunner/data/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class Embedding(BaseModel):
path = Column(String)
tags = Column(String)
active = Column(Boolean, default=True)
version = Column(String, default="SD 1.5")

__table_args__ = (
UniqueConstraint('name', 'path', name='name_path_unique'),
Expand Down Expand Up @@ -302,6 +303,7 @@ class Lora(BaseModel):
enabled = Column(Boolean, default=True)
loaded = Column(Boolean, default=False)
trigger_word = Column(String, default="")
version = Column(String, default="SD 1.5")

@classmethod
def get_all(cls, session):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,14 @@ def scan_for_embeddings(self):
if os.path.exists(embeddings_path):
for root, dirs, _ in os.walk(embeddings_path):
for dir in dirs:
version = dir.split("/")[-1]
path = os.path.join(root, dir)
for entry in os.scandir(path):
if entry.is_file() and entry.name.endswith((".ckpt", ".safetensors", ".pt")):
name = os.path.splitext(entry.name)[0]
embedding = session.query(Embedding).filter_by(name=name).first()
if not embedding:
embedding = Embedding(name=name, path=entry.path)
embedding = Embedding(name=name, path=entry.path, version=version)
session.add(embedding)
session.commit()
self.load_embeddings()
Expand Down
5 changes: 3 additions & 2 deletions src/airunner/widgets/lora/lora_container_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,12 @@ def scan_for_lora(self):
session = get_session()
lora_path = self.settings_manager.path_settings.lora_path
for dirpath, dirnames, filenames in os.walk(lora_path):
# get version from dirpath
version = dirpath.split("/")[-1]
for file in filenames:
if file.endswith(".ckpt") or file.endswith(".safetensors") or file.endswith(".pt"):
print("adding lora to session")
name = file.replace(".ckpt", "").replace(".safetensors", "").replace(".pt", "")
lora = Lora(name=name, path=os.path.join(dirpath, file), enabled=True, scale=100.0)
lora = Lora(name=name, path=os.path.join(dirpath, file), enabled=True, scale=100.0, version=version)
session.add(lora)
save_session(session)

Expand Down

0 comments on commit 8f94753

Please sign in to comment.