Restored image recognition

This commit is contained in:
jeffser 2024-08-30 12:42:48 -06:00
parent 4647e1ba47
commit 0999a64356
2 changed files with 21 additions and 26 deletions

View File

@ -83,6 +83,7 @@ class model_selector_button(Gtk.MenuButton):
elif len(list(listbox)) == 0:
self.get_child().set_label(_("Select a Model"))
self.set_tooltip_text(_("Select a Model"))
window.model_manager.verify_if_image_can_be_used()
def add_model(self, model_name:str):
model_row = Gtk.ListBoxRow(
@ -472,6 +473,23 @@ class model_manager_container(Gtk.Box):
def change_model(self, model_name:str):
self.model_selector.change_model(model_name)
def verify_if_image_can_be_used(self):
logger.debug("Verifying if image can be used")
selected = self.get_selected_model()
if selected == None:
return False
selected = selected.split(":")[0]
with open(os.path.join(source_dir, 'available_models.json'), 'r', encoding="utf-8") as f:
if selected in [key for key, value in json.load(f).items() if value["image"]]:
for name, content in window.attachments.items():
if content['type'] == 'image':
content['button'].set_css_classes(["flat"])
return True
for name, content in window.attachments.items():
if content['type'] == 'image':
content['button'].set_css_classes(["flat", "error"])
return False
#Important: Call this using a thread, if not the app crashes
def pull_model(self, url:str, model_name:str, modelfile:str=None): ##TODO, once you make an instance manager remove the url from this
if ':' not in model_name:

View File

@ -156,8 +156,8 @@ class AlpacaWindow(Adw.ApplicationWindow):
attached_files = {}
for name, content in self.attachments.items():
if content["type"] == 'image':
if self.verify_if_image_can_be_used():
attached_images.append(name)
if self.model_manager.verify_if_image_can_be_used():
attached_images.append(os.path.join(self.data_dir, "chats", current_chat.get_name(), message_id, name))
else:
attached_files[name] = content['type']
if not os.path.exists(os.path.join(self.data_dir, "chats", current_chat.get_name(), message_id)):
@ -322,22 +322,6 @@ class AlpacaWindow(Adw.ApplicationWindow):
self.model_scroller.set_visible(True)
self.no_results_page.set_visible(False)
def verify_if_image_can_be_used(self):
logger.debug("Verifying if image can be used")
selected = self.model_manager.get_selected_model()
if selected == None:
return True
selected = selected.split(":")[0]
if selected in [key for key, value in self.available_models.items() if value["image"]]:
for name, content in self.attachments.items():
if content['type'] == 'image':
content['button'].set_css_classes(["flat"])
return True
for name, content in self.attachments.items():
if content['type'] == 'image':
content['button'].set_css_classes(["flat", "error"])
return False
def convert_model_name(self, name:str, mode:int) -> str: # mode=0 name:tag -> Name (tag) | mode=1 Name (tag) -> name:tag
try:
if mode == 0:
@ -817,7 +801,7 @@ Generate a title following these rules:
try:
texture = clipboard.read_texture_finish(result)
if texture:
if self.verify_if_image_can_be_used():
if self.model_manager.verify_if_image_can_be_used():
pixbuf = Gdk.pixbuf_get_from_texture(texture)
if not os.path.exists(os.path.join(self.cache_dir, 'tmp/images/')):
os.makedirs(os.path.join(self.cache_dir, 'tmp/images/'))
@ -937,11 +921,4 @@ Generate a title following these rules:
self.model_manager.update_local_list()
self.model_manager.update_available_list()
"""
response = connection_handler.simple_get(f"{connection_handler.URL}/api/tags")
self.model_selector.clear_list()
to update local models
"""
self.load_history()