Spaces:
Build error
Build error
Upload folder using huggingface_hub
Browse filesFiles changed (9)
32 unmodified lines33343532 unmodified lines*.zip filter=lfs diff=lfs merge=lfs -text*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -text32 unmodified lines3334353632 unmodified lines*.zip filter=lfs diff=lfs merge=lfs -text*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -textcache/1709866575_76532584.png filter=lfs diff=lfs merge=lfs -text
123456789101112---title: FaceIDemoji: 😻colorFrom: greencolorTo: graysdk: gradiosdk_version: 4.20.1app_file: app.pypinned: false---Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference123456---title: faceIDapp_file: websockets_api_v1_3_0229_debug_beta.pysdk: gradiosdk_version: 3.41.2---
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134import osimport randomimport websocketimport uuidimport jsonimport urllib.requestimport urllib.parseimport gradio as grfrom glob import globimport requestsfrom pathlib import Pathimport base64from PIL import Imageimport timeimport io
server_address = "127.0.0.1:8188"client_id = str(uuid.uuid4())
def queue_prompt(prompt): p = {"prompt": prompt, "client_id": client_id} data = json.dumps(p).encode('utf-8') req = urllib.request.Request("http://{}/prompt".format(server_address), data=data) return json.loads(urllib.request.urlopen(req).read())
def get_image(filename, subfolder, folder_type): data = {"filename": filename, "subfolder": subfolder, "type": folder_type} url_values = urllib.parse.urlencode(data) with urllib.request.urlopen("http://{}/view?{}".format(server_address, url_values)) as response: return response.read()
def get_history(prompt_id): with urllib.request.urlopen("http://{}/history/{}".format(server_address, prompt_id)) as response: return json.loads(response.read())
def get_images(ws, prompt): prompt_id = queue_prompt(prompt)['prompt_id'] output_images = {} while True: out = ws.recv() if isinstance(out, str): message = json.loads(out) if message['type'] == 'executing': data = message['data'] if data['node'] is None and data['prompt_id'] == prompt_id: break #Execution is done else: continue #previews are binary data
history = get_history(prompt_id)[prompt_id] for o in history['outputs']: for node_id in history['outputs']: node_output = history['outputs'][node_id] if 'images' in node_output: images_output = [] for image in node_output['images']: image_data = get_image(image['filename'], image['subfolder'], image['type']) images_output.append(image_data) output_images[node_id] = images_output
return output_images
def detect(image): img = Path(image).read_bytes() rsp = requests.post(f'http://cv.bytedance.net/aipet_head_det/run/predict', json={ 'data': ['data:image/png;base64,'+ base64.b64encode(img).decode('utf-8'), ] })
return rsp.json()['data'][1]
def clip_save(img_in,coords,path="img.png"):
img = Image.open(img_in) img2 = img.crop((int(coords[0]), int(coords[1]), int(coords[2]), int(coords[3]))) img2.save(path)
def load_template(img_in,seed): seed = int(seed) with open(workflow_base,encoding='utf-8') as file: template = json.load(file) template["14"]["inputs"]["image"] = img_in # template["7"]["inputs"]["text"] = animal + templates[style] template["3"]["inputs"]["seed"] = seed if seed > 0 else random.randint(1,1e8) # template["31"]["inputs"]["seed"] = seed if seed > 0 else random.randint(1,1e8) # template["30"]["inputs"]["lora_name"] = loras[style] # template["30"]["inputs"]["strength_model"] = w_lora # template["30"]["inputs"]["strength_clip"] = w_lora # if debug: # print(template["6"]["inputs"]["image"],template["7"]["inputs"]["text"],template["9"]["inputs"]["seed"],template["30"]["inputs"]["lora_name"],template["30"]["inputs"]["strength_model"],template["30"]["inputs"]["strength_clip"]) return template
def generate(img_in,seed): seed = int(seed)
template = load_template(img_in,seed) ws = websocket.WebSocket() ws.connect("ws://{}/ws?clientId={}".format(server_address, client_id)) images = get_images(ws, template)
for node_id in images: for image_data in images[node_id]: image = Image.open(io.BytesIO(image_data)) path_out = dir_cache+"/"+str(time.time()).split('.')[0]+"_"+str(template["3"]["inputs"]["seed"])+".png" image.save(path_out)
return image
if __name__ == '__main__':
workflow_base = "D:/faceID/workflow_api_anime_0306.json" dir_cache = "D:/faceID/cache" seed = -1 # debug = True demo = gr.Interface(
fn = generate, inputs = [ gr.Image(type='filepath'), # gr.Textbox(label="自定义品种",value="", info="自定义品种,内部调试使用"), # gr.Radio(["发财麻将","东北大花","情人玫瑰","天使丘比特","爱心丘比特","美式证件照","新年工笔画","新年唐装","新年糖葫芦","宠物礼盒","生日快乐","雪地工笔画","破壳纪念","爱读书的学霸","米其林大厨","疯狂赛车手","工笔画","圣诞树","圣诞雪人","圣诞老人",], label="风格", info="更多风格规划中,敬请期待~"), # gr.Slider(0, 1, value=0.5,step=0.05,label='风格化程度',info='推荐值:低风格化0.3, 中风格化0.5, 高风格化0.7'), gr.Textbox(label="随机种子",value=-1, info="-1为随机种子,大于0时为自定义种子") ], outputs = ["image"] )
demo.queue(max_size=2) demo.launch(share=True) 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194{ "3": { "inputs": { "seed": 0, "steps": 20, "cfg": 4, "sampler_name": "dpmpp_2m_sde", "scheduler": "karras", "denoise": 1, "model": [ "10", 0 ], "positive": [ "6", 0 ], "negative": [ "7", 0 ], "latent_image": [ "5", 0 ] }, "class_type": "KSampler", "_meta": { "title": "KSampler" } }, "4": { "inputs": { "ckpt_name": "ghostxl_v10BakedVAE.safetensors" }, "class_type": "CheckpointLoaderSimple", "_meta": { "title": "Load Checkpoint" } }, "5": { "inputs": { "width": 768, "height": 1024, "batch_size": 1 }, "class_type": "EmptyLatentImage", "_meta": { "title": "Empty Latent Image" } }, "6": { "inputs": { "text": "masterpiece, 8K, best quality, clean background", "clip": [ "4", 1 ] }, "class_type": "CLIPTextEncode", "_meta": { "title": "CLIP Text Encode (Prompt)" } }, "7": { "inputs": { "text": "nsfw,blurry, low quality, distorted, photo, frame, naked, horror,embedding:EasyNegative", "clip": [ "4", 1 ] }, "class_type": "CLIPTextEncode", "_meta": { "title": "CLIP Text Encode (Prompt)" } }, "8": { "inputs": { "samples": [ "3", 0 ], "vae": [ "4", 2 ] }, "class_type": "VAEDecode", "_meta": { "title": "VAE Decode" } }, "9": { "inputs": { "filename_prefix": "ComfyUI", "images": [ "8", 0 ] }, "class_type": "SaveImage", "_meta": { "title": "Save Image" } }, "10": { "inputs": { "weight": 1, "noise": 0, "weight_type": "original", "start_at": 0, "end_at": 1, "faceid_v2": true, "weight_v2": 1, "unfold_batch": false, "ipadapter": [ "11", 0 ], "clip_vision": [ "41", 0 ], "insightface": [ "13", 0 ], "image": [ "14", 0 ], "model": [ "39", 0 ] }, "class_type": "IPAdapterApplyFaceID", "_meta": { "title": "Apply IPAdapter FaceID" } }, "11": { "inputs": { "ipadapter_file": "ip-adapter-faceid-plusv2_sdxl.bin" }, "class_type": "IPAdapterModelLoader", "_meta": { "title": "Load IPAdapter Model" } }, "13": { "inputs": { "provider": "CUDA" }, "class_type": "InsightFaceLoader", "_meta": { "title": "Load InsightFace" } }, "14": { "inputs": { "image": "comfyworkflows_f0942efd-fb40-422b-8cd4-cbaa39529fab (3).png", "upload": "image" }, "class_type": "LoadImage", "_meta": { "title": "Load Image" } }, "39": { "inputs": { "lora_name": "ip-adapter-faceid-plusv2_sdxl_lora.safetensors", "strength_model": 1, "model": [ "4", 0 ] }, "class_type": "LoraLoaderModelOnly", "_meta": { "title": "LoraLoaderModelOnly" } }, "41": { "inputs": { "clip_name": "ipadpter1.5.safetensors" }, "class_type": "CLIPVisionLoader", "_meta": { "title": "Load CLIP Vision" } }}.gitattributes+1
README.md+3-9
cache/1709864908_36857950.pngAdded

cache/1709866309_18671109.pngAdded

cache/1709866575_76532584.pngAdded

Large File Pointer Details
- SHA256: 9623b06a2d8bfc35e824b68e6ef8ba65d32bcecb3bdad6ae1523d1e5f29ce400
- Pointer size: 132 Bytes
- Size of remote file: 1.03 MB
cache/1709867129_81267182.pngAdded

cache/1709867218_99613356.pngAdded

websockets_api_v1_3_0229_debug_beta.pyAdded+134
workflow_api_anime_0306.jsonAdded+194