From 572980b3cd9b33883340e900ff4235d7c40561d5 Mon Sep 17 00:00:00 2001 From: AndzejsP Date: Mon, 29 May 2023 09:19:00 +0300 Subject: [PATCH 1/7] added disk usage and si units --- web/src/components/ModelEntry.vue | 2 +- web/src/views/SettingsView.vue | 126 +++++++++++++++++++++++++----- 2 files changed, 107 insertions(+), 21 deletions(-) diff --git a/web/src/components/ModelEntry.vue b/web/src/components/ModelEntry.vue index 360f3143..3ce1ee29 100644 --- a/web/src/components/ModelEntry.vue +++ b/web/src/components/ModelEntry.vue @@ -191,7 +191,7 @@ export default { * * @return Formatted string. */ - humanFileSize(bytes, si = false, dp = 1) { + humanFileSize(bytes, si = true, dp = 1) { const thresh = si ? 1000 : 1024; if (Math.abs(bytes) < thresh) { diff --git a/web/src/views/SettingsView.vue b/web/src/views/SettingsView.vue index b0d1ffda..916af28c 100644 --- a/web/src/views/SettingsView.vue +++ b/web/src/views/SettingsView.vue @@ -72,13 +72,14 @@
@@ -99,16 +100,19 @@ -
+ :key="'index-' + index + '-' + binding.folder" :binding="binding" + :on-selected="onSelectedBinding" :selected="binding.folder === configFile.binding"> +
- +
+
+ +
+
Bindings/models folder: {{ binding_models_usage }}
+ + +
Avaliable space:  {{ available_space }} / {{ total_space }}
+
+
+
+
+
+
+
+
@@ -181,10 +203,11 @@

Personalities zoo

-
|
- -
- {{configFile.personality}}
+
|
+ +
+ {{ configFile.personality }}
@@ -539,7 +562,9 @@ export default { showToast: false, isLoading: false, settingsChanged: false, - isModelSelected: false + isModelSelected: false, + diskUsage: {} + } }, @@ -677,6 +702,9 @@ export default { this.showProgress = false; model_object.installing = false this.$refs.toast.showToast("Model:\n" + model_object.title + "\ninstalled!", 4, true) + this.api_get_req("disk_usage").then(response =>{ + this.diskUsage=response + }) } else if (response.status === 'failed') { socket.off('install_progress', progressListener); console.log("Install failed") @@ -686,6 +714,9 @@ export default { this.showProgress = false; console.error('Installation failed:', response.error); this.$refs.toast.showToast("Model:\n" + model_object.title + "\nfailed to install!", 4, false) + this.api_get_req("disk_usage").then(response =>{ + this.diskUsage=response + }) } }; @@ -711,6 +742,9 @@ export default { this.models = this.models.filter((model) => model.title !== model_object.title) } this.$refs.toast.showToast("Model:\n" + model_object.title + "\nwas uninstalled!", 4, true) + this.api_get_req("disk_usage").then(response =>{ + this.diskUsage=response + }) } else if (response.status === 'failed') { // Installation failed or encountered an error model_object.uninstalling = false; @@ -719,6 +753,9 @@ export default { // eslint-disable-next-line no-undef console.error('Uninstallation failed:', message.error); this.$refs.toast.showToast("Model:\n" + model_object.title + "\nfailed to uninstall!", 4, false) + this.api_get_req("disk_usage").then(response =>{ + this.diskUsage=response + }) } }; @@ -726,7 +763,7 @@ export default { socket.emit('uninstall_model', { path: model_object.path }); }, - onSelectedBinding(binding_object){ + onSelectedBinding(binding_object) { this.update_binding(binding_object.binding.folder) //console.log('lol',binding_object) }, @@ -761,6 +798,9 @@ export default { } }); }) + this.api_get_req("disk_usage").then(response =>{ + this.diskUsage=response + }) this.getPersonalitiesArr() this.fetchModels(); }, @@ -789,7 +829,7 @@ export default { .catch(error => { return { 'status': false } }); }, update_binding(value) { - + // eslint-disable-next-line no-unused-vars this.isLoading = true this.update_setting('binding', value, (res) => { @@ -945,7 +985,38 @@ export default { this.personalitiesFiltered = this.personalities.filter((item) => item.category === this.configFile.personality_category && item.language === this.configFile.personality_language) this.isLoading = false - } + }, + /** From https://stackoverflow.com/a/14919494/14106028 + * Format bytes as human-readable text. + * + * @param bytes Number of bytes. + * @param si True to use metric (SI) units, aka powers of 1000. False to use + * binary (IEC), aka powers of 1024. + * @param dp Number of decimal places to display. + * + * @return Formatted string. + */ + humanFileSize(bytes, si = true, dp = 1) { + const thresh = si ? 1000 : 1024; + + if (Math.abs(bytes) < thresh) { + return bytes + ' B'; + } + + const units = si + ? ['kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'] + : ['KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB']; + let u = -1; + const r = 10 ** dp; + + do { + bytes /= thresh; + ++u; + } while (Math.round(Math.abs(bytes) * r) / r >= thresh && u < units.length - 1); + + + return bytes.toFixed(dp) + ' ' + units[u]; + }, }, async mounted() { this.isLoading = true @@ -967,7 +1038,22 @@ export default { await this.getPersonalitiesArr() this.bindings = await this.api_get_req("list_bindings") this.isLoading = false - + this.diskUsage = await this.api_get_req("disk_usage") + }, + computed: { + available_space() { + return this.humanFileSize(this.diskUsage.available_space) + }, + binding_models_usage() { + return this.humanFileSize(this.diskUsage.binding_models_usage) + }, + percent_usage() { + return this.diskUsage.percent_usage + //return this.humanFileSize(this.diskUsage.percent_usage) + }, + total_space() { + return this.humanFileSize(this.diskUsage.total_space) + }, }, watch: { bec_collapsed() { From 8f5267f5adaafc294a0b97778f359b5b9fc43d31 Mon Sep 17 00:00:00 2001 From: AndzejsP Date: Mon, 29 May 2023 09:30:29 +0300 Subject: [PATCH 2/7] moved warning --- web/src/views/SettingsView.vue | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/web/src/views/SettingsView.vue b/web/src/views/SettingsView.vue index 916af28c..358e3d98 100644 --- a/web/src/views/SettingsView.vue +++ b/web/src/views/SettingsView.vue @@ -33,10 +33,10 @@
-
+
Apply changes: @@ -137,10 +137,16 @@

Models zoo

+
+
+ + No model selected! +
+
|
- {{ configFile.model }}
+ {{ configFile.model }}
@@ -149,7 +155,7 @@ Disk usage:
-
Bindings/models folder: {{ binding_models_usage }}
+
Current binding models folder: {{ binding_models_usage }}
Avaliable space:  {{ available_space }} / {{ total_space }}
@@ -844,6 +850,7 @@ export default { }) // If binding changes then reset model this.update_model(null) + this.configFile.model=null }) }, From bd9a3c0f9874c505144cc71fea7acccdfda506b5 Mon Sep 17 00:00:00 2001 From: AndzejsP Date: Mon, 29 May 2023 09:52:53 +0300 Subject: [PATCH 3/7] button fixes --- web/src/components/Navigation.vue | 10 +++++----- web/src/views/SettingsView.vue | 19 ++++++++++++------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/web/src/components/Navigation.vue b/web/src/components/Navigation.vue index 98ffa8fc..9f1f1be0 100644 --- a/web/src/components/Navigation.vue +++ b/web/src/components/Navigation.vue @@ -4,28 +4,28 @@
  • - + Discussions
  • - + Settings
  • - + Extensions
  • - + Training
  • - + Help
  • diff --git a/web/src/views/SettingsView.vue b/web/src/views/SettingsView.vue index 358e3d98..50ae1e58 100644 --- a/web/src/views/SettingsView.vue +++ b/web/src/views/SettingsView.vue @@ -838,6 +838,7 @@ export default { // eslint-disable-next-line no-unused-vars this.isLoading = true + this.update_setting('binding', value, (res) => { this.refresh(); @@ -851,6 +852,10 @@ export default { // If binding changes then reset model this.update_model(null) this.configFile.model=null + + this.api_get_req("disk_usage").then(response =>{ + this.diskUsage=response + }) }) }, @@ -865,14 +870,14 @@ export default { }) }, applyConfiguration() { - if (!this.configFile.model) { + // if (!this.configFile.model) { - this.$refs.toast.showToast("Configuration changed failed.\nPlease select model first", 4, false) - nextTick(() => { - feather.replace() - }) - return - } + // this.$refs.toast.showToast("Configuration changed failed.\nPlease select model first", 4, false) + // nextTick(() => { + // feather.replace() + // }) + // return + // } this.isLoading = true; axios.post('/apply_settings').then((res) => { this.isLoading = false; From c72e249b891f51016973282091c78a8e62ea0d5e Mon Sep 17 00:00:00 2001 From: AndzejsP Date: Mon, 29 May 2023 10:37:27 +0300 Subject: [PATCH 4/7] drag and drop wip --- web/src/components/DragDrop.vue | 28 ++++++++++++++++++++++++++++ web/src/views/DiscussionsView.vue | 7 +++++-- 2 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 web/src/components/DragDrop.vue diff --git a/web/src/components/DragDrop.vue b/web/src/components/DragDrop.vue new file mode 100644 index 00000000..ca8d4220 --- /dev/null +++ b/web/src/components/DragDrop.vue @@ -0,0 +1,28 @@ + + + + diff --git a/web/src/views/DiscussionsView.vue b/web/src/views/DiscussionsView.vue index 6bc6df06..3904d879 100644 --- a/web/src/views/DiscussionsView.vue +++ b/web/src/views/DiscussionsView.vue @@ -155,7 +155,9 @@ +
+
@@ -999,7 +1001,8 @@ export default { Message, ChatBox, WelcomeComponent, - Toast + Toast, + DragDrop }, watch: { filterTitle(newVal) { @@ -1055,7 +1058,7 @@ import Message from '../components/Message.vue' import ChatBox from '../components/ChatBox.vue' import WelcomeComponent from '../components/WelcomeComponent.vue' import Toast from '../components/Toast.vue' - +import DragDrop from '../components/DragDrop.vue' import feather from 'feather-icons' import axios from 'axios' From 28cd7d0b99af74f266bb5b37f264e403f18a611a Mon Sep 17 00:00:00 2001 From: AndzejsP Date: Mon, 29 May 2023 13:38:02 +0300 Subject: [PATCH 5/7] moved helper func to a plugin --- web/src/components/ModelEntry.vue | 42 ++++++------------------------- web/src/main.js | 2 +- web/src/views/SettingsView.vue | 41 ++++++------------------------ 3 files changed, 15 insertions(+), 70 deletions(-) diff --git a/web/src/components/ModelEntry.vue b/web/src/components/ModelEntry.vue index 3ce1ee29..cf519980 100644 --- a/web/src/components/ModelEntry.vue +++ b/web/src/components/ModelEntry.vue @@ -90,6 +90,7 @@ From 9ea52d3b90744d97ed942b5964a3bfeabcd34a50 Mon Sep 17 00:00:00 2001 From: AndzejsP Date: Mon, 29 May 2023 16:26:25 +0300 Subject: [PATCH 7/7] dropzone in progress --- web/src/components/DragDrop.vue | 144 ++++++++++++++++++++++++++---- web/src/plugins/filesize.js | 31 +++++++ web/src/views/DiscussionsView.vue | 131 ++++++++++++++++----------- 3 files changed, 239 insertions(+), 67 deletions(-) create mode 100644 web/src/plugins/filesize.js diff --git a/web/src/components/DragDrop.vue b/web/src/components/DragDrop.vue index ca8d4220..b5cdae47 100644 --- a/web/src/components/DragDrop.vue +++ b/web/src/components/DragDrop.vue @@ -1,28 +1,142 @@ + \ No newline at end of file diff --git a/web/src/plugins/filesize.js b/web/src/plugins/filesize.js new file mode 100644 index 00000000..b197a4b0 --- /dev/null +++ b/web/src/plugins/filesize.js @@ -0,0 +1,31 @@ + /** From https://stackoverflow.com/a/14919494/14106028 + * Format bytes as human-readable text. + * + * @param bytes Number of bytes. + * @param si True to use metric (SI) units, aka powers of 1000. False to use + * binary (IEC), aka powers of 1024. + * @param dp Number of decimal places to display. + * + * @return Formatted string. + */ + export default function humanFileSize(bytes, si = true, dp = 1) { + const thresh = si ? 1000 : 1024; + + if (Math.abs(bytes) < thresh) { + return bytes + ' B'; + } + + const units = si + ? ['kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'] + : ['KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB']; + let u = -1; + const r = 10 ** dp; + + do { + bytes /= thresh; + ++u; + } while (Math.round(Math.abs(bytes) * r) / r >= thresh && u < units.length - 1); + + + return bytes.toFixed(dp) + ' ' + units[u]; + } \ No newline at end of file diff --git a/web/src/views/DiscussionsView.vue b/web/src/views/DiscussionsView.vue index 3904d879..3d4a4611 100644 --- a/web/src/views/DiscussionsView.vue +++ b/web/src/views/DiscussionsView.vue @@ -2,7 +2,7 @@
-
+
@@ -51,11 +51,11 @@
-
- +
- -
+ + +
@@ -75,9 +75,9 @@ @input="filterDiscussions()" />
- +
- +
@@ -125,11 +125,11 @@
- - + +
@@ -142,27 +142,35 @@
-
- - -
- - - - - - - -
- -
- +
+
+
+
+ + +
+ + + + + + + +
+ + +
+ +
+ +
@@ -171,23 +179,26 @@