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

Devastator #957

Merged
merged 4 commits into from
Oct 26, 2024
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
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="airunner",
version="3.1.4",
version="3.1.5",
author="Capsize LLC",
description="A Stable Diffusion GUI",
long_description=open("README.md", "r", encoding="utf-8").read(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from typing import Sequence, Union
import os

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import sqlite

# revision identifiers, used by Alembic.
revision: str = '75020956e3e2'
down_revision: Union[str, None] = '26a0d29a3af3'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None

def convert_image_to_binary(image_path):
with open(image_path, 'rb') as file:
binary_data = file.read()
return binary_data

def upgrade():
try:
op.create_table(
'users',
sa.Column('id', sa.Integer, primary_key=True, autoincrement=True),
sa.Column('username', sa.String, nullable=False),
)
op.execute(
sa.text("INSERT INTO users (username) VALUES ('User')")
)
except Exception as e:
print(f"Error during upgrade: {e}")

try:
op.drop_column('chatbots', 'username')
except Exception as e:
print(f"Column already dropped: {e}")

def downgrade():
try:
op.add_column('chatbots', sa.Column('username', sa.String, nullable=True))
except Exception as e:
print(f"Column already exists: {e}")

try:
op.drop_table('users')
except Exception as e:
print(f"Table already dropped: {e}")
# ### end Alembic commands ###
7 changes: 6 additions & 1 deletion src/airunner/data/models/settings_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,6 @@ class Chatbot(Base):
__tablename__ = 'chatbots'
id = Column(Integer, primary_key=True, autoincrement=True)
name = Column(String, default="Chatbot")
username = Column(String, default="User")
botname = Column(String, default="Computer")
use_personality = Column(Boolean, default=True)
use_mood = Column(Boolean, default=True)
Expand Down Expand Up @@ -390,6 +389,12 @@ class Chatbot(Base):
messages = relationship("Message", back_populates="chatbot")


class User(Base):
__tablename__ = 'users'
id = Column(Integer, primary_key=True, autoincrement=True)
username = Column(String, nullable=False)


class TargetFiles(Base):
__tablename__ = 'target_files'
id = Column(Integer, primary_key=True, autoincrement=True)
Expand Down
4 changes: 2 additions & 2 deletions src/airunner/handlers/llm/agent/base_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def available_actions(self):

@property
def username(self) -> str:
return self.chatbot.username
return self.user.username

@property
def botname(self) -> str:
Expand Down Expand Up @@ -327,7 +327,7 @@ def build_system_prompt(
use_guardrails = self.chatbot.use_guardrails
bot_mood = self.bot_mood
bot_personality = self.chatbot.bot_personality
username = self.chatbot.username
username = self.user.username
botname = self.chatbot.botname
if use_system_instructions:
system_instructions = self.chatbot.system_instructions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,7 @@ def chat_template(self):

@property
def username(self):
if self.chatbot.assign_names:
return self.chatbot.username
return "User"
return self.user.username

@property
def botname(self):
Expand Down
4 changes: 4 additions & 0 deletions src/airunner/styles/dark_theme/styles.qss
Original file line number Diff line number Diff line change
Expand Up @@ -752,3 +752,7 @@ QScrollArea#chat_container #message_container QPushButton:hover {
background-color: #000;
border: 1px solid #1f1f1f;
}

#image {
border: 1px solid #1f1f1f;
}
13 changes: 13 additions & 0 deletions src/airunner/utils/convert_pil_to_qimage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from PIL import Image
from PIL.ImageQt import QImage


def pil_to_qimage(pil_image):
if pil_image.mode == "RGB":
r, g, b = pil_image.split()
pil_image = Image.merge("RGBA", (r, g, b, Image.new("L", r.size, 255)))
elif pil_image.mode == "L":
pil_image = pil_image.convert("RGBA")
data = pil_image.tobytes("raw", "RGBA")
qimage = QImage(data, pil_image.size[0], pil_image.size[1], QImage.Format.Format_RGBA8888)
return qimage
9 changes: 9 additions & 0 deletions src/airunner/utils/convert_pil_to_qpixmap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from PIL.ImageQt import QPixmap

from airunner.utils.convert_pil_to_qimage import pil_to_qimage


def convert_pil_to_qpixmap(image):
qimage = pil_to_qimage(image)
pixmap = QPixmap.fromImage(qimage)
return pixmap
3 changes: 0 additions & 3 deletions src/airunner/utils/toggle_signals.py

