v1.71
parent
e61e3fbc4f
commit
fc6c41a090
|
|
@ -1,6 +1,7 @@
|
|||
/cache/*
|
||||
/yours/*
|
||||
!/yours/.gitkeep
|
||||
/scripts/__pycache__
|
||||
/scripts/__pycache__/*
|
||||
*.git*
|
||||
*.swp
|
||||
|
|
|
|||
|
|
@ -2,12 +2,12 @@
|
|||
* @Author: thisjam 3213441409@qq.com
|
||||
* @Date: 2024-03-24 15:56:01
|
||||
* @LastEditors: Six_God_K
|
||||
* @LastEditTime: 2024-04-07 16:24:56
|
||||
* @FilePath: \undefinedg:\project\sd.webui\webui\extensions\sd-webui-oldsix-prompt\README.md
|
||||
* @LastEditTime: 2024-04-14 18:52:37
|
||||
* @FilePath: \webui\extensions\sd-webui-oldsix-prompt\README.md
|
||||
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
||||
-->
|
||||
|
||||
# sd-webui-oldsix_prompt v1.70
|
||||
# sd-webui-oldsix_prompt v1.71
|
||||
### 老版词库 @路过银河&网上收集
|
||||
### 新词库由群里小伙伴 @麻瓜 @万碎爷 @元一斤 整理
|
||||
### 开源不易,别跑到Issues发牢骚,有重要的事@我QQ,前段时间忙,群里那么多人真的管不过来,大家文明交流 ###
|
||||
|
|
@ -34,7 +34,7 @@
|
|||
### 使用方法
|
||||
* 左键输入正向提示框、 右键输入负向提示框
|
||||
* 支持自定义词库【把你自己整理词库文件放在yours文件夹下,不受更新会被覆盖影响】
|
||||
* 支持翻译、权重调整、位置调整。Alt+Q键呼出隐藏面板
|
||||
* 支持中文输入、权重调整、位置调整。Alt+Q键呼出隐藏面板
|
||||
* 支持动态随机提示词 本插件专属语法示例:#[red,blue,yellow]
|
||||
|
||||
---
|
||||
|
|
|
|||
23
install.py
23
install.py
|
|
@ -0,0 +1,23 @@
|
|||
'''
|
||||
Author: Six_God_K
|
||||
Date: 2024-03-28 09:32:28
|
||||
LastEditors: Six_God_K
|
||||
LastEditTime: 2024-04-07 23:45:47
|
||||
FilePath: \webui\extensions\sd-webui-oldsix-prompt\install.py
|
||||
Description:
|
||||
|
||||
Copyright (c) 2024 by ${git_name_email}, All Rights Reserved.
|
||||
'''
|
||||
import pkg_resources
|
||||
import launch
|
||||
import requests
|
||||
min_version = "2.31.0"
|
||||
current_version = pkg_resources.get_distribution("requests").version
|
||||
if not launch.is_installed('requests'):
|
||||
launch.run_pip("install requests")
|
||||
else:
|
||||
if pkg_resources.parse_version(current_version) < pkg_resources.parse_version(min_version):
|
||||
launch.run_pip("install --upgrade requests")
|
||||
if not launch.is_installed('fastapi'):
|
||||
launch.run_pip("install fastapi")
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Binary file not shown.
|
|
@ -2,7 +2,7 @@
|
|||
Author: Six_God_K
|
||||
Date: 2024-03-24 15:56:01
|
||||
LastEditors: Six_God_K
|
||||
LastEditTime: 2024-04-04 10:26:16
|
||||
LastEditTime: 2024-04-14 18:48:58
|
||||
FilePath: \webui\extensions\sd-webui-oldsix-prompt\scripts\old_six_prompt.py
|
||||
Description:
|
||||
|
||||
|
|
@ -13,10 +13,19 @@ import os,json
|
|||
import json
|
||||
import random
|
||||
import re
|
||||
from bs4 import BeautifulSoup
|
||||
from modules import shared,scripts,script_callbacks
|
||||
import requests
|
||||
from fastapi import FastAPI
|
||||
from scripts.transbd import get as transbd
|
||||
from fastapi import FastAPI,Request
|
||||
import sys
|
||||
|
||||
|
||||
try:
|
||||
from transerver import Translator,baidu,freebd
|
||||
except:
|
||||
transerver_path = os.path.join(os.path.dirname(__file__), "transerver")
|
||||
sys.path.append(transerver_path)
|
||||
import Translator,baidu,freebd
|
||||
|
||||
|
||||
current_script = os.path.realpath(__file__)
|
||||
|
|
@ -47,14 +56,18 @@ def loadjsonfiles(path,dic):
|
|||
dic[filename]=res
|
||||
|
||||
|
||||
|
||||
|
||||
def contains_chinese(s):
|
||||
pattern = re.compile(r'[\u4e00-\u9fff]+')
|
||||
return bool(pattern.search(s))
|
||||
|
||||
|
||||
|
||||
def translate(text):
|
||||
if(transObj['server']=='free'):
|
||||
trans_server=freebd.FreeBDTranslator()
|
||||
return Translator.translate_text(trans_server, None,None,text)
|
||||
else:
|
||||
trans_server=baidu.BaiduTranslator()
|
||||
return Translator.translate_text(trans_server, transObj['appid'],transObj['secret'],text)
|
||||
|
||||
|
||||
|
||||
|
|
@ -62,6 +75,19 @@ def contains_chinese(s):
|
|||
|
||||
|
||||
|
||||
def extract_lora(prompt):
|
||||
pattern = r'<lora.*?>'
|
||||
lora_arr = re.findall(pattern, prompt)
|
||||
prompt = re.sub(pattern, '', prompt)
|
||||
return lora_arr, prompt
|
||||
|
||||
def add_lora(lora_arr,prompt):
|
||||
for index, value in enumerate(lora_arr):
|
||||
prompt += value + ',' if index != len(lora_arr)-1 else value
|
||||
return prompt
|
||||
|
||||
|
||||
|
||||
class Script(scripts.Script):
|
||||
|
||||
|
||||
|
|
@ -81,12 +107,16 @@ class Script(scripts.Script):
|
|||
def before_process(self, p, *args):
|
||||
p.prompt= extract_tags(p.prompt)
|
||||
p.negative_prompt= extract_tags(p.negative_prompt)
|
||||
prompt_lora_arr,p.prompt=extract_lora(p.prompt)
|
||||
nprompt_lora_arr,p.negative_prompt=extract_lora(p.negative_prompt)
|
||||
|
||||
# if(transMode==False):
|
||||
if(contains_chinese(p.prompt)==True):
|
||||
p.prompt=transbd(p.prompt)
|
||||
p.prompt=translate(p.prompt)
|
||||
if(contains_chinese(p.negative_prompt)==True):
|
||||
p.negative_prompt=transbd(p.negative_prompt)|''
|
||||
|
||||
p.negative_prompt=translate(p.negative_prompt)|''
|
||||
p.prompt=add_lora(prompt_lora_arr,p.prompt)
|
||||
p.negative_prompt=add_lora(nprompt_lora_arr,p.negative_prompt)
|
||||
|
||||
# def process(self, p, *args):
|
||||
# print(p.prompt)
|
||||
|
|
@ -114,7 +144,11 @@ def extract_tags(text):
|
|||
text = re.sub(pattern, rdtext, text,count=1)
|
||||
return text
|
||||
|
||||
|
||||
transObj={
|
||||
'server':'',
|
||||
'appid':'',
|
||||
'secret':''
|
||||
}
|
||||
|
||||
def on_app_started(_: gr.Blocks, app: FastAPI):
|
||||
@app.get("/api/sixgod/getJsonFiles")
|
||||
|
|
@ -126,6 +160,23 @@ def on_app_started(_: gr.Blocks, app: FastAPI):
|
|||
global transMode
|
||||
transMode=isEn
|
||||
|
||||
@app.post("/api/sixgod/setTransServer")
|
||||
async def setTransServer(request:Request):
|
||||
postData=await request.json()
|
||||
transObj['server']=postData['server']
|
||||
transObj['appid']=postData['appid']
|
||||
transObj['secret']=postData['secret']
|
||||
return 'ok'
|
||||
|
||||
@app.get("/api/sixgod/testTransServer")
|
||||
async def testTransServer():
|
||||
trans_text = translate('苹果')
|
||||
if (trans_text!='apple'):
|
||||
trans_text='翻译失败'
|
||||
else:
|
||||
trans_text='接口正常'
|
||||
return trans_text
|
||||
|
||||
|
||||
|
||||
script_callbacks.on_app_started(on_app_started)
|
||||
|
|
@ -2,8 +2,8 @@
|
|||
Author: thisjam 3213441409@qq.cm
|
||||
Date: 2024-01-02 14:11:27
|
||||
LastEditors: Six_God_K
|
||||
LastEditTime: 2024-04-04 10:25:19
|
||||
FilePath: \webui\extensions\sd-webui-oldsix-prompt\scripts\baidu.py
|
||||
LastEditTime: 2024-04-08 08:33:53
|
||||
FilePath: \webui\extensions\sd-webui-oldsix-prompt\scripts\transbd.py
|
||||
Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
||||
'''
|
||||
import requests
|
||||
|
|
@ -28,6 +28,7 @@ def decodeText(data):
|
|||
return decodeLong(jsonObj)
|
||||
|
||||
def get(trans_text):
|
||||
print(requests.__version__)
|
||||
url1="https://fanyi.baidu.com/transapi"
|
||||
headers = {
|
||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36',
|
||||
|
|
@ -51,4 +52,4 @@ def get(trans_text):
|
|||
|
||||
if __name__ == '__main__':
|
||||
# print(get('(拼贴1.5),(关注细节),精细的细节,景深,极其细致的CG unity 8k壁纸,杰作,吸血鬼女孩,美丽的深紫色长发,(1个女孩:1.5),((详细的美丽蝴蝶) ),(黑色吊带裙:1.3),(((个展)),(水中卷毛)),(红水:1.2),(蓝色背景:1.3),(细节背景),(星空 在美丽的细节),(朦胧的雾),完美的细节,美丽华丽的项链,{{{真实细致的脸}}},高曝光,明亮的光线,(反光玻璃碎片:1.7),(小玻璃球:1), (宝石纹理:1.5),彩色瞳孔细节,,(极光),眼泪,电影角度,紫玫瑰花框,色差,(破镜:0.7),Armin Hansen'))
|
||||
print(get('1girl,长头发,<lora:testaaa:1.0>'))
|
||||
print(get('一个黄色头发的美女'))
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
from abc import ABC, abstractmethod
|
||||
import hashlib
|
||||
|
||||
class TranslatorInterface(ABC):
|
||||
@abstractmethod
|
||||
def translate(self,appid:str,secretKey:str,text: str,headers, lang_from: str, lang_to: str) -> str:
|
||||
pass
|
||||
|
||||
def encrypt_string_to_md5(self,input_string):
|
||||
encoded_string = input_string.encode()
|
||||
md5_hash = hashlib.md5()
|
||||
md5_hash.update(encoded_string)
|
||||
hashed_value = md5_hash.hexdigest()
|
||||
return hashed_value
|
||||
|
||||
def translate_text(translator: TranslatorInterface,appid:str,secretKey:str, text: str, lang_from: str='zh', lang_to: str='en'):
|
||||
headers = {
|
||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36',
|
||||
'content-type': 'application/x-www-form-urlencoded; charset=UTF-8'
|
||||
}
|
||||
return translator.translate(appid,secretKey,text, headers,lang_from, lang_to)
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
'''
|
||||
Author: Six_God_K
|
||||
Date: 2024-04-13 12:54:31
|
||||
LastEditors: Six_God_K
|
||||
LastEditTime: 2024-04-13 15:50:47
|
||||
FilePath: \ComfyUI\custom_nodes\comfyui-sixgod_prompt\transerver\baidu.py
|
||||
Description:
|
||||
|
||||
Copyright (c) 2024 by ${git_name_email}, All Rights Reserved.
|
||||
'''
|
||||
import Translator
|
||||
import requests
|
||||
import json
|
||||
|
||||
class BaiduTranslator(Translator.TranslatorInterface):
|
||||
def translate(self,appid:str,secretKey:str,text: str,headers, lang_from: str, lang_to: str) -> str:
|
||||
url='https://fanyi-api.baidu.com/api/trans/vip/translate'
|
||||
|
||||
postdata={
|
||||
"appid":appid,
|
||||
"from": lang_from,
|
||||
"to": lang_to,
|
||||
"q": text,
|
||||
"salt": "1435660288",# 随机数
|
||||
"sign":self.encrypt_string_to_md5(appid+text+"1435660288"+secretKey)
|
||||
}
|
||||
|
||||
try:
|
||||
resdata= requests.post(url,headers=headers,data=postdata)
|
||||
jsonObj=json.loads(resdata.content.decode('utf-8'))
|
||||
if('error_code'in jsonObj):
|
||||
print('trans_result erro')
|
||||
return text
|
||||
return jsonObj['trans_result'][0]['dst']
|
||||
|
||||
|
||||
except requests.exceptions.RequestException as e:
|
||||
print(e)
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
appid='xx'
|
||||
secretKey='xx'
|
||||
text="今天天气非常不错"
|
||||
baidu_translator = BaiduTranslator()
|
||||
res = Translator.translate_text(baidu_translator, appid,secretKey,text)
|
||||
print(res)
|
||||
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
'''
|
||||
Author: Six_God_K
|
||||
Date: 2024-04-13 15:23:00
|
||||
LastEditors: Six_God_K
|
||||
LastEditTime: 2024-04-13 15:51:19
|
||||
FilePath: \ComfyUI\custom_nodes\comfyui-sixgod_prompt\transerver\freebd.py
|
||||
Description:
|
||||
|
||||
Copyright (c) 2024 by ${git_name_email}, All Rights Reserved.
|
||||
'''
|
||||
import Translator
|
||||
import requests
|
||||
import json
|
||||
|
||||
class FreeBDTranslator(Translator.TranslatorInterface):
|
||||
def __init__(self):
|
||||
pass
|
||||
def translate(self,appid:str,secretKey:str,text: str,headers, lang_from: str, lang_to: str) -> str:
|
||||
url='https://fanyi.baidu.com/transapi'
|
||||
postdata={
|
||||
"from": "zh",
|
||||
"to": "en",
|
||||
"query": text,
|
||||
"source": "txt",
|
||||
}
|
||||
try:
|
||||
res= requests.post(url,headers=headers,data=postdata)
|
||||
return self.decodeText(res,text)
|
||||
|
||||
except requests.exceptions.RequestException as e:
|
||||
print(f"err:{e}")
|
||||
return text
|
||||
|
||||
def decodeLong(self,data):
|
||||
return data['data'][0]['dst']
|
||||
def decodeShort(self,data):
|
||||
result=json.loads(data['result'])
|
||||
restcont=result['content'][0]['mean'][0]['cont']
|
||||
restext=list(restcont.keys())[0]
|
||||
return restext
|
||||
def decodeText(self,data,trans_text):
|
||||
jsonObj=json.loads(data.content.decode('utf-8'))
|
||||
if 'type' in jsonObj:
|
||||
if(jsonObj['type']==1): # type=1||2
|
||||
return self.decodeShort(jsonObj)
|
||||
else :
|
||||
return self.decodeLong(jsonObj)
|
||||
else:
|
||||
print('trans_result erro')
|
||||
return trans_text
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
text="今天天气非常不错"
|
||||
baidu_translator = FreeBDTranslator()
|
||||
res = Translator.translate_text(baidu_translator, None,None,text)
|
||||
print(res)
|
||||
|
||||
Loading…
Reference in New Issue