Skip to content

Commit

Permalink
26 - Code cleanup after revision
Browse files Browse the repository at this point in the history
  • Loading branch information
marijnvg-tng committed Nov 21, 2024
1 parent f83a079 commit 9777bf9
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 34 deletions.
6 changes: 6 additions & 0 deletions WebUI/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@ function showDownloadModelConfirm(downList: DownloadModelParam[], success?: () =
function showModelRequest() {
showModelRequestDialog.value = true;
nextTick(() => {
addLLMCompt.value!.onShow();
});
}
function callCheckModel(){
Expand All @@ -249,6 +252,9 @@ function showWarning(message : string, func : () => void) {
warningCompt.value!.warningMessage = message;
showWarningDialog.value = true;
warningCompt.value!.confirmFunction = func;
nextTick(() => {
warningCompt.value!.onShow();
});
}
</script>
1 change: 0 additions & 1 deletion WebUI/src/assets/js/store/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ export const useModels = defineStore("models", () => {
const notYetDownloaded = (model: Model) => !downloadedModels.map(m => m.name).includes(model.name);

models.value = [...downloadedModels, ...userModels, ...predefinedModels.filter(notYetDownloaded)];
console.log(models);

}

Expand Down
10 changes: 6 additions & 4 deletions WebUI/src/components/AddLLMDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ const emits = defineEmits<{
(e: "showWarning", warning : string, func : () => void): void
}>();
onDeactivated(() => {
animate.value = false;
})
function fastGenerate(e: KeyboardEvent) {
if (e.code == "Enter") {
Expand All @@ -49,6 +46,10 @@ function fastGenerate(e: KeyboardEvent) {
}
}
function onShow() {
animate.value = true;
}
async function addModel() {
const previousModel = globalSetup.modelSettings.llm_model
const is_in_models = models.models.some((model) => model.name === modelRequest.value)
Expand All @@ -67,7 +68,6 @@ async function addModel() {
globalSetup.modelSettings.llm_model = previousModel
addModelErrorMessage.value = i18nState.ERROR_REPO_NOT_EXISTS
addModelError.value = true;
console.log("Hey")
}
} else {
globalSetup.modelSettings.llm_model = previousModel
Expand Down Expand Up @@ -112,6 +112,8 @@ function closeAdd() {
emits("close");
}
defineExpose({ onShow });
</script>
<style scoped>
table {
Expand Down
4 changes: 0 additions & 4 deletions WebUI/src/components/DownloadDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,6 @@ const readTerms = ref(false);
const downloadList = ref<DownloadModelRender[]>([]);
onDeactivated(() => {
animate.value = false;
})
function dataProcess(line: string) {
console.log(line);
const dataJson = line.slice(5);
Expand Down
1 change: 0 additions & 1 deletion WebUI/src/components/InpaintMask.vue
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ function moveWithShadow(e: MouseEvent) {
function showShadow() {
shadowPos.show = true;
console.log("showShadow");
}
defineExpose({ clearMaskImage, getMaskImage })
Expand Down
9 changes: 5 additions & 4 deletions WebUI/src/components/WarningDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ const emits = defineEmits<{
(e: "close"): void
}>();
onDeactivated(() => {
animate.value = false;
})
async function confirmAdd() {
confirmFunction.value()
Expand All @@ -35,7 +32,11 @@ function cancelConfirm() {
emits("close");
}
defineExpose({warningMessage, confirmFunction});
function onShow(){
animate.value = true
}
defineExpose({warningMessage, confirmFunction, onShow });
</script>
<style scoped>
Expand Down
12 changes: 0 additions & 12 deletions WebUI/src/views/Answer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,6 @@
</div>
<rag v-if="ragData.showUploader" ref="ragPanel" @close="ragData.showUploader = false"></rag>
</div>
<teleport to="#answerPanel" v-if="showDowloadDlg">
<download-dialog ref="downloadDigCompt"></download-dialog>
</teleport>
<teleport to="#answerPanel" v-if="showModelRequestDialog">
<add-l-l-m-dialog ref="addLLMDialog" @add-model="checkModel"></add-l-l-m-dialog>
</teleport>
</div>

</template>
Expand All @@ -190,8 +184,6 @@ import Rag from "../components/Rag.vue";
import ProgressBar from "../components/ProgressBar.vue";
import LoadingBar from "../components/LoadingBar.vue";
import DropSelector from "@/components/DropSelector.vue";
import DownloadDialog from "@/components/DownloadDialog.vue";
import AddLLMDialog from "@/components/AddLLMDialog.vue";
import ModelDropDownItem from "@/components/ModelDropDownItem.vue";
import { useI18N } from '@/assets/js/store/i18n';
import { toast } from '@/assets/js/toast';
Expand Down Expand Up @@ -226,15 +218,11 @@ const loadingModel = ref(false);
let receiveOut = "";
let chatPanel: HTMLElement;
const markdownParser = new MarkdownParser(i18nState.COM_COPY);
const showDowloadDlg = ref(false);
const showModelRequestDialog = ref(false);
const ragData = reactive({
enable: false,
processEnable: false,
showUploader: false,
});
const downloadDigCompt = ref<InstanceType<typeof DownloadDialog>>()
const addLLMDialog = ref<InstanceType<typeof AddLLMDialog>>()
const source = ref("");
const emits = defineEmits<{
Expand Down
14 changes: 11 additions & 3 deletions service/model_downloader.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from huggingface_hub import HfFileSystem, hf_hub_url, model_info
from huggingface_hub.utils._errors import RepositoryNotFoundError
from typing import Any, Callable, Dict, List
from os import path, makedirs, rename
import requests
Expand All @@ -11,11 +12,11 @@
import traceback
import concurrent.futures
import aipg_utils as utils
import shutil

model_list_cache = dict()
model_lock = Lock()


class HFFileItem:
relpath: str
size: int
Expand Down Expand Up @@ -83,8 +84,12 @@ def __init__(self, hf_token=None) -> None:
self.thread_lock = Lock()
self.hf_token = hf_token

def probe_url(self, repo_id: str):
model_info(repo_id)
def hf_url_exists(self, repo_id: str):
try:
model_info(repo_id)
return True
except RepositoryNotFoundError:
return False

def probe_type(self, repo_id : str):
return model_info(repo_id).pipeline_tag
Expand Down Expand Up @@ -264,6 +269,9 @@ def multiple_thread_downlod(self, thread_count: int):
path.join(self.save_path, self.repo_id.replace("/", "---"))
),
)
else:
# Download aborted
shutil.rmtree(self.save_path_tmp)

def start_report_download_progress(self):
thread = Thread(target=self.report_download_progress)
Expand Down
7 changes: 2 additions & 5 deletions service/web_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,12 @@ def check_model_exist():
result_list.append({"repo_id": repo_id, "type": type, "exist": exist})
return jsonify({"code": 0, "message": "success", "exists": result_list})


@app.route("/api/checkURLExists", methods=["POST"])
def check_url_exists():
address = request.get_json()
downloader = HFPlaygroundDownloader()
exists = True
try:
downloader.probe_url(address)
except hf.utils._errors.RepositoryNotFoundError:
exists = False
exists = downloader.hf_url_exists(address)

return jsonify(
{
Expand Down

0 comments on commit 9777bf9

Please sign in to comment.