Skip to content

Commit

Permalink
Embedding saving and sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
slimerplanet committed Oct 20, 2023
1 parent c64f1c4 commit 585515c
Show file tree
Hide file tree
Showing 4 changed files with 260 additions and 47 deletions.
31 changes: 28 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1581,8 +1581,19 @@ <h3 id="errorType" class="text-lg font-medium">Error</h3>
</select>
</li>
<li>
<!--Rating-->

<!-- Type -->
<li class="flex items-center horde">
<label class="ml-2 text-sm font-medium text-gray-900 dark:text-gray-100 mr-2">
Type:
</label>
<select id="civitai_type"
class="bg-white border pr-10 pl-2 py-1.5 border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-primary-500 focus:border-primary-500 block w-full dark:bg-gray-600 dark:border-gray-500 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500">
<option value="&types=LORA&types=TextualInversion">All</option>
<option value="&types=LORA">Lora</option>
<option value="&types=TextualInversion">Embedding</option>
</select>
</li>
<li>


</li>
Expand Down Expand Up @@ -1707,7 +1718,7 @@ <h3 id="errorType" class="text-lg font-medium">Error</h3>
</div>

<div class="container mx-auto mt-10 p-2 automatic1111 horde">
<div class="mb-6 border p-4 rounded border-gray-300 dark:border-gray-700">
<div class="border p-4 rounded border-gray-300 dark:border-gray-700">
<div class="flex justify-between items-center">
<h2 class="text-2xl font-bold mb-4 text-white">Loras</h2>
<h2 id="loraCount" class="horde text-2xl font-bold mb-4 text-white mr-4">0/5</h2>
Expand All @@ -1721,13 +1732,27 @@ <h2 id="loraCount" class="horde text-2xl font-bold mb-4 text-white mr-4">0/5</h2
</div>


</div>
</div>

<div class="container mx-auto p-2 horde">
<div class="mb-6 border p-4 rounded border-gray-300 dark:border-gray-700">
<div class="flex justify-between items-center">
<h2 class="text-2xl font-bold mb-4 text-white">Embeddings</h2>
</div>
<div class="horde overflow-y-scroll max-h-80" id="horde_TIContainer">
<!-- Lora elements will be added here dynamically -->

</div>


</div>
</div>





<script>
// Function to format the slider value with a trailing ".0" if it's a whole number
function formatSliderValue(value) {
Expand Down
39 changes: 30 additions & 9 deletions scripts/civitai.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,23 @@ function civitaiSearch(searchTerm) {

let nsfw = civitai_nsfw.checked

let _url = `https://civitai.com/api/v1/models?primaryFileOnly=true&types=LORA&sort=${civitai_sort.value}&period=${civitai_period.value}&nsfw=${nsfw}&tag=${current_tag}&query=${searchTerm.replaceAll(" ", "%20")}`;
let _url = `https://civitai.com/api/v1/models?primaryFileOnly=true&sort=${civitai_sort.value}&period=${civitai_period.value}&nsfw=${nsfw}&tag=${current_tag}&query=${searchTerm.replaceAll(" ", "%20")}`;


if (civitai_favorites.checked) {
_url = `https://civitai.com/api/v1/models?ids=0&primaryFileOnly=true&types=LORA&sort=${civitai_sort.value}&period=${civitai_period.value}&nsfw=${nsfw}&tag=${current_tag}`
_url = `https://civitai.com/api/v1/models?ids=0&primaryFileOnly=true&sort=${civitai_sort.value}&period=${civitai_period.value}&nsfw=${nsfw}&tag=${current_tag}`
favorite_loras.forEach(id => {
_url += `&ids=${id}`
});

_url += `&query=${searchTerm.replaceAll(" ", "%20")}`
}

if(serverType == ServerType.Horde){
_url+= document.getElementById("civitai_type").value;
}else{
_url+= "&types=LORA";
}

console.log(_url);
fetch(_url)
.then(response => {
Expand Down Expand Up @@ -463,6 +469,21 @@ function civitai_addLoraEntry(imageSrc, data, Blurred = null) {


if (serverType == ServerType.Horde) {

if(data.type == "TextualInversion"){
horde_AddEmbedding(data);

horde_embeddings.push({
name: data.id.toString(),
strength: 1,
inject_ti:"prompt"
});
console.log(horde_embeddings);

return;
}


if (horde_loras.length >= 5 || horde_loras.find(lora => lora.name === data.id.toString())) {
return;
}
Expand All @@ -473,12 +494,12 @@ function civitai_addLoraEntry(imageSrc, data, Blurred = null) {
});
loraCount.textContent = horde_loras.length + "/5";
console.log(horde_loras);
horde_AddLora(data.name, data.id, data.modelVersions[0].trainedWords);

} else if (automatic1111_support) {


if(data.type == "LORA") {
horde_AddLora(data.name, data.id, data.modelVersions[0].trainedWords);
}

} else if (automatic1111_support) {
if (installed_models[data.id]) {
handleLoraEntryClick(installed_models[data.id].filename);
} else {
Expand Down Expand Up @@ -921,7 +942,7 @@ async function findLorasInPrompt() {
label.textContent = lora[1];
loraDiv.appendChild(label);

var modelname = lora[1].replaceAll(" ", "%20").replaceAll(":", "%3A").replaceAll("/", "%2F").replaceAll("\\", "%5C").replaceAll(".", "%2E");
var modelname = lora[1].replaceAll(" ", "+").replaceAll(":", "%3A").replaceAll("/", "%2F").replaceAll("\\", "%5C").replaceAll(".", "%2E");

const ModelContainer = document.createElement("div");
ModelContainer.classList.add("h-64", "overflow-x-auto", "flex", "overflow-y-clip", "space-x-2", "pb-6");
Expand Down
Loading

0 comments on commit 585515c

Please sign in to comment.