This file was deleted.

13 changes: 6 additions & 7 deletions src/airunner/widgets/llm/bot_preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from airunner.data.models.settings_models import TargetFiles, Chatbot
from airunner.enums import SignalCode
from airunner.utils.open_file_path import open_file_path
from airunner.utils.toggle_signals import toggle_signals
from airunner.widgets.base_widget import BaseWidget
from airunner.widgets.llm.document_widget import DocumentWidget
from airunner.widgets.llm.templates.bot_preferences_ui import Ui_bot_preferences
Expand All @@ -22,7 +21,6 @@ def showEvent(self, event):

def load_form_elements(self):
elements = [
"username",
"botname",
"bot_personality",
"names_groupbox",
Expand All @@ -33,8 +31,7 @@ def load_form_elements(self):
"guardrails_groupbox",
"target_files",
]
toggle_signals(self.ui, elements)
self.ui.username.setText(self.chatbot.username)
self.toggle_signals(self.ui, elements)
self.ui.botname.setText(self.chatbot.botname)
self.ui.bot_personality.setPlainText(self.chatbot.bot_personality)
self.ui.names_groupbox.setChecked(self.chatbot.assign_names)
Expand All @@ -44,10 +41,12 @@ def load_form_elements(self):
self.ui.guardrails_prompt.setPlainText(self.chatbot.guardrails_prompt)
self.ui.guardrails_groupbox.setChecked(self.chatbot.use_guardrails)
self.load_documents()
toggle_signals(self.ui, elements, False)
self.toggle_signals(self.ui, elements, False)

def username_changed(self, val):
self.update_chatbot("username", val)
@staticmethod
def toggle_signals(ui: object, elements: list, block: bool = True):
for element in elements:
getattr(ui, element).blockSignals(block)

