├── requirements.txt ├── image ├── demo.png └── fanyi2.png ├── __init__.py ├── README.md ├── workflow.json └── fanyi.py /requirements.txt: -------------------------------------------------------------------------------- 1 | requests 2 | json 3 | random 4 | hashlib -------------------------------------------------------------------------------- /image/demo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SoftMeng/ComfyUI-FanYi/HEAD/image/demo.png -------------------------------------------------------------------------------- /image/fanyi2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SoftMeng/ComfyUI-FanYi/HEAD/image/fanyi2.png -------------------------------------------------------------------------------- /__init__.py: -------------------------------------------------------------------------------- 1 | from .fanyi import NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS 2 | 3 | __all__ = ['NODE_CLASS_MAPPINGS', 'NODE_DISPLAY_NAME_MAPPINGS'] 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ComfyUI_FanYi 2 | 3 | ## 功能简述 4 | 5 | 一个简单的中英文翻译,使用的百度翻译(机器翻译). 6 | 7 | ## 使用图例 8 | 9 | ### 申请百度翻译 10 | 11 | 在百度翻译官网申请翻译API: 12 | 13 | 官网地址:https://api.fanyi.baidu.com/ 14 | 15 | ![fanyi2.png](image%2Ffanyi2.png) 16 | 17 | ### 修改配置 18 | 19 | 在[fanyi.py](fanyi.py)中修改如下内容: 20 | 21 | ```shell 22 | # Set your own appid/appkey. 23 | appid = 'xxxxx' 24 | appkey = 'xxxxxxx' 25 | ``` 26 | 27 | ### Node使用 28 | 29 | ![demo.png](image%2Fdemo.png) 30 | 31 | ## 工作流举例 32 | 33 | SDXL模型下载地址(欢迎点赞点关注): https://www.liblib.art/modelinfo/5913fb0765ce4a4ba210cb1c898df276 34 | 工作流文件(直接拖拽到ComfyUI的页面里即可): [workflow.json](workflow.json) 35 | 36 | 37 | ## For More 38 | 39 | ### ComfyUI 40 | 1. 将中文翻译英文:https://github.com/SoftMeng/ComfyUI-FanYi 41 | 2. 从图片提取自然语言:https://github.com/SoftMeng/ComfyUI_ImageToText 42 | 3. 随机生成提示词:https://github.com/SoftMeng/ComfyUI-Prompt 43 | 4. 通过HTML模版制作AI海报:https://github.com/SoftMeng/ComfyUI_Mexx_Poster 44 | 5. 通过图片模版制作AI海报:https://github.com/SoftMeng/ComfyUI_Mexx_Image_Mask 45 | 6. Java工程调用ComfyUI生成AI图片(含全自动图片馆):https://github.com/SoftMeng/comfy-flow-api 46 | ### Stable Diffusion WebUI 47 | 1. 随机生成提示词:https://github.com/SoftMeng/stable-diffusion-prompt-pai 48 | ### Fooocus 49 | 1. 汉化:https://github.com/SoftMeng/Fooocus-zh 50 | ### 其他 51 | 2. 视频会议:https://github.com/SoftMeng/vue-webrtc -------------------------------------------------------------------------------- /workflow.json: -------------------------------------------------------------------------------- 1 | { 2 | "last_node_id": 3, 3 | "last_link_id": 2, 4 | "nodes": [ 5 | { 6 | "id": 2, 7 | "type": "ShowText|pysssss", 8 | "pos": [ 9 | 600, 10 | 130 11 | ], 12 | "size": { 13 | "0": 489.29296875, 14 | "1": 196.09765625 15 | }, 16 | "flags": {}, 17 | "order": 1, 18 | "mode": 0, 19 | "inputs": [ 20 | { 21 | "name": "text", 22 | "type": "STRING", 23 | "link": 2, 24 | "widget": { 25 | "name": "text" 26 | }, 27 | "label": "文本" 28 | } 29 | ], 30 | "outputs": [ 31 | { 32 | "name": "STRING", 33 | "type": "STRING", 34 | "links": null, 35 | "shape": 6, 36 | "label": "字符串" 37 | } 38 | ], 39 | "properties": { 40 | "Node name for S&R": "ShowText|pysssss" 41 | }, 42 | "widgets_values": [ 43 | "", 44 | "Professional photography, RAW photos taken using Fujifilm Provia 400X, HD, HDR, detailed textures, natural skin, vivid colors, an 18-year-old Chinese girl, wearing a hoodie at night, outdoors," 45 | ] 46 | }, 47 | { 48 | "id": 3, 49 | "type": "ComfyUI_FanYi", 50 | "pos": [ 51 | 100, 52 | 130 53 | ], 54 | "size": { 55 | "0": 400, 56 | "1": 200 57 | }, 58 | "flags": {}, 59 | "order": 0, 60 | "mode": 0, 61 | "outputs": [ 62 | { 63 | "name": "text_positive", 64 | "type": "STRING", 65 | "links": [ 66 | 2 67 | ], 68 | "shape": 3, 69 | "label": "text_positive", 70 | "slot_index": 0 71 | } 72 | ], 73 | "properties": { 74 | "Node name for S&R": "ComfyUI_FanYi" 75 | }, 76 | "widgets_values": [ 77 | "专业摄影,使用富士胶片Provia 400X拍摄的RAW照片,HD,HDR,细节纹理,自然皮肤,生动的颜色,18岁的中国女孩,晚上,穿着连帽衫,户外,", 78 | "Yes" 79 | ] 80 | } 81 | ], 82 | "links": [ 83 | [ 84 | 2, 85 | 3, 86 | 0, 87 | 2, 88 | 0, 89 | "STRING" 90 | ] 91 | ], 92 | "groups": [], 93 | "config": {}, 94 | "extra": {}, 95 | "version": 0.4 96 | } -------------------------------------------------------------------------------- /fanyi.py: -------------------------------------------------------------------------------- 1 | import requests 2 | import random 3 | import json 4 | from hashlib import md5 5 | 6 | # Set your own appid/appkey. 7 | appid = 'xxxxx' 8 | appkey = 'xxxxxxx' 9 | 10 | # For list of language codes, please refer to `https://api.fanyi.baidu.com/doc/21` 11 | from_lang = 'zh' 12 | to_lang = 'en' 13 | 14 | map = {} 15 | 16 | endpoint = 'http://api.fanyi.baidu.com' 17 | path = '/api/trans/vip/translate' 18 | url = endpoint + path 19 | 20 | # Generate salt and sign 21 | def make_md5(s, encoding='utf-8'): 22 | return md5(s.encode(encoding)).hexdigest() 23 | 24 | class ComfyUI_FanYi: 25 | def __init__(self): 26 | pass 27 | 28 | @classmethod 29 | def INPUT_TYPES(s): 30 | return { 31 | "required": { 32 | "text_positive": ("STRING", {"default": "专业摄影,使用富士胶片Provia 400X拍摄的RAW照片,HD,HDR,细节纹理,自然皮肤,生动的颜色,18岁的中国女孩,晚上,穿着连帽衫,户外,", "multiline": True}), 33 | "log_prompt": (["No", "Yes"], {"default":"Yes"}), 34 | }, 35 | } 36 | 37 | RETURN_TYPES = ('STRING',) 38 | RETURN_NAMES = ('text_positive',) 39 | FUNCTION = "fanyi" 40 | OUTPUT_NODE = True 41 | CATEGORY = "ComfyUI_Mexx" 42 | 43 | def fanyi(self, text_positive, log_prompt): 44 | if text_positive in map.keys(): 45 | en = map[text_positive] 46 | return [en] 47 | salt = random.randint(32768, 65536) 48 | sign = make_md5(appid + text_positive + str(salt) + appkey) 49 | 50 | # Build request 51 | headers = {'Content-Type': 'application/x-www-form-urlencoded'} 52 | payload = {'appid': appid, 'q': text_positive, 'from': from_lang, 'to': to_lang, 'salt': salt, 'sign': sign} 53 | 54 | # Send request 55 | r = requests.post(url, params=payload, headers=headers) 56 | result = r.json() 57 | 58 | if log_prompt == "Yes": 59 | print(f"中文: {text_positive}") 60 | print(json.dumps(result, indent=4, ensure_ascii=False)) 61 | 62 | en = result["trans_result"][0]["dst"] 63 | if log_prompt == "Yes": 64 | print(f"英文: {en}") 65 | map[text_positive] = en 66 | return [en] 67 | 68 | 69 | NODE_CLASS_MAPPINGS = { 70 | "ComfyUI_FanYi": ComfyUI_FanYi 71 | } 72 | 73 | NODE_DISPLAY_NAME_MAPPINGS = { 74 | "ComfyUI_FanYi": "ComfyUI_FanYi" 75 | } 76 | --------------------------------------------------------------------------------