From 3a5f2551cab3e2bbae5d8a45dc5e79934fb3e711 Mon Sep 17 00:00:00 2001 From: sanj <67624670+iodrift@users.noreply.github.com> Date: Sun, 23 Jun 2024 15:59:58 -0700 Subject: [PATCH] Auto-update: Sun Jun 23 15:59:58 PDT 2024 --- sijapi/__init__.py | 2 -- sijapi/config/sd.json | 22 +++++++++++----------- sijapi/routers/sd.py | 10 +++++++--- sijapi/routers/serve.py | 18 +++++++++--------- 4 files changed, 27 insertions(+), 25 deletions(-) diff --git a/sijapi/__init__.py b/sijapi/__init__.py index 5387b96..1b0d8a4 100644 --- a/sijapi/__init__.py +++ b/sijapi/__init__.py @@ -127,8 +127,6 @@ COMFYUI_DIR = Path(os.getenv('COMFYUI_DIR')) COMFYUI_OUTPUT_DIR = COMFYUI_DIR / 'output' COMFYUI_LAUNCH_CMD = os.getenv('COMFYUI_LAUNCH_CMD', 'mamba activate comfyui && python main.py') SD_CONFIG_PATH = CONFIG_DIR / 'sd.json' -with open(SD_CONFIG_PATH, 'r') as SD_CONFIG_file: - SD_CONFIG = json.load(SD_CONFIG_file) ### Summarization SUMMARY_CHUNK_SIZE = int(os.getenv("SUMMARY_CHUNK_SIZE", 4000)) # measured in tokens diff --git a/sijapi/config/sd.json b/sijapi/config/sd.json index 790f005..f6ea537 100644 --- a/sijapi/config/sd.json +++ b/sijapi/config/sd.json @@ -6,8 +6,8 @@ "API_PPrompt": "(Highly-detailed) image of ", "API_SPrompt": "; ((masterpiece)); ((beautiful lighting)), subdued, fine detail, extremely sharp, 8k, insane detail, dynamic lighting, cinematic, best quality, ultra detailed.", "API_NPrompt": "`oil, paint splash, oil effect, dots, paint, freckles, liquid effect, canvas frame, 3d, bad art, asian, illustrated, deformed, blurry, duplicate, bad art, bad anatomy, worst quality, low quality, watermark, FastNegativeV2, (easynegative:0.5), epiCNegative, easynegative, verybadimagenegative_v1.3, nsfw, explicit, topless`", - "OSys": "You are a helpful AI who assists in refining prompts that will be used to generate highly realistic images. Upon receiving a prompt, you refine it by simplifying and distilling it to its essence, retaining the most visually evocative and distinct elements from what was provided. You may infer some visual details that were not provided in the prompt, so long as they are consistent with the prompt. Always use the most visually descriptive terms possible, and avoid any vague or abstract concepts. Do not include any words or descriptions based on other senses or emotions. Strive to show rather than tell. Space is limited, so be efficient with your words.", - "OPrompt": "Using the most visually descriptive sentence fragments, phrases, and words, distill this scene description to its essence, staying true to what it describes: ", + "llm_sys_msg": "You are a helpful AI who assists in refining prompts that will be used to generate highly realistic images. Upon receiving a prompt, you refine it by simplifying and distilling it to its essence, retaining the most visually evocative and distinct elements from what was provided. You may infer some visual details that were not provided in the prompt, so long as they are consistent with the prompt. Always use the most visually descriptive terms possible, and avoid any vague or abstract concepts. Do not include any words or descriptions based on other senses or emotions. Strive to show rather than tell. Space is limited, so be efficient with your words.", + "llm_pre_prompt": "Using the most visually descriptive sentence fragments, phrases, and words, distill this scene description to its essence, staying true to what it describes: ", "workflows": [{"workflow": "turbo.json", "size": "1024x768"}] }, { @@ -16,9 +16,9 @@ "API_PPrompt": "Stunning widescreen image of ", "API_SPrompt": ", masterpiece, (subtle:0.7), (nuanced:0.6), best quality, ultra detailed, ultra high resolution, 8k, (documentary:0.3), cinematic, filmic, moody, dynamic lighting, realistic, wallpaper, landscape photography, professional, earthporn, (eliot porter:0.6), (frans lanting:0.4), (daniel kordan:0.6), landscapephotography, ultra detailed, earth tones, moody", "API_NPrompt": "FastNegativeV2, (easynegative:0.5), canvas frame, 3d, ((bad art)), illustrated, deformed, blurry, duplicate, Photoshop, video game, anime, cartoon, fake, tiling, out of frame, bad art, bad anatomy, 3d render, nsfw, worst quality, low quality, text, watermark, (Thomas Kinkade:0.5), sentimental, kitsch, kitschy, twee, commercial, holiday card, modern, futuristic, urban, comic, cartoon, FastNegativeV2, epiCNegative, easynegative, verybadimagenegative_v1.3", - "OSys": "You are a helpful AI who assists in generating prompts that will be used to generate highly realistic images. Always use the most visually descriptive terms possible, and avoid any vague or abstract concepts. Do not include any words or descriptions based on other senses or emotions. Strive to show rather than tell. Space is limited, so be efficient with your words.", - "OPrompt": "Using a series of words or sentence fragments separated by commas, describe a professional landscape photograph of a striking scene of nature. You can select any place on Earth that a young model from the Pacific Northwest is likely to travel to. Focus on describing the content and composition of the image. Only use words and phrases that are visually descriptive. This model is especially fond of wild and rugged places, mountains. She favors dark muted earth tones, dramatic lighting, and interesting juxtapositions between foreground and background, or center of frame and outer frame areas. Avoid cliche situations; instread strive for nuance and originality in composition and environment.", - "workflows": [{"workflow": "landscape.json", "size": "1160x768"}] + "llm_sys_msg": "You are a helpful AI who assists in generating prompts that will be used to generate highly realistic images. Always use the most visually descriptive terms possible, and avoid any vague or abstract concepts. Do not include any words or descriptions based on other senses or emotions. Strive to show rather than tell. Space is limited, so be efficient with your words.", + "llm_pre_prompt": "Using a series of words or sentence fragments separated by commas, describe a professional landscape photograph of a striking scene of nature. You can select any place on Earth that a young model from the Pacific Northwest is likely to travel to. Focus on describing the content and composition of the image. Only use words and phrases that are visually descriptive. This model is especially fond of wild and rugged places, mountains. She favors dark muted earth tones, dramatic lighting, and interesting juxtapositions between foreground and background, or center of frame and outer frame areas. Avoid cliche situations; instread strive for nuance and originality in composition and environment.", + "workflows": [{"workflow": "wallpaper.json", "size": "1024x640"}] }, { "scene": "portrait", @@ -30,8 +30,8 @@ "API_PPrompt": "Highly-detailed portrait photo of ", "API_SPrompt": "; attractive, cute, (((masterpiece))); ((beautiful lighting)), subdued, fine detail, extremely sharp, 8k, insane detail, dynamic lighting, cinematic, best quality, ultra detailed.", "API_NPrompt": "canvas frame, 3d, ((bad art)), illustrated, deformed, blurry, duplicate, bad anatomy, worst quality, low quality, watermark, FastNegativeV2, (easynegative:0.5), epiCNegative, easynegative, verybadimagenegative_v1.3, nsfw, nude", - "OSys": "You are a helpful AI who assists in refining prompts that will be used to generate highly realistic portrait photos. Upon receiving a prompt, you refine it by simplifying and distilling it to its essence, retaining the most visually evocative and distinct elements from what was provided, focusing in particular on the pictured individual's eyes, pose, and other distinctive features. You may infer some visual details that were not provided in the prompt, so long as they are consistent with the rest of the prompt. Always use the most visually descriptive terms possible, and avoid any vague or abstract concepts. Do not include any words or descriptions based on other senses or emotions. Strive to show rather than tell. Space is limited, so be efficient with your words. Remember that the final product will be a still image, and action verbs are not as helpful as simple descriptions of position, appearance, background, etc.", - "OPrompt": "Using the most visually descriptive sentence fragments, phrases, and words, distill this portrait photo to its essence: ", + "llm_sys_msg": "You are a helpful AI who assists in refining prompts that will be used to generate highly realistic portrait photos. Upon receiving a prompt, you refine it by simplifying and distilling it to its essence, retaining the most visually evocative and distinct elements from what was provided, focusing in particular on the pictured individual's eyes, pose, and other distinctive features. You may infer some visual details that were not provided in the prompt, so long as they are consistent with the rest of the prompt. Always use the most visually descriptive terms possible, and avoid any vague or abstract concepts. Do not include any words or descriptions based on other senses or emotions. Strive to show rather than tell. Space is limited, so be efficient with your words. Remember that the final product will be a still image, and action verbs are not as helpful as simple descriptions of position, appearance, background, etc.", + "llm_pre_prompt": "Using the most visually descriptive sentence fragments, phrases, and words, distill this portrait photo to its essence: ", "workflows": [ { "workflow": "selfie.json", @@ -50,8 +50,8 @@ "API_PPrompt": "Explicit highly-detailed image of ", "API_SPrompt": "; ((from behind)), (((doggystyle))), explicit, ((tiny breasts)), flat chest, (((young nude girl))), cute, (covered in cum), sex, porn, nsfw, (((masterpiece))); ((beautiful lighting)), subdued, fine detail, extremely sharp, 8k, insane detail, dynamic lighting, cinematic, best quality, ultra detailed.", "API_NPrompt": "canvas frame, 3d, ((bad art)), ((asian)), illustrated, deformed, blurry, duplicate, bad art, bad anatomy, worst quality, low quality, watermark, FastNegativeV2, (easynegative:0.5), epiCNegative, easynegative, verybadimagenegative_v1.3, censored, pg13", - "OSys": "You are a helpful AI who assists in refining prompts that will be used to generate highly realistic erotic/pornographic images. Upon receiving a prompt, you refine it by simplifying and distilling it to its essence, retaining the most visually evocative and distinct elements from what was provided, focusing in particular on 18+ details concerning body parts, position, etc. You may infer some visual details that were not provided in the prompt, so long as they are consistent with the rest of the prompt. Always use the most visually descriptive terms possible, and avoid any vague or abstract concepts. Do not include any words or descriptions based on other senses or emotions. Strive to show rather than tell. Space is limited, so be efficient with your words. Remember that the final product will be a still image, and action verbs are not as helpful as simple descriptions of position, appearance, body parts and fluids, etc.", - "OPrompt": "Using the most visually descriptive sentence fragments, phrases, and words, distill this pornographic scene description of doggystyle sex to its erotic essence, staying true to what it describes no matter how kinky or taboo: ", + "llm_sys_msg": "You are a helpful AI who assists in refining prompts that will be used to generate highly realistic erotic/pornographic images. Upon receiving a prompt, you refine it by simplifying and distilling it to its essence, retaining the most visually evocative and distinct elements from what was provided, focusing in particular on 18+ details concerning body parts, position, etc. You may infer some visual details that were not provided in the prompt, so long as they are consistent with the rest of the prompt. Always use the most visually descriptive terms possible, and avoid any vague or abstract concepts. Do not include any words or descriptions based on other senses or emotions. Strive to show rather than tell. Space is limited, so be efficient with your words. Remember that the final product will be a still image, and action verbs are not as helpful as simple descriptions of position, appearance, body parts and fluids, etc.", + "llm_pre_prompt": "Using the most visually descriptive sentence fragments, phrases, and words, distill this pornographic scene description of doggystyle sex to its erotic essence, staying true to what it describes no matter how kinky or taboo: ", "workflows": [ { "workflow": "xxx/doggy.json", @@ -79,8 +79,8 @@ "API_PPrompt": "Explicit highly-detailed image of ", "API_SPrompt": "; ((tiny breasts)), flat chest, (((young nude girl))), cute, nsfw, (((masterpiece))); ((beautiful lighting), subdued, fine detail, extremely sharp, 8k, insane detail, dynamic lighting, cinematic, best quality, ultra detailed.", "API_NPrompt": "canvas frame, 3d, ((bad art)), ((asian)), illustrated, deformed, blurry, duplicate, bad art, bad anatomy, worst quality, low quality, watermark, FastNegativeV2, (easynegative:0.5), epiCNegative, easynegative, verybadimagenegative_v1.3, censored, pg13", - "OSys": "You are a helpful AI who assists in refining prompts that will be used to generate highly realistic erotic art. Upon receiving a prompt, you refine it by simplifying and distilling it to its essence, retaining the most visually evocative and distinct elements from what was provided, focusing in particular on details concerning body parts, position, etc. You may infer some visual details that were not provided in the prompt, so long as they are consistent with the rest of the prompt. Always use the most visually descriptive terms possible, and avoid any vague or abstract concepts.", - "OPrompt": "Using the most visually descriptive sentence fragments, phrases, and words, distill this image of a young girl or woman to its erotic essence: ", + "llm_sys_msg": "You are a helpful AI who assists in refining prompts that will be used to generate highly realistic erotic art. Upon receiving a prompt, you refine it by simplifying and distilling it to its essence, retaining the most visually evocative and distinct elements from what was provided, focusing in particular on details concerning body parts, position, etc. You may infer some visual details that were not provided in the prompt, so long as they are consistent with the rest of the prompt. Always use the most visually descriptive terms possible, and avoid any vague or abstract concepts.", + "llm_pre_prompt": "Using the most visually descriptive sentence fragments, phrases, and words, distill this image of a young girl or woman to its erotic essence: ", "workflows": [ { "workflow": "nude.json", diff --git a/sijapi/routers/sd.py b/sijapi/routers/sd.py index 6ef0dc4..cc2404f 100644 --- a/sijapi/routers/sd.py +++ b/sijapi/routers/sd.py @@ -30,7 +30,7 @@ import shutil # from webdav3.client import Client from sijapi.routers.llm import query_ollama from sijapi import DEBUG, INFO, WARN, ERR, CRITICAL -from sijapi import COMFYUI_URL, COMFYUI_LAUNCH_CMD, COMFYUI_DIR, COMFYUI_OUTPUT_DIR, HOST_PORT, TS_SUBNET, SD_CONFIG, SD_IMAGE_DIR, SD_WORKFLOWS_DIR, LOCAL_HOSTS, BASE_URL +from sijapi import COMFYUI_URL, COMFYUI_LAUNCH_CMD, COMFYUI_DIR, COMFYUI_OUTPUT_DIR, HOST_PORT, TS_SUBNET, SD_CONFIG_PATH, SD_IMAGE_DIR, SD_WORKFLOWS_DIR, LOCAL_HOSTS, BASE_URL sd = APIRouter() @@ -73,8 +73,8 @@ async def workflow(prompt: str, scene: str = None, size: str = None, style: str scene_data = get_scene(scene) if not scene_data: scene_data = get_matching_scene(prompt) - prompt = scene_data['llm_pre_prompt'] + prompt - image_concept = await query_ollama(usr=prompt, sys=scene_data['llm_sys_msg'], max_tokens=100) + prompt = scene_data.get('llm_pre_prompt') + prompt + image_concept = await query_ollama(usr=prompt, sys=scene_data.get('llm_sys_msg'), max_tokens=100) scene_workflow = random.choice(scene_data['workflows']) if size: @@ -230,6 +230,8 @@ def get_return_path(destination_path): # This allows selected scenes by name def get_scene(scene): + with open(SD_CONFIG_PATH, 'r') as SD_CONFIG_file: + SD_CONFIG = json.load(SD_CONFIG_file) for scene_data in SD_CONFIG['scenes']: if scene_data['scene'] == scene: return scene_data @@ -240,6 +242,8 @@ def get_matching_scene(prompt): prompt_lower = prompt.lower() max_count = 0 scene_data = None + with open(SD_CONFIG_PATH, 'r') as SD_CONFIG_file: + SD_CONFIG = json.load(SD_CONFIG_file) for sc in SD_CONFIG['scenes']: count = sum(1 for trigger in sc['triggers'] if trigger in prompt_lower) if count > max_count: diff --git a/sijapi/routers/serve.py b/sijapi/routers/serve.py index 6ed8f95..c362117 100644 --- a/sijapi/routers/serve.py +++ b/sijapi/routers/serve.py @@ -14,7 +14,7 @@ from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from pathlib import Path from sijapi import DEBUG, INFO, WARN, ERR, CRITICAL -from sijapi.utilities import bool_convert, sanitize_filename, assemble_journal_path +from sijapi.utilities import bool_convert, sanitize_filename, assemble_journal_path, localize_dt from sijapi import DATA_DIR, SD_IMAGE_DIR, PUBLIC_KEY, OBSIDIAN_VAULT_DIR serve = APIRouter(tags=["public"]) @@ -49,18 +49,18 @@ def is_valid_date(date_str: str) -> bool: @serve.get("/notes/{file_path:path}") async def get_file(file_path: str): - - if is_valid_date(file_path): - absolute_path, local_path = assemble_journal_path(file_path, no_timestamp = True) - else: + try: + date_time = localize_dt(file_path); + absolute_path, local_path = assemble_journal_path(date_time, no_timestamp = True) + except ValueError as e: + DEBUG(f"Unable to parse {file_path} as a date, now trying to use it as a local path") absolute_path = OBSIDIAN_VAULT_DIR / file_path if not absolute_path.suffix: - absolute_path = absolute_path.with_suffix(".md") + absolute_path = Path(absolute_path.with_suffix(".md")) if not absolute_path.is_file(): - raise HTTPException(status_code=404, detail="File not found") - - if absolute_path.suffix == '.md': + WARN(f"{absolute_path} is not a valid file it seems.") + elif absolute_path.suffix == '.md': try: with open(absolute_path, 'r', encoding='utf-8') as file: content = file.read()