6 Commits
0.9.5 ... 0.9.6

Author SHA1 Message Date
jeffser
5f0cddffd0 Getting ready for 0.9.6 2024-06-21 17:22:46 -06:00
jeffser
6fdf335412 Merge branch 'main' of github.com-jeffser:Jeffser/Alpaca 2024-06-21 17:17:16 -06:00
jeffser
3db0a374e6 Added compatibility for docx and pdf 2024-06-21 17:16:59 -06:00
Théo FORTIN
aa6d317321 Fix french typos (#105) 2024-06-21 15:36:09 -06:00
Jeffry Samuel
37702a2527 :( 2024-06-07 19:17:39 -06:00
Louis Chauvet-Villaret
ccb19516bb FR update (#95) 2024-06-05 11:54:41 -06:00
15 changed files with 1222 additions and 1095 deletions

View File

@@ -43,9 +43,6 @@ Code highlighting | Chatting with models | Managing models
## Ollama session tips ## Ollama session tips
### Migrate Ollama session to Alpaca's integrated session
For now Alpaca doesn't offer a way to do this from the GUI but it's really simple, when you are using Ollama it creates a folder in the home directory called `.ollama`, you just need to move that folder to `~/.var/app/com.jeffser.Alpaca/data/`
### Change the port of the integrated Ollama instance ### Change the port of the integrated Ollama instance
Go to `~/.var/app/com.jeffser.Alpaca/config/server.json` and change the `"local_port"` value, by default it is `11435`. Go to `~/.var/app/com.jeffser.Alpaca/config/server.json` and change the `"local_port"` value, by default it is `11435`.

View File

@@ -71,6 +71,44 @@
} }
] ]
}, },
{
"name": "python3-pypdf",
"buildsystem": "simple",
"build-commands": [
"pip3 install --verbose --exists-action=i --no-index --find-links=\"file://${PWD}\" --prefix=${FLATPAK_DEST} \"pypdf\" --no-build-isolation"
],
"sources": [
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/c9/d1/450b19bbdbb2c802f554312c62ce2a2c0d8744fe14735bc70ad2803578c7/pypdf-4.2.0-py3-none-any.whl",
"sha256": "dc035581664e0ad717e3492acebc1a5fc23dba759e788e3d4a9fc9b1a32e72c1"
}
]
},
{
"name": "python3-python-docx",
"buildsystem": "simple",
"build-commands": [
"pip3 install --verbose --exists-action=i --no-index --find-links=\"file://${PWD}\" --prefix=${FLATPAK_DEST} \"python-docx\" --no-build-isolation"
],
"sources": [
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/63/f7/ffbb6d2eb67b80a45b8a0834baa5557a14a5ffce0979439e7cd7f0c4055b/lxml-5.2.2.tar.gz",
"sha256": "bb2dc4898180bea79863d5487e5f9c7c34297414bad54bcd0f0852aee9cfdb87"
},
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/3e/3d/330d9efbdb816d3f60bf2ad92f05e1708e4a1b9abe80461ac3444c83f749/python_docx-1.1.2-py3-none-any.whl",
"sha256": "08c20d6058916fb19853fcf080f7f42b6270d89eac9fa5f8c15f691c0017fabe"
},
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/26/9f/ad63fc0248c5379346306f8668cda6e2e2e9c95e01216d2b8ffd9ff037d0/typing_extensions-4.12.2-py3-none-any.whl",
"sha256": "04e5ca0351e0f3f85c6853954072df659d0d13fac324d0072316b67d7794700d"
}
]
},
{ {
"name": "ollama", "name": "ollama",
"buildsystem": "simple", "buildsystem": "simple",

View File

@@ -64,6 +64,17 @@
<url type="homepage">https://github.com/Jeffser/Alpaca</url> <url type="homepage">https://github.com/Jeffser/Alpaca</url>
<url type="donation">https://github.com/sponsors/Jeffser</url> <url type="donation">https://github.com/sponsors/Jeffser</url>
<releases> <releases>
<release version="0.9.6" date="2024-06-21">
<url type="details">https://github.com/Jeffser/Alpaca/releases/tag/0.9.6</url>
<description>
<p>Big Update</p>
<ul>
<li>Added compatibility for PDF</li>
<li>Added compatibility for DOCX</li>
<li>Merged 'file attachment' menu into one button</li>
</ul>
</description>
</release>
<release version="0.9.5" date="2024-06-04"> <release version="0.9.5" date="2024-06-04">
<url type="details">https://github.com/Jeffser/Alpaca/releases/tag/0.9.5</url> <url type="details">https://github.com/Jeffser/Alpaca/releases/tag/0.9.5</url>
<description> <description>

View File

@@ -1,5 +1,5 @@
project('Alpaca', 'c', project('Alpaca', 'c',
version: '0.9.5', version: '0.9.6',
meson_version: '>= 0.62.0', meson_version: '>= 0.62.0',
default_options: [ 'warning_level=2', 'werror=false', ], default_options: [ 'warning_level=2', 'werror=false', ],
) )

File diff suppressed because it is too large Load Diff

497
po/es.po

File diff suppressed because it is too large Load Diff

View File

@@ -7,7 +7,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-06-04 20:08-0600\n" "POT-Creation-Date: 2024-06-04 20:09-0600\n"
"PO-Revision-Date: 2024-05-19 19:44-0600\n" "PO-Revision-Date: 2024-05-19 19:44-0600\n"
"Last-Translator: Jeffry Samuel Eduarte Rojas <jeffrysamuer@gmail.com>\n" "Last-Translator: Jeffry Samuel Eduarte Rojas <jeffrysamuer@gmail.com>\n"
"Language-Team: Spanish <es@tp.org.es>\n" "Language-Team: Spanish <es@tp.org.es>\n"
@@ -107,6 +107,16 @@ msgstr "Gestionando modelos"
msgid "Quick Fix" msgid "Quick Fix"
msgstr "Arreglo rápido" msgstr "Arreglo rápido"
#: data/com.jeffser.Alpaca.metainfo.xml.in:71
msgid ""
"There were some errors when transitioning from the old version of chats to "
"the new version. I apologize if this caused any corruption in your chat "
"history. This should be the only time such a transition is needed."
msgstr ""
"Hubieron unos errores mientras los chats transicionaban a la nueva versión. "
"Pido disculpas si eso causo alguna corrupción en to historial de chats. "
"Esta debería de ser la única vez que una transición es necesaria"
#: data/com.jeffser.Alpaca.metainfo.xml.in:77 #: data/com.jeffser.Alpaca.metainfo.xml.in:77
#: data/com.jeffser.Alpaca.metainfo.xml.in:229 #: data/com.jeffser.Alpaca.metainfo.xml.in:229
#, fuzzy #, fuzzy

553
po/fr.po

File diff suppressed because it is too large Load Diff

View File

@@ -6,21 +6,22 @@
# to chat discuter # to chat discuter
# a chat une discussion # a chat une discussion
# template template # template template
# # Louis Chauvet-Villaret <louischauvet0@gmail.com>, 2024.
# #
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: 0.8.7\n" "Project-Id-Version: 0.8.7\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-06-04 20:08-0600\n" "POT-Creation-Date: 2024-06-04 20:09-0600\n"
"PO-Revision-Date: 2024-06-02 12:54+0200\n" "PO-Revision-Date: 2024-06-05 11:06+0200\n"
"Last-Translator: Louis Chauvet-Villaret <louischauvet0@gmail.com>\n" "Last-Translator: Louis Chauvet-Villaret <louischauvet0@gmail.com>\n"
"Language-Team: \n" "Language-Team: French\n"
"Language: fr\n" "Language: fr\n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 3.4.4\n" "X-Generator: Gtranslator 46.1\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
#: data/com.jeffser.Alpaca.desktop.in:3 #: data/com.jeffser.Alpaca.desktop.in:3
#: data/com.jeffser.Alpaca.metainfo.xml.in:7 #: data/com.jeffser.Alpaca.metainfo.xml.in:7
@@ -64,7 +65,7 @@ msgstr "Reconnaissance d'image (modèles compatibles)"
#: data/com.jeffser.Alpaca.metainfo.xml.in:18 #: data/com.jeffser.Alpaca.metainfo.xml.in:18
msgid "Plain text documents recognition" msgid "Plain text documents recognition"
msgstr "" msgstr "Reconnaissance de documents en texte brut"
#: data/com.jeffser.Alpaca.metainfo.xml.in:19 #: data/com.jeffser.Alpaca.metainfo.xml.in:19
msgid "Import and export chats" msgid "Import and export chats"
@@ -105,27 +106,36 @@ msgstr "Gestion des modèles"
msgid "Quick Fix" msgid "Quick Fix"
msgstr "Petite correction de bogues" msgstr "Petite correction de bogues"
#: data/com.jeffser.Alpaca.metainfo.xml.in:71
msgid ""
"There were some errors when transitioning from the old version of chats to "
"the new version. I apologize if this caused any corruption in your chat "
"history. This should be the only time such a transition is needed."
msgstr ""
"Résolu : il y avait quelques erreurs lors de la transition de l'ancienne "
"version des discussions vers la nouvelle. Nous nous excusons si cela a "
"corrompu votre historique de discussion. Cela devrait être la seule fois "
"qu'une telle modification ait lieu."
#: data/com.jeffser.Alpaca.metainfo.xml.in:77 #: data/com.jeffser.Alpaca.metainfo.xml.in:77
#: data/com.jeffser.Alpaca.metainfo.xml.in:229 #: data/com.jeffser.Alpaca.metainfo.xml.in:229
msgid "Huge Update" msgid "Huge Update"
msgstr "Mise à jour majeure" msgstr "Mise à jour majeure"
#: data/com.jeffser.Alpaca.metainfo.xml.in:79 #: data/com.jeffser.Alpaca.metainfo.xml.in:79
#, fuzzy
msgid "Added: Support for plain text files" msgid "Added: Support for plain text files"
msgstr "Ajouté : support de la personnalisation et création de modèles" msgstr "Ajouté : support des documents de type texte brut"
#: data/com.jeffser.Alpaca.metainfo.xml.in:80 #: data/com.jeffser.Alpaca.metainfo.xml.in:80
msgid "Added: New backend system for storing messages" msgid "Added: New backend system for storing messages"
msgstr "" msgstr "Ajouté : nouveau système en arrière-plan de sauvegarde des messages"
#: data/com.jeffser.Alpaca.metainfo.xml.in:81 #: data/com.jeffser.Alpaca.metainfo.xml.in:81
#, fuzzy #, fuzzy
msgid "Added: Support for changing Ollama's overrides" msgid "Added: Support for changing Ollama's overrides"
msgstr "Ajouté : support de la personnalisation et création de modèles" msgstr "Ajouté : support pour changer les paramètres d'Ollama"
#: data/com.jeffser.Alpaca.metainfo.xml.in:82 #: data/com.jeffser.Alpaca.metainfo.xml.in:82
#, fuzzy
msgid "General Optimization" msgid "General Optimization"
msgstr "Optimisation générale" msgstr "Optimisation générale"
@@ -147,8 +157,8 @@ msgstr "Ajouté : support de la personnalisation et création de modèles"
#: data/com.jeffser.Alpaca.metainfo.xml.in:93 #: data/com.jeffser.Alpaca.metainfo.xml.in:93
msgid "Fixed: Icons don't appear on non Gnome systems" msgid "Fixed: Icons don't appear on non Gnome systems"
msgstr "" msgstr ""
"Résolu : certains icônes n'apparaissait pas sur les systèmes ne fonctionnant " "Résolu : certaines icônes n'apparaissait pas sur les systèmes ne "
"pas avec le bureau Gnome" "fonctionnant pas avec le bureau Gnome"
#: data/com.jeffser.Alpaca.metainfo.xml.in:94 #: data/com.jeffser.Alpaca.metainfo.xml.in:94
msgid "Update Ollama to v0.1.39" msgid "Update Ollama to v0.1.39"
@@ -717,9 +727,8 @@ msgstr ""
"réinitialisée" "réinitialisée"
#: src/window.py:124 #: src/window.py:124
#, fuzzy
msgid "Image recognition is only available on specific models" msgid "Image recognition is only available on specific models"
msgstr "Reconnaissance d'image (modèles compatibles)" msgstr "La reconnaissance d'image est seulement disponible sur certains modèles"
#: src/window.py:127 #: src/window.py:127
msgid "Please select a model before chatting" msgid "Please select a model before chatting"
@@ -742,9 +751,8 @@ msgid "Code copied to the clipboard"
msgstr "Code copié dans le presse-papier" msgstr "Code copié dans le presse-papier"
#: src/window.py:132 #: src/window.py:132
#, fuzzy
msgid "Message copied to the clipboard" msgid "Message copied to the clipboard"
msgstr "Code copié dans le presse-papier" msgstr "Message copié dans le presse-papier"
#: src/window.py:135 #: src/window.py:135
msgid "Model deleted successfully" msgid "Model deleted successfully"
@@ -776,7 +784,7 @@ msgstr "Téléchargement en arrière-plan..."
#: src/window.py:788 #: src/window.py:788
msgid "Task Complete" msgid "Task Complete"
msgstr "Tache terminée" msgstr "Tâche terminée"
#: src/window.py:788 #: src/window.py:788
msgid "Model '{}' pulled successfully." msgid "Model '{}' pulled successfully."
@@ -809,10 +817,9 @@ msgstr "Menu"
#: src/window.ui:197 #: src/window.ui:197
msgid "Attach file" msgid "Attach file"
msgstr "" msgstr "Ajouter un fichier"
#: src/window.ui:243 #: src/window.ui:243
#, fuzzy
msgid "Send message" msgid "Send message"
msgstr "Envoyer le message" msgstr "Envoyer le message"
@@ -854,7 +861,7 @@ msgstr "Exécution en arrière-plan"
#: src/window.ui:329 #: src/window.ui:329
msgid "Model" msgid "Model"
msgstr "" msgstr "Modèle"
#: src/window.ui:333 #: src/window.ui:333
msgid "Model Tweaks" msgid "Model Tweaks"
@@ -903,20 +910,23 @@ msgstr ""
"temps demandé en minutes. (défaut : 5)" "temps demandé en minutes. (défaut : 5)"
#: src/window.ui:387 #: src/window.ui:387
#, fuzzy
msgid "Ollama Instance" msgid "Ollama Instance"
msgstr "Ollama pré-intégré" msgstr "Instance d'Ollama"
# What is override ???
#: src/window.ui:391 #: src/window.ui:391
#, fuzzy #, fuzzy
msgid "Ollama Overrides" msgid "Ollama Overrides"
msgstr "Site web d'Ollama" msgstr "Paramètres d'Ollama"
#: src/window.ui:392 #: src/window.ui:392
msgid "" msgid ""
"Manage the arguments used on Ollama, any changes on this page only applies " "Manage the arguments used on Ollama, any changes on this page only applies "
"to the integrated instance, the instance will restart if you make changes" "to the integrated instance, the instance will restart if you make changes"
msgstr "" msgstr ""
"Gérer les arguments utilisés par Ollama. Tous les changements sur cette page "
"s'appliquent seulement à l'instance intégré. L'instance va redémarrer si "
"vous effectuez des changements."
#: src/window.ui:472 #: src/window.ui:472
msgid "Create" msgid "Create"
@@ -947,7 +957,7 @@ msgid ""
"Some models require a specific template. Please visit the model's website " "Some models require a specific template. Please visit the model's website "
"for more information if you're unsure." "for more information if you're unsure."
msgstr "" msgstr ""
"Certain modèle requiert un template spécifique. Merci de visiter le site du " "Certains modèles requièrent un format spécifique. Merci de visiter le site du "
"modèle pour plus d'information." "modèle pour plus d'information."
#: src/window.ui:700 #: src/window.ui:700
@@ -974,8 +984,8 @@ msgid ""
msgstr "" msgstr ""
"Alpaca et ses développeurs ne sont pas responsables des dommages causés à " "Alpaca et ses développeurs ne sont pas responsables des dommages causés à "
"votre appareil ou vos logiciels suite à l'exécution de code généré par un " "votre appareil ou vos logiciels suite à l'exécution de code généré par un "
"modèle. Merci de faire attention et de relire attentivement le code avant de " "modèle. Merci de faire attention et de relire attentivement le code avant "
"l'exécuter." "de l'exécuter."
#: src/window.ui:775 #: src/window.ui:775
msgid "Featured Models" msgid "Featured Models"
@@ -1029,15 +1039,15 @@ msgstr "Importer une discussion"
#: src/window.ui:897 #: src/window.ui:897
msgid "From existing model" msgid "From existing model"
msgstr "" msgstr "Depuis un modèle existant"
#: src/window.ui:901 #: src/window.ui:901
msgid "From GGUF file (Testing)" msgid "From GGUF file (Testing)"
msgstr "" msgstr "Depuis un fichier GGUF (Instable)"
#: src/window.ui:909 #: src/window.ui:909
msgid "Plain text file" msgid "Plain text file"
msgstr "" msgstr "Fichier texte brut"
#: src/window.ui:913 #: src/window.ui:913
msgid "Image" msgid "Image"
@@ -1079,7 +1089,7 @@ msgstr "Envoyer le message"
#~ msgstr "Charger une image" #~ msgstr "Charger une image"
#~ msgid "Only available on selected models" #~ msgid "Only available on selected models"
#~ msgstr "Non-disponible sur ce modèle" #~ msgstr "Disponible uniquement sur certains modèles"
#~ msgid "Advanced Model Settings" #~ msgid "Advanced Model Settings"
#~ msgstr "Paramètres avancés" #~ msgstr "Paramètres avancés"

File diff suppressed because it is too large Load Diff

View File

@@ -3,7 +3,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-06-04 20:08-0600\n" "POT-Creation-Date: 2024-06-04 20:09-0600\n"
"PO-Revision-Date: 2024-05-23 23:29-0600\n" "PO-Revision-Date: 2024-05-23 23:29-0600\n"
"Last-Translator: Daimar Stein <daimarstein@pm.me>\n" "Last-Translator: Daimar Stein <daimarstein@pm.me>\n"
"Language-Team: \n" "Language-Team: \n"
@@ -103,6 +103,13 @@ msgstr "Gerenciando modelos"
msgid "Quick Fix" msgid "Quick Fix"
msgstr "Consertos Rápidos" msgstr "Consertos Rápidos"
#: data/com.jeffser.Alpaca.metainfo.xml.in:71
msgid ""
"There were some errors when transitioning from the old version of chats to "
"the new version. I apologize if this caused any corruption in your chat "
"history. This should be the only time such a transition is needed."
msgstr ""
#: data/com.jeffser.Alpaca.metainfo.xml.in:77 #: data/com.jeffser.Alpaca.metainfo.xml.in:77
#: data/com.jeffser.Alpaca.metainfo.xml.in:229 #: data/com.jeffser.Alpaca.metainfo.xml.in:229
#, fuzzy #, fuzzy

View File

@@ -270,15 +270,24 @@ def create_model_from_file(self):
# FILE CHOOSER | WORKS # FILE CHOOSER | WORKS
def attach_file_response(self, file_dialog, result, file_type): def attach_file_response(self, file_dialog, result):
file_types = {
"plain_text": ["txt", "md", "html", "css", "js", "py", "java", "json", "xml"],
"image": ["png", "jpeg", "jpg", "webp", "gif"],
"pdf": ["pdf"],
"docx": ["docx"]
}
try: file = file_dialog.open_finish(result) try: file = file_dialog.open_finish(result)
except: return except: return
self.attach_file(file.get_path(), file_type) extension = file.get_path().split(".")[-1]
file_type = next(key for key, value in file_types.items() if extension in value)
if not file_type: return
def attach_file(self, filter, file_type):
if file_type == 'image' and not self.verify_if_image_can_be_used(): if file_type == 'image' and not self.verify_if_image_can_be_used():
self.show_toast('error', 8, self.main_overlay) self.show_toast('error', 8, self.main_overlay)
return return
self.attach_file(file.get_path(), file_type)
def attach_file(self, filter):
file_dialog = Gtk.FileDialog(default_filter=filter) file_dialog = Gtk.FileDialog(default_filter=filter)
file_dialog.open(self, None, lambda file_dialog, result, file_type=file_type: attach_file_response(self, file_dialog, result, file_type)) file_dialog.open(self, None, lambda file_dialog, result: attach_file_response(self, file_dialog, result))

View File

@@ -47,7 +47,7 @@ class AlpacaApplication(Adw.Application):
application_name='Alpaca', application_name='Alpaca',
application_icon='com.jeffser.Alpaca', application_icon='com.jeffser.Alpaca',
developer_name='Jeffry Samuel Eduarte Rojas', developer_name='Jeffry Samuel Eduarte Rojas',
version='0.9.5', version='0.9.6',
developers=['Jeffser https://jeffser.com'], developers=['Jeffser https://jeffser.com'],
designers=['Jeffser https://jeffser.com'], designers=['Jeffser https://jeffser.com'],
translator_credits='Alex K (Russian) https://github.com/alexkdeveloper\nJeffser (Spanish) https://jeffser.com\nDaimar Stein (Brazilian Portuguese) https://github.com/not-a-dev-stein\nLouis Chauvet-Villaret (French) https://github.com/loulou64490', translator_credits='Alex K (Russian) https://github.com/alexkdeveloper\nJeffser (Spanish) https://jeffser.com\nDaimar Stein (Brazilian Portuguese) https://github.com/not-a-dev-stein\nLouis Chauvet-Villaret (French) https://github.com/loulou64490',

View File

@@ -21,10 +21,11 @@ import gi
gi.require_version('GtkSource', '5') gi.require_version('GtkSource', '5')
gi.require_version('GdkPixbuf', '2.0') gi.require_version('GdkPixbuf', '2.0')
from gi.repository import Adw, Gtk, Gdk, GLib, GtkSource, Gio, GdkPixbuf from gi.repository import Adw, Gtk, Gdk, GLib, GtkSource, Gio, GdkPixbuf
import json, requests, threading, os, re, base64, sys, gettext, locale, webbrowser, subprocess, uuid, shutil, tarfile, tempfile import json, requests, threading, os, re, base64, sys, gettext, locale, webbrowser, subprocess, uuid, shutil, tarfile, tempfile, docx
from time import sleep from time import sleep
from io import BytesIO from io import BytesIO
from PIL import Image from PIL import Image
from pypdf import PdfReader
from datetime import datetime from datetime import datetime
from .available_models import available_models from .available_models import available_models
from . import dialogs, local_instance, connection_handler, update_history from . import dialogs, local_instance, connection_handler, update_history
@@ -90,10 +91,10 @@ class AlpacaWindow(Adw.ApplicationWindow):
chats_menu_button = Gtk.Template.Child() chats_menu_button = Gtk.Template.Child()
attachment_container = Gtk.Template.Child() attachment_container = Gtk.Template.Child()
attachment_box = Gtk.Template.Child() attachment_box = Gtk.Template.Child()
file_filter_image = Gtk.Template.Child()
file_filter_tar = Gtk.Template.Child() file_filter_tar = Gtk.Template.Child()
file_filter_gguf = Gtk.Template.Child() file_filter_gguf = Gtk.Template.Child()
file_filter_text = Gtk.Template.Child() file_filter_attachments = Gtk.Template.Child()
attachment_button = Gtk.Template.Child()
model_drop_down = Gtk.Template.Child() model_drop_down = Gtk.Template.Child()
model_string_list = Gtk.Template.Child() model_string_list = Gtk.Template.Child()
@@ -1129,6 +1130,20 @@ class AlpacaWindow(Adw.ApplicationWindow):
elif file_type == 'plain_text': elif file_type == 'plain_text':
with open(file_path, 'r') as f: with open(file_path, 'r') as f:
return f.read() return f.read()
elif file_type == 'pdf':
reader = PdfReader(file_path)
if len(reader.pages) == 0: return None
text = ""
for i, page in enumerate(reader.pages):
text += f"\n- Page {i}\n{page.extract_text()}\n"
return text
elif file_type == 'docx':
document = docx.Document(file_path)
if len(document.paragraphs) == 0: return None
text = ""
for paragraph in document.paragraphs:
text += f"{paragraph.text}\n"
return text
def remove_attached_file(self, button): def remove_attached_file(self, button):
del self.attachments[button.get_name()] del self.attachments[button.get_name()]
@@ -1143,7 +1158,12 @@ class AlpacaWindow(Adw.ApplicationWindow):
button_content = Adw.ButtonContent( button_content = Adw.ButtonContent(
label=shown_name, label=shown_name,
icon_name={"image": "image-x-generic-symbolic", "plain_text": "document-text-symbolic"}[file_type] icon_name={
"image": "image-x-generic-symbolic",
"plain_text": "document-text-symbolic",
"pdf": "document-text-symbolic",
"docx": "document-text-symbolic"
}[file_type]
) )
button = Gtk.Button( button = Gtk.Button(
vexpand=True, vexpand=True,
@@ -1176,10 +1196,8 @@ class AlpacaWindow(Adw.ApplicationWindow):
self.get_application().create_action('import_chat', lambda *_: self.import_chat()) self.get_application().create_action('import_chat', lambda *_: self.import_chat())
self.get_application().create_action('create_model_from_existing', lambda *_: dialogs.create_model_from_existing(self)) self.get_application().create_action('create_model_from_existing', lambda *_: dialogs.create_model_from_existing(self))
self.get_application().create_action('create_model_from_file', lambda *_: dialogs.create_model_from_file(self)) self.get_application().create_action('create_model_from_file', lambda *_: dialogs.create_model_from_file(self))
self.get_application().create_action('attach_image', lambda *_: dialogs.attach_file(self, self.file_filter_image, "image"))
self.get_application().create_action('attach_plain_text', lambda *_: dialogs.attach_file(self, self.file_filter_text, "plain_text"))
self.add_chat_button.connect("clicked", lambda button : self.new_chat()) self.add_chat_button.connect("clicked", lambda button : self.new_chat())
self.attachment_button.connect("clicked", lambda button, file_filter=self.file_filter_attachments: dialogs.attach_file(self, file_filter))
self.create_model_name.get_delegate().connect("insert-text", self.check_alphanumeric) self.create_model_name.get_delegate().connect("insert-text", self.check_alphanumeric)
self.remote_connection_entry.connect("entry-activated", lambda entry : entry.set_css_classes([])) self.remote_connection_entry.connect("entry-activated", lambda entry : entry.set_css_classes([]))
self.remote_connection_switch.connect("notify", lambda pspec, user_data : self.connection_switched()) self.remote_connection_switch.connect("notify", lambda pspec, user_data : self.connection_switched())

View File

@@ -189,9 +189,7 @@
<property name="orientation">0</property> <property name="orientation">0</property>
<property name="spacing">12</property> <property name="spacing">12</property>
<child> <child>
<object class="GtkMenuButton" id="attachment_button"> <object class="GtkButton" id="attachment_button">
<property name="menu-model">attachment_menu</property>
<property name="direction">0</property>
<property name="vexpand">false</property> <property name="vexpand">false</property>
<property name="valign">3</property> <property name="valign">3</property>
<property name="tooltip-text" translatable="yes">Attach file</property> <property name="tooltip-text" translatable="yes">Attach file</property>
@@ -903,21 +901,8 @@
</item> </item>
</section> </section>
</menu> </menu>
<menu id="attachment_menu"> <object class="GtkFileFilter" id="file_filter_attachments">
<section>
<item>
<attribute name="label" translatable="yes">Plain text file</attribute>
<attribute name="action">app.attach_plain_text</attribute>
</item>
<item>
<attribute name="label" translatable="yes">Image</attribute>
<attribute name="action">app.attach_image</attribute>
</item>
</section>
</menu>
<object class="GtkFileFilter" id="file_filter_text">
<suffixes> <suffixes>
<suffix></suffix>
<suffix>txt</suffix> <suffix>txt</suffix>
<suffix>md</suffix> <suffix>md</suffix>
<suffix>html</suffix> <suffix>html</suffix>
@@ -927,17 +912,14 @@
<suffix>java</suffix> <suffix>java</suffix>
<suffix>json</suffix> <suffix>json</suffix>
<suffix>xml</suffix> <suffix>xml</suffix>
<suffix>pdf</suffix>
<suffix>docx</suffix>
<suffix>png</suffix>
<suffix>jpeg</suffix>
<suffix>webp</suffix>
<suffix>gif</suffix>
</suffixes> </suffixes>
</object> </object>
<object class="GtkFileFilter" id="file_filter_image">
<mime-types>
<mime-type>image/svg+xml</mime-type>
<mime-type>image/png</mime-type>
<mime-type>image/jpeg</mime-type>
<mime-type>image/webp</mime-type>
<mime-type>image/gif</mime-type>
</mime-types>
</object>
<object class="GtkFileFilter" id="file_filter_tar"> <object class="GtkFileFilter" id="file_filter_tar">
<mime-types> <mime-types>
<mime-type>application/x-tar</mime-type> <mime-type>application/x-tar</mime-type>