Skip to content

Commit

Permalink
Merge pull request #6 from TNG/fix/pressreleasebuild
Browse files Browse the repository at this point in the history
Fix/pressreleasebuild
  • Loading branch information
florianesser-tng authored Nov 29, 2024
2 parents 6e64bd1 + 6085928 commit 14580b3
Show file tree
Hide file tree
Showing 20 changed files with 206 additions and 135 deletions.
2 changes: 1 addition & 1 deletion ComfyUI
Submodule ComfyUI updated from 518c0d to 0d4e29
14 changes: 3 additions & 11 deletions WebUI/electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,18 +519,10 @@ function initEventHandle() {
imagePath = imageUrl.pathname.replace(/^\/*/, '')
} else {
const s = imageUrl.searchParams;
imagePath = `${s.get('type')}/${s.get('filename')}`
imagePath = `static/sd_out/${s.get('filename')}`
}
if (app.isPackaged) {
// Resolve path relative to app when packaged
imagePath = path.join(externalRes, backend, imagePath);
} else {
// Resolve path relative to current directory during development
const cwd = app.getAppPath();
const parent_dir = path.dirname(cwd);
imagePath = path.join(parent_dir, backend, imagePath);
}
return imagePath;

return path.join(externalRes, 'service', imagePath);
}

ipcMain.on("openImageWithSystem", (event, url: string) => {
Expand Down
2 changes: 1 addition & 1 deletion WebUI/electron/pathsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export class PathsManager {
fs.readdirSync(dir).forEach(pathname => {
const fullPath = path.join(dir, pathname);
if (fs.statSync(fullPath).isDirectory() && fs.existsSync(
path.join(fullPath, "config.json")
path.join(fullPath)
)) {
const modelName = pathname.replace("---", "/")
if (!modelsSet.has(modelName)) {
Expand Down
7 changes: 6 additions & 1 deletion WebUI/src/assets/i18n/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,12 @@
"DECREASE_FONT_SIZE": "Shrink Text",
"ANSWER_RAG_ENABLE":"Enable File Query",
"ANSWER_RAG_OPEN_DIALOG":"Open File Uploader",
"REQUEST_LLM_MODEL_NAME":"Add a model of your choice from huggingface.co,<br />for example: <i>meta-llama/Llama-3.2-1B </i>",
"REQUEST_LLM_MODEL_NAME":"Add a model of your choice from huggingface.co",
"REQUEST_LLM_MODEL_DESCRIPTION": "You can download a model repository with the syntax",
"REQUEST_LLM_MODEL_EXAMPLE": "&lt;namespace&gt;/&lt;repo_name&gt;, e.g. 'openai-community/gpt2'",
"REQUEST_LLM_SINGLE_EXAMPLE": "&lt;namespace&gt;/&lt;file_path&gt;, e.g. 'microsoft/Phi-3-mini-4k-instruct-gguf/Phi-3-mini-4k-instruct-q4.gguf'",
"REQUEST_LLM_MODEL_DESCRIPTION_tmp":"You can either download a model repository by providing &lt;namespace&gt;/&lt;repo_name&gt;, e.g. 'openai-community/gpt2' or a single model file, by typing &lt;namespace&gt;/&lt;file_path&gt;, e.g. 'microsoft/Phi-3-mini-4k-instruct-gguf/Phi-3-mini-4k-instruct-q4.gguf'",
"REQUEST_LLM_MODEL_DISCLAIMER":"NOTE: Not every model on huggingface.co is suited for the task you want it to perform. <br />Carefully read the model introduction and requirements before downloading.",
"DOWNLOADER_CONFRIM_TIP":"You are missing one or more models needed to run. Would you like to download the model(s) listed below?",
"DOWNLOADER_MODEL":"Model",
"DOWNLOADER_INFO":"Info",
Expand Down
17 changes: 12 additions & 5 deletions WebUI/src/assets/js/store/globalSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,15 +292,21 @@ export const useGlobalSetup = defineStore("globalSetup", () => {
}
}

async function checkModelExists(params: CheckModelExistParam[]) {
const response = await fetch(`${apiHost.value}/api/checkModelExist`, {
async function checkModelAlreadyLoaded(params: CheckModelAlreadyLoadedParameters[]) {
const response = await fetch(`${apiHost.value}/api/checkModelAlreadyLoaded`, {
method: "POST",
body: JSON.stringify(params),
body: JSON.stringify({ 'data': params}),
headers: {
"Content-Type": "application/json"
}
});
const data = (await response.json()) as ApiResponse & { exists: CheckModelExistResult[] };
const parsedResponse = (await response.json()) as ApiResponse & { data: CheckModelAlreadyLoadedResult[] };
return parsedResponse.data;
}

async function checkIfHuggingFaceUrlExists(repo_id: string) {
const response = await fetch(`${apiHost.value}/api/checkHFRepoExists?repo_id=${repo_id}`)
const data = await response.json()
return data.exists;
}

Expand All @@ -323,7 +329,8 @@ export const useGlobalSetup = defineStore("globalSetup", () => {
refreshSDModles,
refreshInpaintModles,
refreshLora,
checkModelExists,
checkModelAlreadyLoaded: checkModelAlreadyLoaded,
checkIfHuggingFaceUrlExists,
applyPresetModelSettings,
restorePathsSettings,
};
Expand Down
28 changes: 16 additions & 12 deletions WebUI/src/assets/js/store/imageGeneration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,11 @@ export const useImageGeneration = defineStore("imageGeneration", () => {

async function getMissingComfyuiBackendModels() {
if (activeWorkflow.value?.requiredModels === undefined) {
toast.error('"Defined workflow did not specify required models. Please add "requiredModels" to workflowfile.');
toast.error('Defined workflow did not specify required models. Please add "requiredModels" to workflowfile.');
return []
} else {
function extractDownloadModelParamsFromString(modelParamString: string): CheckModelExistParam {
const [modelType, repoAddress] = modelParamString.split(":")
function extractDownloadModelParamsFromString(modelParamString: string): CheckModelAlreadyLoadedParameters {
const [modelType, repoAddress] = modelParamString.replace(" ", "").split(":")
function modelTypeToId(type: string) {
switch (type) {
case "unet" : return Const.MODEL_TYPE_COMFY_UNET
Expand All @@ -282,17 +282,21 @@ export const useImageGeneration = defineStore("imageGeneration", () => {
}
return {type: modelTypeToId(modelType), repo_id: repoAddress, backend: "comfyui"}
}
const checkList: CheckModelExistParam[] = activeWorkflow.value.requiredModels.map( extractDownloadModelParamsFromString)
const result: CheckModelExistResult[] = await globalSetup.checkModelExists(checkList);
return result
.filter(checkModelExistsResult => !checkModelExistsResult.exist)
.map(item => ({ repo_id: item.repo_id, type: item.type, backend: item.backend }))
const checkList: CheckModelAlreadyLoadedParameters[] = activeWorkflow.value.requiredModels.map( extractDownloadModelParamsFromString)
const checkedModels: CheckModelAlreadyLoadedResult[] = await globalSetup.checkModelAlreadyLoaded(checkList);
const modelsToBeLoaded = checkedModels.filter(checkModelExistsResult => !checkModelExistsResult.already_loaded)
for (const item of modelsToBeLoaded) {
if(!await globalSetup.checkIfHuggingFaceUrlExists(item.repo_id)) {
toast.error(`declared model ${item.repo_id} does not exist. Aborting Generation.`)
return []
}
}
return modelsToBeLoaded.map(item => ({ repo_id: item.repo_id, type: item.type, backend: item.backend }))
}

}

async function getMissingDefaultBackendModels() {
const checkList: CheckModelExistParam[] = [{ repo_id: imageModel.value, type: Const.MODEL_TYPE_STABLE_DIFFUSION, backend: activeWorkflow.value.backend }];
const checkList: CheckModelAlreadyLoadedParameters[] = [{ repo_id: imageModel.value, type: Const.MODEL_TYPE_STABLE_DIFFUSION, backend: activeWorkflow.value.backend }];
if (lora.value !== "None") {
checkList.push({ repo_id: lora.value, type: Const.MODEL_TYPE_LORA, backend: activeWorkflow.value.backend })
}
Expand All @@ -301,9 +305,9 @@ export const useImageGeneration = defineStore("imageGeneration", () => {
checkList.push({ repo_id: "madebyollin/taesdxl", type: Const.MODEL_TYPE_PREVIEW , backend: activeWorkflow.value.backend})
}

const result = await globalSetup.checkModelExists(checkList);
const result = await globalSetup.checkModelAlreadyLoaded(checkList);
return result
.filter(checkModelExistsResult => !checkModelExistsResult.exist)
.filter(checkModelExistsResult => !checkModelExistsResult.already_loaded)
.map(item => ({ repo_id: item.repo_id, type: item.type, backend: item.backend }))

}
Expand Down
8 changes: 4 additions & 4 deletions WebUI/src/assets/js/store/stableDiffusion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,18 @@ export const useStableDiffusion = defineStore("stableDiffusion", () => {

async function checkModel() {
return new Promise<void>(async (resolve, reject) => {
const checkList: CheckModelExistParam[] = [{ repo_id: globalSetup.modelSettings.sd_model, type: Const.MODEL_TYPE_STABLE_DIFFUSION, backend: "default" }];
const checkList: CheckModelAlreadyLoadedParameters[] = [{ repo_id: globalSetup.modelSettings.sd_model, type: Const.MODEL_TYPE_STABLE_DIFFUSION, backend: "default" }];
if (globalSetup.modelSettings.lora != "None") {
checkList.push({ repo_id: globalSetup.modelSettings.lora, type: Const.MODEL_TYPE_LORA , backend: "default"})
}
if (globalSetup.modelSettings.imagePreview) {
checkList.push({ repo_id: "madebyollin/taesd", type: Const.MODEL_TYPE_PREVIEW , backend: "default"})
checkList.push({ repo_id: "madebyollin/taesdxl", type: Const.MODEL_TYPE_PREVIEW , backend: "default"})
}
const result = await globalSetup.checkModelExists(checkList);
const downloadList: CheckModelExistParam[] = [];
const result = await globalSetup.checkModelAlreadyLoaded(checkList);
const downloadList: CheckModelAlreadyLoadedParameters[] = [];
for (const item of result) {
if (!item.exist) {
if (!item.already_loaded) {
downloadList.push({ repo_id: item.repo_id, type: item.type, backend: "default" })
}
}
Expand Down
55 changes: 44 additions & 11 deletions WebUI/src/components/AddLLMDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,21 @@
<div
class="py-10 px-20 w-500px flex flex-col items-center justify-center bg-gray-600 rounded-3xl gap-6 text-white"
:class="{ 'animate-scale-in': animate }">
<p v-html="i18nState.REQUEST_LLM_MODEL_NAME"></p>
<Input :placeholder="languages.COM_LLM_HF_PROMPT" v-model="modelRequest" @keyup.enter="addModel"></Input>
<b v-html="i18nState.REQUEST_LLM_MODEL_NAME"></b>
<div class="flex flex-col items-center gap-2 p-4 border border-yellow-600 bg-yellow-600/10 rounded-lg">
<p v-html="i18nState.REQUEST_LLM_MODEL_DISCLAIMER"></p>
</div>
<div class="container flex">
<span @mouseover="showInfo = true" @mouseout="showInfo = false" style="vertical-align: middle;" class="svg-icon i-info w-7 h-7 px-6"></span>
<Input :placeholder="languages.COM_LLM_HF_PROMPT" v-model="modelRequest" @keyup.enter="addModel"></Input>
</div>
<span v-if="showInfo" class="hover-box w-0.6">
<p v-html="i18nState.REQUEST_LLM_MODEL_DESCRIPTION"></p>
<ul>
<li v-html="i18nState.REQUEST_LLM_MODEL_EXAMPLE"></li>
<!-- <li v-html="i18nState.REQUEST_LLM_SINGLE_EXAMPLE"></li>-->
</ul>
</span>
<p v-show="addModelError" style="color: #F44336;">{{ addModelErrorMessage }}</p>
<div class="flex justify-center items-center gap-9">
<button @click="closeAdd" class="bg-color-control-bg py-1 px-4 rounded">{{ i18nState.COM_CLOSE }}</button>
Expand All @@ -15,6 +28,7 @@
</div>
</div>
</template>

<script setup lang="ts">
import { Input } from '@/components/ui/input'
import { useGlobalSetup } from '@/assets/js/store/globalSetup';
Expand All @@ -27,6 +41,7 @@ const globalSetup = useGlobalSetup();
const models = useModels();
const modelRequest = ref("");
const addModelErrorMessage = ref("")
const showInfo = ref(false);
const addModelError = ref(false);
const animate = ref(false);
const emits = defineEmits<{
Expand All @@ -40,21 +55,28 @@ function onShow() {
}
async function addModel() {
const previousModel = globalSetup.modelSettings.llm_model
const isInModels = models.models.some((model) => model.name === modelRequest.value)
const cancelAndShowWarning = (text: string) => {
globalSetup.modelSettings.llm_model = previousModel;
addModelErrorMessage.value = text;
addModelError.value = true;
}
if(modelRequest.value.split("/").length !== 2) {
cancelAndShowWarning("Please provide a valid model reference.")
return
}
const isInModels = models.models.some((model) => model.name === modelRequest.value)
if (isInModels) {
cancelAndShowWarning(i18nState.ERROR_ALREADY_IN_MODELS);
return;
}
const urlExists = await checkIfUrlExists(modelRequest.value);
const urlExists = await globalSetup.checkIfHuggingFaceUrlExists(modelRequest.value);
if (!urlExists) {
cancelAndShowWarning(i18nState.ERROR_REPO_NOT_EXISTS);
return;
Expand Down Expand Up @@ -82,12 +104,6 @@ async function registerModel() {
globalSetup.modelSettings.llm_model = modelRequest.value;
}
async function checkIfUrlExists(repo_id: string) {
const response = await fetch(`${globalSetup.apiHost}/api/checkHFRepoExists?repo_id=${repo_id}`)
const data = await response.json()
return data.exists;
}
async function isLLM(repo_id: string) {
const response = await fetch(`${globalSetup.apiHost}/api/isLLM?repo_id=${repo_id}`)
const data = await response.json()
Expand All @@ -101,6 +117,23 @@ function closeAdd() {
emits("close");
}
defineExpose({ onShow });
</script>
</script>

<style>
ul {
list-style-type: disc;
padding-left: 20px;
}
.hover-box {
position: absolute;
background-color: rgba(90, 90, 90, 0.91);
border: 1px solid #000000;
padding: 10px;
border-radius: 10px;
z-index: 1;
}
</style>
2 changes: 1 addition & 1 deletion WebUI/src/components/DownloadDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ function download() {
curDownloadTip.value = "";
fetch(`${globalSetup.apiHost}/api/downloadModel`, {
method: "POST",
body: JSON.stringify(toRaw(downloadList.value)),
body: JSON.stringify(toRaw({ 'data': downloadList.value})),
headers: {
"Content-Type": "application/json",
...(models.hfTokenIsValid ? { Authorization: `Bearer ${models.hfToken}` } : {})
Expand Down
12 changes: 6 additions & 6 deletions WebUI/src/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,20 +293,20 @@ type NumberRange = {

type DownloadFailedParams = { type: "error" | "cancelConfrim" | "cancelDownload" | "conflict", error?: any }

type CheckModelExistParam = {
type CheckModelAlreadyLoadedParameters = {
repo_id: string;
type: number;
backend: BackendType;
}

type BackendType = "comfyui" | "default"

type DownloadModelParam = CheckModelExistParam
type DownloadModelParam = CheckModelAlreadyLoadedParameters

type DownloadModelRender = { size: string, gated?: boolean } & CheckModelExistParam
type DownloadModelRender = { size: string, gated?: boolean } & CheckModelAlreadyLoadedParameters

type CheckModelExistResult = {
exist: boolean
} & CheckModelExistParam
type CheckModelAlreadyLoadedResult = {
already_loaded: boolean
} & CheckModelAlreadyLoadedParameters

type SDGenerateState = "no_start" | "input_image" | "load_model" | "load_model_components" | "generating" | "image_out" | "error"
8 changes: 4 additions & 4 deletions WebUI/src/views/Answer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,8 @@ async function newPromptGenerate() {
async function checkModel() {
return new Promise<void>(async (resolve, reject) => {
const checkList: CheckModelExistParam[] = [{ repo_id: globalSetup.modelSettings.llm_model, type: Const.MODEL_TYPE_LLM, backend: "default" }];
if (!(await globalSetup.checkModelExists(checkList))[0].exist) {
const checkList: CheckModelAlreadyLoadedParameters[] = [{ repo_id: globalSetup.modelSettings.llm_model, type: Const.MODEL_TYPE_LLM, backend: "default" }];
if (!(await globalSetup.checkModelAlreadyLoaded(checkList))[0].already_loaded) {
emits(
"showDownloadModelConfirm",
checkList,
Expand Down Expand Up @@ -550,8 +550,8 @@ async function toggleRag(value: boolean) {
ragData.processEnable = true;
try {
if (value) {
var checkList: CheckModelExistParam[] = [{ repo_id: globalSetup.modelSettings.embedding, type: Const.MODEL_TYPE_EMBEDDING, backend: "default" }];
if (!(await globalSetup.checkModelExists(checkList))[0].exist) {
var checkList: CheckModelAlreadyLoadedParameters[] = [{ repo_id: globalSetup.modelSettings.embedding, type: Const.MODEL_TYPE_EMBEDDING, backend: "default" }];
if (!(await globalSetup.checkModelAlreadyLoaded(checkList))[0].already_loaded) {
emits("showDownloadModelConfirm",
checkList,
enableRag,
Expand Down
6 changes: 3 additions & 3 deletions WebUI/src/views/AppSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -391,10 +391,10 @@ function restorePresetModelSettings() {
}
function downloadModel(model_repo_id: string, type: number) {
const params: CheckModelExistParam[] = [{ repo_id: model_repo_id, type: type, backend: "default" }];
globalSetup.checkModelExists(params)
const params: CheckModelAlreadyLoadedParameters[] = [{ repo_id: model_repo_id, type: type, backend: "default" }];
globalSetup.checkModelAlreadyLoaded(params)
.then(exits => {
if (exits[0].exist) {
if (exits[0].already_loaded) {
toast.show(i18n.state.SETTINGS_MODEL_EXIST);
} else {
emits("showDownloadModelConfirm", params);
Expand Down
6 changes: 3 additions & 3 deletions WebUI/src/views/Create.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
class="bg-color-image-tool-button rounded-sm w-6 h-6 flex items-center justify-center">
<span class="svg-icon text-white i-transfer w-4 h-4"></span>
</button>
<button @click="showParamsDialog" :title="languages.COM_OPEN_PARAMS"
<button v-if="imageGeneration.activeWorkflow.backend === 'default'" @click="showParamsDialog" :title="languages.COM_OPEN_PARAMS"
class="bg-color-image-tool-button rounded-sm w-6 h-6 flex items-center justify-center">
<span class="svg-icon text-white i-info w-4 h-4"></span>
</button>
Expand Down Expand Up @@ -161,7 +161,7 @@ function swithPreview(i: number) {
}
function showParamsDialog() {
showParams.value = true;
infoParams.value = stableDiffusion.generateParams[imageGeneration.previewIdx];
showParams.value = true;
infoParams.value = stableDiffusion.generateParams[imageGeneration.previewIdx];
}
</script>
6 changes: 3 additions & 3 deletions WebUI/src/views/Enhance.vue
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ async function generate() {
async function checkModel() {
return new Promise<void>(async (resolve, reject) => {
const checkList: CheckModelExistParam[] = [];
const checkList: CheckModelAlreadyLoadedParameters[] = [];
if ([3, 4].includes(mode.value) && imageGeneration.inpaintModel != i18nState.ENHANCE_INPAINT_USE_IMAGE_MODEL) {
checkList.push({ repo_id: imageGeneration.inpaintModel, type: Const.MODEL_TYPE_INPAINT, backend: imageGeneration.activeWorkflow.backend});
} else {
Expand All @@ -451,10 +451,10 @@ async function checkModel() {
checkList.push({ repo_id: "madebyollin/taesd", type: Const.MODEL_TYPE_PREVIEW, backend: imageGeneration.activeWorkflow.backend })
checkList.push({ repo_id: "madebyollin/taesdxl", type: Const.MODEL_TYPE_PREVIEW, backend: imageGeneration.activeWorkflow.backend })
}
const result = await globalSetup.checkModelExists(checkList);
const result = await globalSetup.checkModelAlreadyLoaded(checkList);
const downloadList: DownloadModelParam[] = [];
for (const item of result) {
if (!item.exist) {
if (!item.already_loaded) {
downloadList.push({ repo_id: item.repo_id, type: item.type, backend: imageGeneration.activeWorkflow.backend })
}
}
Expand Down
2 changes: 1 addition & 1 deletion service/aipg_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def check_defaultbackend_mmodel_exist(type: int, repo_id: str) -> bool:
folder_name = repo_local_root_dir_name(repo_id)
if type == 0:
dir = model_config.config.get("llm")
return os.path.exists(os.path.join(dir, folder_name, "config.json"))
return os.path.exists(os.path.join(dir, folder_name))
elif type == 1:
dir = model_config.config.get("stableDiffusion")
if is_single_file(repo_id):
Expand Down
Loading

0 comments on commit 14580b3

Please sign in to comment.