mirror of
https://github.com/Physton/sd-webui-prompt-all-in-one.git
synced 2026-05-01 03:31:41 +00:00
Checking installation status of Python packages, optimizing translation interface text
Former-commit-id: 6fbe746b8675c175220ddd80335d9127ab42883f
This commit is contained in:
@@ -1 +1 @@
|
||||
8e33ccb55b5e8dcd68b5dd6b7f593719c69d0526
|
||||
730a7a117e1f6259a5ea26cd19287a1ae9d29f29
|
||||
17
install.py
17
install.py
@@ -13,11 +13,12 @@ packages = {
|
||||
"aliyunsdkalimt": "aliyun-python-sdk-alimt",
|
||||
}
|
||||
|
||||
for package_name in packages:
|
||||
package = packages[package_name]
|
||||
try:
|
||||
if not launch.is_installed(package_name):
|
||||
launch.run_pip(f"install {package}", f"sd-webui-prompt-all-in-one: {package_name}")
|
||||
except Exception as e:
|
||||
print(e)
|
||||
print(f'Warning: Failed to install {package}, some preprocessors may not work.')
|
||||
if __name__ == "__main__":
|
||||
for package_name in packages:
|
||||
package = packages[package_name]
|
||||
try:
|
||||
if not launch.is_installed(package_name):
|
||||
launch.run_pip(f"install {package}", f"sd-webui-prompt-all-in-one: {package_name}")
|
||||
except Exception as e:
|
||||
print(e)
|
||||
print(f'Warning: Failed to install {package}, some preprocessors may not work.')
|
||||
@@ -1 +1 @@
|
||||
1b29fa7884001b75f81d3a6e11f97bbbe7a7eae9
|
||||
bb0269042afd81d63588f52ba6df2514b52cd491
|
||||
@@ -1 +1 @@
|
||||
2592d91f6cf354bc9ad0d94bdc2f661827934ec4
|
||||
19987b373402ee38925c2c71d48ccf44f0d9a766
|
||||
@@ -1,5 +1,6 @@
|
||||
import gradio as gr
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from modules import script_callbacks, extra_networks, prompt_parser
|
||||
from fastapi import FastAPI, Body, Request, Response
|
||||
@@ -14,6 +15,7 @@ from scripts.history import history
|
||||
from scripts.csv import get_csvs, get_csv
|
||||
from scripts.styles import getStyleFullPath, getExtensionCssList
|
||||
from scripts.get_extra_networks import get_extra_networks
|
||||
from scripts.packages import get_packages_state, install_package
|
||||
|
||||
VERSION = '0.0.1'
|
||||
|
||||
@@ -30,8 +32,17 @@ def on_app_started(_: gr.Blocks, app: FastAPI):
|
||||
return {
|
||||
'i18n': get_i18n(True),
|
||||
'translate_apis': get_translate_apis(True),
|
||||
'packages_state': get_packages_state(),
|
||||
'python': sys.executable,
|
||||
}
|
||||
|
||||
@app.post("/physton_prompt/install_package")
|
||||
async def _install_package(request: Request):
|
||||
data = await request.json()
|
||||
if 'name' not in data or 'package' not in data:
|
||||
return {"result": "name or package is required"}
|
||||
return {"result": install_package(data['name'], data['package'])}
|
||||
|
||||
@app.get("/physton_prompt/get_extensions")
|
||||
async def _get_extensions():
|
||||
return {"extends": get_extensions()}
|
||||
|
||||
30
scripts/packages.py
Normal file
30
scripts/packages.py
Normal file
@@ -0,0 +1,30 @@
|
||||
from install import packages
|
||||
import launch
|
||||
|
||||
def get_packages_state():
|
||||
states = []
|
||||
for package_name in packages:
|
||||
package = packages[package_name]
|
||||
item = {
|
||||
'name': package_name,
|
||||
'package': package,
|
||||
'state': False
|
||||
}
|
||||
if launch.is_installed(package_name):
|
||||
item['state'] = True
|
||||
|
||||
states.append(item)
|
||||
|
||||
return states
|
||||
|
||||
def install_package(name, package):
|
||||
result = {'state': False, 'message': ''}
|
||||
try:
|
||||
launch.run_pip(f"install {package}", f"sd-webui-prompt-all-in-one: {name}")
|
||||
result['state'] = True
|
||||
result['message'] = f'install {package} success!'
|
||||
except Exception as e:
|
||||
print(e)
|
||||
print(f'Warning: Failed to install {package}, some preprocessors may not work.')
|
||||
result['message'] = f'Error: install {package} failed!\n' + str(e)
|
||||
return result
|
||||
@@ -67,6 +67,10 @@
|
||||
@use="onUseFavorite"></favorite>
|
||||
<extension-css ref="extensionCss" v-model:language-code="languageCode"
|
||||
:translate-apis="translateApis" :languages="languages"/>
|
||||
<packages-state ref="packagesState" v-model:language-code="languageCode"
|
||||
:translate-apis="translateApis" :languages="languages"
|
||||
@click:select-language="onSelectLanguageClick"
|
||||
:packages-state="packagesState" :python="python"/>
|
||||
|
||||
<div class="physton-paste-popup" v-if="showPastePopup" @click="closePastePopup">
|
||||
<div class="paste-popup-main" @click.stop>
|
||||
@@ -97,10 +101,12 @@ import History from "@/components/history.vue";
|
||||
import IconSvg from "@/components/iconSvg.vue";
|
||||
import ExtensionCss from "@/components/extensionCss.vue";
|
||||
import PromptFormat from "@/components/promptFormat.vue";
|
||||
import PackagesState from "@/components/packagesState.vue";
|
||||
|
||||
export default {
|
||||
name: 'App',
|
||||
components: {
|
||||
PackagesState,
|
||||
PromptFormat,
|
||||
ExtensionCss,
|
||||
IconSvg,
|
||||
@@ -223,6 +229,9 @@ export default {
|
||||
loras: [],
|
||||
lycos: [],
|
||||
embeddings: [],
|
||||
|
||||
python: '',
|
||||
packagesState: [],
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
@@ -368,6 +377,8 @@ export default {
|
||||
this.languageCode = res.i18n.default
|
||||
this.translateApi = res.translate_apis.default
|
||||
this.translateApis = res.translate_apis.apis
|
||||
this.python = res.python
|
||||
this.packagesState = res.packages_state
|
||||
let languages = {}
|
||||
res.i18n.languages.forEach(lang => {
|
||||
languages[lang.code] = lang
|
||||
|
||||
166
src/src/components/packagesState.vue
Normal file
166
src/src/components/packagesState.vue
Normal file
@@ -0,0 +1,166 @@
|
||||
<template>
|
||||
<div class="physton-packages-state" v-if="isOpen" @click="close">
|
||||
<div class="state-main" @click.stop>
|
||||
<div class="state-close" @click="close">
|
||||
<icon-svg name="close"/>
|
||||
</div>
|
||||
<div class="state-body" @click.stop>
|
||||
<div class="today-now-show">
|
||||
<label>
|
||||
<input type="checkbox" :value="todayNotShow" @change="onTodayNotShowChange">
|
||||
{{ getLang('today_not_show') }}
|
||||
</label>
|
||||
</div>
|
||||
<div class="state-body-name">sd-webui-prompt-all-in-one</div>
|
||||
<div class="state-body-language" @click="$emit('click:selectLanguage', $event)">
|
||||
<icon-svg name="i18n"/>
|
||||
<div>Language: {{ langName }}</div>
|
||||
</div>
|
||||
<div class="state-body-desc" v-html="getLang('packages_desc')"></div>
|
||||
<div class="package-list">
|
||||
<div v-for="(item) in packagesState" :key="item.name" class="package-item">
|
||||
<div class="package-name">{{ item.name }}</div>
|
||||
<div :class="['package-state', item.state ? 'installed' : 'not_install']">{{ getLang(item.state ? 'installed' : 'not_install') }}</div>
|
||||
<div class="package-command">{{ getCommand(item) }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="btn-packages-install hover-scale-120" @click="onInstallClick">
|
||||
<icon-svg v-if="loading" name="loading"/>
|
||||
<template v-else>{{ getLang('install') }}</template>
|
||||
</div>
|
||||
<div class="install-result" v-if="showResult">
|
||||
{{ getLang('packages_installing') }}
|
||||
<div class="result-content" v-if="result" ref="result">{{ result }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<script>
|
||||
import LanguageMixin from "@/mixins/languageMixin";
|
||||
import IconSvg from "@/components/iconSvg.vue";
|
||||
|
||||
export default {
|
||||
name: 'PackagesState',
|
||||
components: {IconSvg},
|
||||
mixins: [LanguageMixin],
|
||||
props: {
|
||||
python: {
|
||||
type: String,
|
||||
default: './python',
|
||||
},
|
||||
packagesState: {
|
||||
type: Array,
|
||||
default: () => [],
|
||||
},
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
todayNotShow: false,
|
||||
isOpen: false,
|
||||
loading: false,
|
||||
showResult: false,
|
||||
result: '1112323\nsfsdfsdf\n2222\n3333\n1112323\nsfsdfsdf\n2222\n3333\n1112323\nsfsdfsdf\n2222\n3333',
|
||||
}
|
||||
},
|
||||
emits: [],
|
||||
computed: {},
|
||||
watch: {
|
||||
packagesState: {
|
||||
handler() {
|
||||
if (!this.isAllInstalled()) {
|
||||
this.open()
|
||||
} else {
|
||||
// this.close()
|
||||
}
|
||||
},
|
||||
deep: true,
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
},
|
||||
methods: {
|
||||
isInstalled(packageName) {
|
||||
let installed = false
|
||||
for (let item of this.packagesState) {
|
||||
if (item.name === packageName) {
|
||||
return item.state
|
||||
}
|
||||
}
|
||||
return false
|
||||
},
|
||||
isAllInstalled() {
|
||||
for (let item of this.packagesState) {
|
||||
if (!item.state) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
},
|
||||
getCommand(item) {
|
||||
return `${this.python} -m pip install ${item.package}`
|
||||
},
|
||||
onInstallClick() {
|
||||
if (this.loading) return
|
||||
this.loading = true
|
||||
this.showResult = true
|
||||
this.result = ''
|
||||
let packages = []
|
||||
this.packagesState.forEach((item) => {
|
||||
if (!item.state) packages.push(item)
|
||||
})
|
||||
const complete = (state = false) => {
|
||||
this.loading = false
|
||||
if (state) {
|
||||
this.result += '\ncomplete!'
|
||||
setTimeout(this.close, 2000)
|
||||
}
|
||||
this.scrollToBottom()
|
||||
}
|
||||
const install = () => {
|
||||
let item = packages.shift()
|
||||
if (!item) return complete(true)
|
||||
this.gradioAPI.installPackage(item.name, item.package).then(res => {
|
||||
this.result += `${res.message}\n`
|
||||
if (res.state) {
|
||||
this.scrollToBottom()
|
||||
install()
|
||||
} else {
|
||||
complete(false)
|
||||
}
|
||||
}).catch(err => {
|
||||
console.log(err)
|
||||
this.result += `${item.name} install failed\n${err.message}\n`
|
||||
complete(false)
|
||||
})
|
||||
}
|
||||
install()
|
||||
},
|
||||
scrollToBottom() {
|
||||
this.$nextTick(() => {
|
||||
this.$refs.result.scrollTop = this.$refs.result.scrollHeight
|
||||
})
|
||||
},
|
||||
onTodayNotShowChange() {
|
||||
this.todayNotShow = !this.todayNotShow
|
||||
this.gradioAPI.setData('packagesStateTodayNotShow', new Date().toLocaleDateString())
|
||||
},
|
||||
open() {
|
||||
this.gradioAPI.getData('packagesStateTodayNotShow').then(res => {
|
||||
if (res && res === new Date().toLocaleDateString()) {
|
||||
this.close()
|
||||
} else {
|
||||
this.result = ''
|
||||
this.loading = false
|
||||
this.showResult = false
|
||||
this.isOpen = true
|
||||
}
|
||||
}).catch(err => {
|
||||
})
|
||||
},
|
||||
close() {
|
||||
this.isOpen = false
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
@@ -9,7 +9,7 @@
|
||||
<optgroup v-for="typeGroup in supportApi" :key="typeGroup.type"
|
||||
:label="getLang(typeGroup.type)">
|
||||
<option v-for="item in typeGroup.children" :key="item.key" :value="item.key">
|
||||
{{ item.name }} -- QPS: {{ item.concurrent || 1 }}
|
||||
{{ getItemName(item.name) }} QPS: {{ item.concurrent || 1 }}
|
||||
</option>
|
||||
</optgroup>
|
||||
</select>
|
||||
@@ -186,6 +186,11 @@ Github: Physton/sd-webui-prompt-all-in-one`,
|
||||
this.onlyCsvOnAutoValue = this.onlyCsvOnAuto
|
||||
this.refreshCSVs()
|
||||
},
|
||||
getItemName(name) {
|
||||
name = name.replace('[Free] ', '[' + this.getLang('free') + '] ')
|
||||
name = name.replace('[ApiKey] ', '[' + this.getLang('apply_for_free') + '] ')
|
||||
return name
|
||||
},
|
||||
refreshCSVs() {
|
||||
if (this.tagCompleteFilesLoading) return
|
||||
this.tagCompleteFilesLoading = true
|
||||
|
||||
@@ -23,6 +23,11 @@ export default class GradioAPI {
|
||||
return (await this.api.get("/get_config")).data
|
||||
}
|
||||
|
||||
async installPackage(name, _package) {
|
||||
const config = {timeout: 10000000}
|
||||
return (await this.api.post("/install_package", {name, 'package': _package}, config)).data.result
|
||||
}
|
||||
|
||||
async getExtensions() {
|
||||
return (await this.api.get("/get_extensions")).data.extensions
|
||||
}
|
||||
|
||||
1676
styles/main.less
1676
styles/main.less
File diff suppressed because it is too large
Load Diff
1
styles/main.less.REMOVED.git-id
Normal file
1
styles/main.less.REMOVED.git-id
Normal file
@@ -0,0 +1 @@
|
||||
5d6732bf0fc8494037d43a8e2b65d495a649edec
|
||||
@@ -1 +1 @@
|
||||
30d9f0cf4a75acba1618db60b4e1e1737b427f70
|
||||
5d20d8adf45e7c1d6da2e79f191e053df40346f5
|
||||
@@ -1 +1 @@
|
||||
380237b2fb55734182a38c6e3ea46faef5276231
|
||||
2f0f6e4af9b14250f8d193613c119b72b5e11853
|
||||
Reference in New Issue
Block a user