From 2fae18ed9fdbc564d3434df09258fbcdb6851b98 Mon Sep 17 00:00:00 2001 From: PeterTF656 Date: Fri, 16 Aug 2024 01:49:20 +0000 Subject: [PATCH] gitignore huggingface + extra model paths + server.py --- .gitignore | 3 +- extra_model_paths.yaml | 14 ++- folder_paths.py | 4 + .../controlnet/put_controlnets_and_t2i_here | 0 server.py | 105 ++++-------------- 5 files changed, 34 insertions(+), 92 deletions(-) delete mode 100644 models/controlnet/put_controlnets_and_t2i_here diff --git a/.gitignore b/.gitignore index b8ed76113..d5e5474b9 100644 --- a/.gitignore +++ b/.gitignore @@ -18,4 +18,5 @@ venv/ /tests-ui/data/object_info.json /user/ *.log -web_custom_versions/ \ No newline at end of file +/huggingface/ +web_custom_versions/ diff --git a/extra_model_paths.yaml b/extra_model_paths.yaml index 89092fdd4..daffcc0da 100644 --- a/extra_model_paths.yaml +++ b/extra_model_paths.yaml @@ -3,16 +3,18 @@ comfyui: checkpoints: models/checkpoints/ clip: models/clip/ clip_vision: models/clip_vision/ - configs: models/configs/ + configs: models/checkpoints/ controlnet: models/controlnet/ embeddings: models/embeddings/ upscale_models: models/upscale_models/ vae: models/vae/ loras: | - models/lora - models/ip_adapter_faceid/lora - hypernetworks: embeddings + models/lora/ + models/ip_adapter_faceid/lora/ + hypernetworks: embeddings/ ipadapter: | - models/ip_adapter_faceid/models - models/ip_adapter + models/ip_adapter_faceid/models/ + models/ip_adapter/ insightface: models/insightface/ + + diff --git a/folder_paths.py b/folder_paths.py index 71faa2df4..9a121e7c8 100644 --- a/folder_paths.py +++ b/folder_paths.py @@ -134,6 +134,7 @@ def add_model_folder_path(folder_name, full_folder_path): folder_names_and_paths[folder_name] = ([full_folder_path], set()) def get_folder_paths(folder_name): + print(folder_names_and_paths[folder_name][0][:]) return folder_names_and_paths[folder_name][0][:] def recursive_search(directory, excluded_dir_names=None): @@ -191,8 +192,11 @@ def get_full_path(folder_name, filename): def get_filename_list_(folder_name): global folder_names_and_paths + print("global path") + print(folder_names_and_paths) output_list = set() folders = folder_names_and_paths[folder_name] + print(f"folders path :\n {folders}") output_folders = {} for x in folders[0]: files, folders_all = recursive_search(x, excluded_dir_names=[".git"]) diff --git a/models/controlnet/put_controlnets_and_t2i_here b/models/controlnet/put_controlnets_and_t2i_here deleted file mode 100644 index e69de29bb..000000000 diff --git a/server.py b/server.py index 2f39b01a6..7c2b1902c 100644 --- a/server.py +++ b/server.py @@ -2,6 +2,7 @@ import os import sys import asyncio import traceback +# import io import nodes import folder_paths @@ -175,132 +176,66 @@ class PromptServer(): return a.hexdigest() == b.hexdigest() return False - def is_base64_string(s): - try: - if isinstance(s, str): - if s.startswith('data:image'): - return True - return False - except Exception as e: - return False + # def is_base64_string(s): + # try: + # if isinstance(s, str): + # if s.startswith('data:image'): + # return True + # return False + # except Exception as e: + # return False def image_upload(post, image_save_function=None): - print("Starting image upload process") - image = post.get("image") overwrite = post.get("overwrite") image_is_duplicate = False image_upload_type = post.get("type") - print(f"Image upload type: {image_upload_type}") - - # print(f"Received image data: {image}") - upload_dir, image_upload_type = get_dir_by_type(image_upload_type) - print(f"Upload directory: {upload_dir}, Image type: {image_upload_type}, Overwrite: {overwrite}") - if image: - if isinstance(image, web.FileField): - filename = image.filename - file_content = image.file.read() - else: - filename = image.get("filename") - file_content = image.get("file") - if is_base64_string(file_content): - file_content = base64.b64decode(file_content.split(",")[1]) - - print(f"Filename: {filename}") - print(f"File content length: {len(file_content)}") - - if not filename or not file_content: - print("No filename or file content provided") + if image and image.file: + filename = image.filename + if not filename: return web.Response(status=400) subfolder = post.get("subfolder", "") full_output_folder = os.path.join(upload_dir, os.path.normpath(subfolder)) filepath = os.path.abspath(os.path.join(full_output_folder, filename)) - print(f"Full output folder: {full_output_folder}") - print(f"File path: {filepath}") if os.path.commonpath((upload_dir, filepath)) != upload_dir: - print("Security check failed: filepath not within upload directory") return web.Response(status=400) if not os.path.exists(full_output_folder): os.makedirs(full_output_folder) - print(f"Created output folder: {full_output_folder}") split = os.path.splitext(filename) - print(f"File split: {split}") if overwrite is not None and (overwrite == "true" or overwrite == "1"): - print("Overwrite enabled") pass else: i = 1 while os.path.exists(filepath): - print(f"File exists: {filepath}") - if compare_image_hash(filepath, file_content): # compare hash to prevent saving of duplicates with same name - print(f"Duplicate image found: {filepath}") + if compare_image_hash(filepath, image): #compare hash to prevent saving of duplicates with same name, fix for #3465 image_is_duplicate = True break filename = f"{split[0]} ({i}){split[1]}" filepath = os.path.join(full_output_folder, filename) i += 1 - print(f"New filename: {filename}, New filepath: {filepath}") if not image_is_duplicate: - if is_base64_string(file_content): - print("File content is a Base64 string") - # Handle base64 string - image_bytes = base64.b64decode(file_content.split(",")[1]) - if image_save_function is not None: - print(f"Using custom image save function for Base64 content") - image_save_function(image_bytes, post, filepath) - else: - with open(filepath, "wb") as f: - print(f"Saving Base64 decoded image to: {filepath}") - f.write(image_bytes) + if image_save_function is not None: + image_save_function(image, post, filepath) else: - print("File content is a raw file-like object") - # Handle raw file-like object - if image_save_function is not None: - print(f"Using custom image save function for raw file") - image_save_function(file_content, post, filepath) - else: - with open(filepath, "wb") as f: - print(f"Saving raw file to: {filepath}") - f.write(file_content) - return web.json_response({"name": filename, "subfolder": subfolder, "type": image_upload_type}) + with open(filepath, "wb") as f: + f.write(image.file.read()) + + return web.json_response({"name" : filename, "subfolder": subfolder, "type": image_upload_type}) else: - print("No image provided in the post data") return web.Response(status=400) @routes.post("/upload/image") async def upload_image(request): - content_type = request.headers.get('Content-Type') - print(f"Content-Type: {content_type}") - - post = {} - if 'application/json' in content_type: - try: - post = await request.json() - print(f"Received JSON post data: {post}") - except Exception as e: - print(f"Error parsing JSON: {e}") - return web.Response(status=400, text="Invalid JSON data") - elif 'multipart/form-data' in content_type: - try: - post = await request.post() - print(f"Received form-data post data: {post}") - post = {key: post[key] for key in post.keys()} - except Exception as e: - print(f"Error parsing form-data: {e}") - return web.Response(status=400, text="Invalid form-data") - else: - print("Unsupported Content-Type") - return web.Response(status=400, text="Unsupported Content-Type") - + post = await request.post() return image_upload(post)