main
thisjam 2024-04-27 13:33:56 +08:00
parent 57db14d104
commit 61e7f677f9
23 changed files with 583 additions and 64 deletions

2
.gitignore vendored
View File

@ -7,6 +7,8 @@
*.swp
*.pyc
*.idea*
/models/*
!/models/.gitkeep

View File

@ -1,42 +1,54 @@
<!--
* @Author: thisjam 3213441409@qq.com
* @Date: 2024-03-24 15:56:01
* @LastEditors: Six_God_K
* @LastEditTime: 2024-04-16 12:43:24
* @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.72
# v1.74
### 老版词库 @路过银河&网上收集
### 新词库由群里小伙伴 @麻瓜 @万碎爷 @元一斤 整理
### 开源不易别跑到Issues发牢骚有重要的事@我QQ前段时间忙群里那么多人真的管不过来大家文明交流 ###
### 觉得好用的可以给我点颗星。
### 开源不易,觉得好用的可以给我点颗星 ###
#### 英文不好不用怕彻底解决prompt对于国人不友好的痛点整理了多个分类上千个提示词无需英文快速输入提示词
#### 词库会持续更新
* AI交流Q群390942276 各种疑难解答 帮你踩坑
* 已分好类别的词库,不会做太大改动,尽量不破坏大家的使用习惯
* webUI1.21以下版本不支持如果无法显示词库请升级webUI到最新尤其是linux云端用户部署的可能是古老版本的环境请升级到新版webUI
---
* 特别鸣谢群里兄弟们的支持
<p> @鑫鑫、@六尘、@以及不愿意透露姓名的水友们</p>
* 插件已给一些公司、和个人都大大提升了效率有定制化插件、软件、APP、小程序的需求也可以单独联系我喜欢本插件的可以支持一下小弟
# <img src="imgs/wx.jpg" width="300" height="400" />
### 安装方法
* 方法1、复制地址到你的webui中 从网站安装后应用并重启
### 插件安装
* comfyui版本
```sh
https://github.com/thisjam/sd-webui-oldsix-prompt.git
```
* 方法2、 如果webui中无法安装的可以选择手动安装点击页面上的code->DownloadZip 解压以后放在你的sd文件夹下的extensions文件夹后应用并重启
* webui、forge版本
```sh
https://github.com/thisjam/comfyui-sixgod_prompt.git
```
---
### 使用方法
* 左键输入正向提示框、 右键输入负向提示框
* 支持自定义词库【把你自己整理词库文件放在yours文件夹下不受更新会被覆盖影响】
* 支持中文输入、权重调整、位置调整。Alt+Q键呼出隐藏面板
* 支持动态随机提示词 本插件专属语法示例:#[red,blue,yellow]
* 支持动态随机提示词 本插件专属语法示例:#[red,blue,yellow]
* comyui版需要绑定数据提示词节点的位置在上的是正面位置在下是负面提示框节点一个个添加不要复制
---
### 大模型配置(可用于翻译和随机灵感)
1. 安装 llama_cpp_python
* 方式一、参考https://github.com/abetlen/llama-cpp-python
* 方式二、到本插件目录下的cpp文件夹下安装离线包
* (注:我仅提供了两个版本 其他版本在地址https://github.com/abetlen/llama-cpp-python/releases)
3. 大模型下载(需要.gguf格式
* 建议千问大模型推荐qwen1_5-4b-chat-q2_k.gguf
* 地址https://huggingface.co/Qwen
* 下载后放到插件目录下的models文件夹下
---
### 展示
# <img src="imgs/1.png" width="768" height="512" />
# <img src="imgs/2.png" width="768" height="512" />

Binary file not shown.

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 376 KiB

After

Width:  |  Height:  |  Size: 98 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 400 KiB

After

Width:  |  Height:  |  Size: 328 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 250 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 252 KiB

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

99
json/景观.json Normal file
View File

@ -0,0 +1,99 @@
{
"自然景观":{
"黄石国家公园": "yellowstone national park",
"大峡谷": "grand canyon",
"珠穆朗玛峰": "mount everest",
"大堡礁": "great barrier reef",
"撒哈拉沙漠": "sahara desert",
"亚马逊雨林": "amazon rainforest",
"伊瓜苏大瀑布": "iguazu falls",
"维多利亚瀑布": "victoria falls",
"死海": "dead sea",
"科莫多国家公园": "komodo national park",
"加拉帕戈斯群岛": "galapagos islands",
"乞力马扎罗山": "mount kilimanjaro",
"诺罗威国家公园": "norwegian fjords",
"巴厘岛": "bali",
"安第斯山脉": "andes",
"摩洛哥蓝色小镇": "chefchaouen",
"澳大利亚珊瑚海": "coral sea",
"阿尔卑斯山": "alps",
"巴塔哥尼亚": "patagonia",
"哈里森湖洞穴": "harrison's cave",
"泰姬陵": "taj mahal",
"尼亚加拉大瀑布": "niagara falls",
"极光": "aurora borealis",
"喜马拉雅山脉": "himalayas",
"乌鲁鲁": "uluru",
"黄金海岸": "gold coast",
"马尔代夫": "maldives",
"马丘比丘": "machu picchu",
"塞尔维亚的德里纳河": "drina river"
},
"人造景观":{
"万里长城": "great wall of china",
"自由女神像": "statue of liberty",
"埃菲尔铁塔": "eiffel tower",
"大本钟": "big ben",
"白金汉宫": "buckingham palace",
"圣彼得大教堂": "st. peter's basilica",
"金门桥": "golden gate bridge",
"古罗马斗兽场": "colosseum",
"悉尼歌剧院": "sydney opera house",
"伦敦眼": "london eye",
"克里姆林宫": "kremlin",
"红场": "red square",
"莫斯科圣瓦西里大教堂": "saint basil's cathedral",
"比萨斜塔": "leaning tower of pisa",
"卢浮宫": "louvre",
"凡尔赛宫": "palace of versailles",
"尼斯湖": "loch ness",
"圣保罗大教堂": "st. paul's cathedral",
"埃德蒙顿购物中心": "west edmonton mall",
"布拉格城堡": "prague castle",
"新天鹅堡": "neuschwanstein castle",
"泰姬陵": "taj mahal",
"马丘比丘": "machu picchu",
"克里斯特救世像": "christ the redeemer",
"巴比伦空中花园": "hanging gardens of babylon",
"亚历山大灯塔": "lighthouse of alexandria",
"宙斯神庙": "temple of artemis",
"摩洛哥蓝色小镇": "chefchaouen",
"阿尔罕布拉宫": "alhambra",
"佩特拉古城": "petra",
"布拉格天文钟": "prague astronomical clock",
"春秋战国时期的秦始皇兵马俑": "terracotta army",
"埃及金字塔": "egyptian pyramids",
"吉萨大金字塔": "great pyramid of giza",
"斯芬克斯": "sphinx",
"巴黎圣母院": "notre-dame de paris",
"威尼斯水城": "venice",
"阿姆斯特丹运河": "amsterdam canals",
"巴塞罗那圣家堂": "sagrada familia",
"米兰大教堂": "milan cathedral",
"维也纳国家歌剧院": "vienna state opera",
"比利时布鲁日的布鲁日广场": "markt square bruges",
"荷兰风车": "dutch windmills",
"巴塞罗那哥特区": "gothic quarter barcelona",
"佛罗伦萨大教堂": "florence cathedral",
"慕尼黑啤酒节": "oktoberfest munich",
"巴拿马运河": "panama canal",
"好莱坞标志": "hollywood sign",
"帝国大厦": "empire state building",
"自然历史博物馆": "natural history museum",
"史密森尼博物馆": "smithsonian museum",
"卢浮宫金字塔": "louvre pyramid",
"迪士尼乐园": "disneyland",
"百老汇": "broadway",
"时代广场": "times square",
"拉斯维加斯大道": "las vegas strip",
"旧金山唐人街": "chinatown san francisco",
"尼亚加拉瀑布": "niagara falls",
"肯辛顿宫": "kensington palace",
"伦敦塔桥": "tower bridge",
"圣马可广场": "st. mark's square"
}
}

File diff suppressed because one or more lines are too long

4
models/.gitkeep Normal file
View File

@ -0,0 +1,4 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore

View File

@ -2,7 +2,7 @@
Author: Six_God_K
Date: 2024-03-24 15:56:01
LastEditors: Six_God_K
LastEditTime: 2024-04-14 18:48:58
LastEditTime: 2024-04-27 11:46:16
FilePath: \webui\extensions\sd-webui-oldsix-prompt\scripts\old_six_prompt.py
Description:
@ -20,11 +20,11 @@ import sys
try:
from transerver import Translator,baidu,freebd
from transerver import Translator,baidu,freebd,llmTranslate,llm
except:
transerver_path = os.path.join(os.path.dirname(__file__), "transerver")
sys.path.append(transerver_path)
import Translator,baidu,freebd
import Translator,baidu,freebd,llmTranslate,llm
current_script = os.path.realpath(__file__)
@ -61,10 +61,13 @@ def contains_chinese(s):
def translate(text):
if(transObj['server']=='free'):
if(transObj['server']=='free'):
trans_server=freebd.FreeBDTranslator()
return Translator.translate_text(trans_server, None,None,text)
else:
return Translator.translate_text(trans_server,text)
elif(transObj['server']=='llm'):
trans_server=llmTranslate.LLMTranslator()
return Translator.translate_text(trans_server,text,transObj['llmName'])
elif(transObj['server']=='baidu'):
trans_server=baidu.BaiduTranslator()
return Translator.translate_text(trans_server, transObj['appid'],transObj['secret'],text)
@ -146,7 +149,8 @@ def extract_tags(text):
transObj={
'server':'',
'appid':'',
'secret':''
'secret':'',
'llmName':''
}
def on_app_started(_: gr.Blocks, app: FastAPI):
@ -165,16 +169,24 @@ def on_app_started(_: gr.Blocks, app: FastAPI):
transObj['server']=postData['server']
transObj['appid']=postData['appid']
transObj['secret']=postData['secret']
transObj['llmName']=postData['llmName']
return 'ok'
@app.get("/api/sixgod/testTransServer")
async def testTransServer():
trans_text = translate('苹果')
if (trans_text!='apple'):
if (trans_text.lower()!='apple'):
trans_text='翻译失败'
else:
trans_text='接口正常'
return trans_text
@app.post("/api/sixgod/imaginePrompt")
async def imaginePrompt(request:Request):#不注明类型无法请求 422
post = await request.json()
Preset='你是一名AI提示词工程师用提供的关键词构思一副精美的构图画面只需要提示词不要你的感受自定义风格、场景、装饰等尽量详细用中文回复'
res=llm.chat(post,transObj['llmName'],Preset)
return res

View File

@ -1,9 +1,26 @@
'''
Author: Six_God_K
Date: 2024-04-13 12:12:19
LastEditors: Six_God_K
LastEditTime: 2024-04-26 22:06:41
FilePath: \webui\extensions\sd-webui-oldsix-prompt\scripts\transerver\Translator.py
Description:
Copyright (c) 2024 by ${git_name_email}, All Rights Reserved.
'''
from abc import ABC, abstractmethod
import hashlib
class TranslatorInterface(ABC):
def __init__(self):
self.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'
}
self.lang_from='zh'
self.lang_to='en'
@abstractmethod
def translate(self,appid:str,secretKey:str,text: str,headers, lang_from: str, lang_to: str) -> str:
def translate(self,*args, **kwargs) -> str:
pass
def encrypt_string_to_md5(self,input_string):
@ -13,9 +30,7 @@ class TranslatorInterface(ABC):
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)
def translate_text(translator: TranslatorInterface,*args, **kwargs):
return translator.translate(*args, **kwargs)

View File

@ -2,8 +2,8 @@
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
LastEditTime: 2024-04-26 22:05:11
FilePath: \webui\extensions\sd-webui-oldsix-prompt\scripts\transerver\baidu.py
Description:
Copyright (c) 2024 by ${git_name_email}, All Rights Reserved.
@ -13,20 +13,20 @@ 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:
def translate(self,appid:str,secretKey:str,text: str) -> str:
url='https://fanyi-api.baidu.com/api/trans/vip/translate'
postdata={
"appid":appid,
"from": lang_from,
"to": lang_to,
"from": self.lang_from,
"to": self.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)
resdata= requests.post(url,headers=self.headers,data=postdata)
jsonObj=json.loads(resdata.content.decode('utf-8'))
if('error_code'in jsonObj):
print('trans_result erro')
@ -40,9 +40,9 @@ class BaiduTranslator(Translator.TranslatorInterface):
if __name__ == '__main__':
appid='xx'
secretKey='xx'
text="今天天气非常不错"
appid='202406401002012191'
secretKey='qKvBIOYoQsiqSm9RjlcGU'
text="红色的气球"
baidu_translator = BaiduTranslator()
res = Translator.translate_text(baidu_translator, appid,secretKey,text)
print(res)

View File

@ -2,8 +2,8 @@
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
LastEditTime: 2024-04-26 22:05:30
FilePath: \webui\extensions\sd-webui-oldsix-prompt\scripts\transerver\freebd.py
Description:
Copyright (c) 2024 by ${git_name_email}, All Rights Reserved.
@ -13,18 +13,16 @@ 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'
def translate(self,text) -> str:
url='https://fanyi.baidu.com/transapi'
postdata={
"from": "zh",
"to": "en",
"from": self.lang_from,
"to": self.lang_to,
"query": text,
"source": "txt",
}
try:
res= requests.post(url,headers=headers,data=postdata)
res= requests.post(url,headers=self.headers,data=postdata)
return self.decodeText(res,text)
except requests.exceptions.RequestException as e:
@ -54,8 +52,8 @@ class FreeBDTranslator(Translator.TranslatorInterface):
if __name__ == '__main__':
text="今天天气非常不错"
text="一个女孩在雨中行走"
baidu_translator = FreeBDTranslator()
res = Translator.translate_text(baidu_translator, None,None,text)
res = Translator.translate_text(baidu_translator,text)
print(res)

44
scripts/transerver/llm.py Normal file
View File

@ -0,0 +1,44 @@
'''
Author: Six_God_K
Date: 2024-04-26 22:05:49
LastEditors: Six_God_K
LastEditTime: 2024-04-27 11:26:14
FilePath: \webui\extensions\sd-webui-oldsix-prompt\scripts\transerver\llm.py
Description:
Copyright (c) 2024 by ${git_name_email}, All Rights Reserved.
'''
import time
import os
import random
# from llama_cpp import Llama
try:
from llama_cpp import Llama
current_script = os.path.realpath(__file__)
plug_script=os.path.dirname(os.path.dirname(os.path.dirname(current_script)))
extension_path = os.path.join(plug_script,'models')
def chat(question,modelName="qwen1_5-4b-chat-q2_k",Preset="Translate Chinese into English"):
llm = Llama(
model_path=os.path.join(extension_path,modelName)+'.gguf',
)
res=llm.create_chat_completion(
messages = [
{"role": "system", "content":Preset},
{
"role": "user",
"content": question
}
],
temperature=1.2
)
return(res['choices'][0]["message"]['content'])
except Exception as e:
err_msg='找不到llama_cpp模块'
print(err_msg)

View File

@ -0,0 +1,30 @@
'''
Author: Six_God_K
Date: 2024-04-13 12:54:31
LastEditors: Six_God_K
LastEditTime: 2024-04-26 22:07:07
FilePath: \webui\extensions\sd-webui-oldsix-prompt\scripts\transerver\llmTranslate.py
Description:
Copyright (c) 2024 by ${git_name_email}, All Rights Reserved.
'''
import Translator
import requests
import json
import llm
class LLMTranslator(Translator.TranslatorInterface):
def translate(self,text: str,modelName:str) -> str:
return llm.chat(text,modelName)
if __name__ == '__main__':
appid='xx'
secretKey='xx'
text="今天天气非常不错,我们出去玩吧"
modelName='qwen/qwen1_5-4b-chat-q5_k_m'
llm_translator = LLMTranslator()
res =Translator.translate_text(llm_translator,text,modelName)
print(res)

File diff suppressed because one or more lines are too long

25
更新日志.txt Normal file
View File

@ -0,0 +1,25 @@
-----v1.5 -----------------------------------------------------
添加设置菜单
1、翻译栏提供自定义翻译API目前支持百度接口
百度接口
标准版:免费调用量 5万字符/月 单次最长请求1000字符 QPS=1
高级版免费调用量100万字符/月 单次最长请求6000字符 QPS=10
接口自行申请
2、添加自定义快捷键
-----v1.51-----------------------------------------------------
修复自定义快复合捷键时,单键也生效
-----v1.71-----------------------------------------------------
和comfyui同步版本
添加了随机灵感
-----v1.72-----------------------------------------------------
添加快速查找词库功能
-----v1.73-----------------------------------------------------
支持本地大语言模型,用于关键词随机灵感
-----v1.74-----------------------------------------------------
词库小调整