def botname_changed(self, val):
self.update_chatbot("botname", val)
Expand Down
10 changes: 8 additions & 2 deletions src/airunner/widgets/llm/chat_prompt_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def do_generate(self, image_override=None, prompt_override=None, callback=None,
self.generating = True

widget = self.add_message_to_conversation(
name=self.chatbot.username,
name=self.user.username,
message=self.prompt,
is_bot=False
)
Expand Down Expand Up @@ -338,7 +338,13 @@ def add_message_to_conversation(

widget = None
if message != "":
widget = MessageWidget(name=name, message=message, is_bot=is_bot, message_id=message_id, conversation_id=self.conversation_id)
widget = MessageWidget(
name=name,
message=message,
is_bot=is_bot,
message_id=message_id,
conversation_id=self.conversation_id
)
self.ui.scrollAreaWidgetContents.layout().addWidget(widget)

self.add_spacer()
Expand Down
2 changes: 2 additions & 0 deletions src/airunner/widgets/llm/llm_history_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ def load_conversations(self):
self.ui.scrollAreaWidgetContents.setLayout(layout)

for conversation in conversations:
if conversation.title == "":
continue
llm_history_item_widget = LLMHistoryItemWidget(
conversation=conversation
)
Expand Down
6 changes: 3 additions & 3 deletions src/airunner/widgets/llm/message_widget.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from airunner.data.models.settings_models import Message, Conversation
from airunner.data.models.settings_models import Message
from airunner.enums import SignalCode
from airunner.widgets.base_widget import BaseWidget
from airunner.widgets.llm.templates.message_ui import Ui_message

from PySide6.QtGui import QTextCursor, QFontDatabase, QFont
from PySide6.QtGui import QFontDatabase, QFont
from PySide6.QtWidgets import QTextEdit, QApplication, QWidget
from PySide6.QtGui import QFontMetrics
from PySide6.QtCore import Qt, QSize, Slot, QEvent, QTimer
from PySide6.QtCore import Qt, QSize, Slot, QEvent
from PySide6.QtCore import Signal


Expand Down
53 changes: 5 additions & 48 deletions src/airunner/widgets/llm/templates/bot_preferences.ui
Original file line number Diff line number Diff line change
Expand Up @@ -166,32 +166,6 @@
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="QLabel" name="label_3">
<property name="font">
<font>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>User name</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="username">
<property name="text">
<string>User</string>
</property>
<property name="placeholderText">
<string>User name</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
Expand Down Expand Up @@ -353,22 +327,6 @@
</widget>
<resources/>
<connections>
<connection>
<sender>username</sender>
<signal>textChanged(QString)</signal>
<receiver>bot_preferences</receiver>
<slot>username_changed(QString)</slot>
<hints>
<hint type="sourcelabel">
<x>674</x>
<y>460</y>
</hint>
<hint type="destinationlabel">
<x>55</x>
<y>0</y>
</hint>
</hints>
</connection>
<connection>
<sender>botname</sender>
<signal>textChanged(QString)</signal>
Expand All @@ -392,8 +350,8 @@
<slot>bot_personality_changed()</slot>
<hints>
<hint type="sourcelabel">
<x>392</x>
<y>971</y>
<x>404</x>
<y>1105</y>
</hint>
<hint type="destinationlabel">
<x>292</x>
Expand Down Expand Up @@ -425,7 +383,7 @@
<hints>
<hint type="sourcelabel">
<x>108</x>
<y>916</y>
<y>995</y>
</hint>
<hint type="destinationlabel">
<x>0</x>
Expand All @@ -440,8 +398,8 @@
<slot>guardrails_prompt_changed()</slot>
<hints>
<hint type="sourcelabel">
<x>202</x>
<y>765</y>
<x>214</x>
<y>836</y>
</hint>
<hint type="destinationlabel">
<x>1</x>
Expand Down Expand Up @@ -579,7 +537,6 @@
</connection>
</connections>
<slots>
<slot>username_changed(QString)</slot>
<slot>botname_changed(QString)</slot>
<slot>bot_personality_changed()</slot>
<slot>toggle_use_names(bool)</slot>
Expand Down
20 changes: 0 additions & 20 deletions src/airunner/widgets/llm/templates/bot_preferences_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,22 +103,6 @@ def setupUi(self, bot_preferences):

self.horizontalLayout.addLayout(self.verticalLayout_6)

self.verticalLayout_5 = QVBoxLayout()
self.verticalLayout_5.setObjectName(u"verticalLayout_5")
self.label_3 = QLabel(self.names_groupbox)
self.label_3.setObjectName(u"label_3")
self.label_3.setFont(font)

self.verticalLayout_5.addWidget(self.label_3)

self.username = QLineEdit(self.names_groupbox)
self.username.setObjectName(u"username")

self.verticalLayout_5.addWidget(self.username)


self.horizontalLayout.addLayout(self.verticalLayout_5)


self.gridLayout.addWidget(self.names_groupbox, 3, 0, 1, 1)

Expand Down Expand Up @@ -213,7 +197,6 @@ def setupUi(self, bot_preferences):


self.retranslateUi(bot_preferences)
self.username.textChanged.connect(bot_preferences.username_changed)
self.botname.textChanged.connect(bot_preferences.botname_changed)
self.bot_personality.textChanged.connect(bot_preferences.bot_personality_changed)
self.names_groupbox.toggled.connect(bot_preferences.toggle_use_names)
Expand Down Expand Up @@ -242,9 +225,6 @@ def retranslateUi(self, bot_preferences):
self.label.setText(QCoreApplication.translate("bot_preferences", u"Assistant name", None))
self.botname.setText(QCoreApplication.translate("bot_preferences", u"AI Runner", None))
self.botname.setPlaceholderText(QCoreApplication.translate("bot_preferences", u"Bot name", None))
self.label_3.setText(QCoreApplication.translate("bot_preferences", u"User name", None))
self.username.setText(QCoreApplication.translate("bot_preferences", u"User", None))
self.username.setPlaceholderText(QCoreApplication.translate("bot_preferences", u"User name", None))
self.guardrails_groupbox.setTitle(QCoreApplication.translate("bot_preferences", u"Guardrails", None))
self.guardrails_prompt.setPlaceholderText(QCoreApplication.translate("bot_preferences", u"The guardrails prompt is used to moderate results.", None))
self.groupBox.setTitle(QCoreApplication.translate("bot_preferences", u"Existing Agents", None))
Expand Down
8 changes: 4 additions & 4 deletions src/airunner/widgets/llm/templates/message.ui
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@
<slot>delete()</slot>
<hints>
<hint type="sourcelabel">
<x>435</x>
<y>19</y>
<x>485</x>
<y>30</y>
</hint>
<hint type="destinationlabel">
<x>391</x>
Expand All @@ -163,8 +163,8 @@
<slot>copy()</slot>
<hints>
<hint type="sourcelabel">
<x>469</x>
<y>28</y>
<x>452</x>
<y>34</y>
</hint>
<hint type="destinationlabel">
<x>451</x>
Expand Down
Loading