Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
if-ai authored Nov 17, 2024
1 parent f373f60 commit 5ab5975
Show file tree
Hide file tree
Showing 12 changed files with 429 additions and 267 deletions.
4 changes: 3 additions & 1 deletion IFChatPromptNode.py
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,9 @@ async def process_chat(
else:
image_tensor, default_mask_tensor = process_images_for_comfy(
retrieved_image,
self.placeholder_image_path
self.placeholder_image_path,
response_key=None,
field_name=None
)
mask_tensor = default_mask_tensor

Expand Down
2 changes: 1 addition & 1 deletion IFDisplayTextWildcardNode.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(self):
self.wildcard_lock = threading.Lock()

# Initialize paths
self.base_path = folder_paths.base_path
#self.base_path = folder_paths.base_path
self.presets_dir = os.path.join(folder_paths.base_path, "custom_nodes", "ComfyUI-IF_AI_tools", "IF_AI", "presets")
self.wildcards_dir = os.path.join(self.presets_dir, "wildcards")

Expand Down
314 changes: 219 additions & 95 deletions IFImagePromptNode.py

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions IFStepCounterNode.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# IFStepCounterNode.py
class IFCounter:
def __init__(self):
self.counters = {}
Expand Down
2 changes: 1 addition & 1 deletion IF_AI/presets/neg_prompts.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"None": "",
"AI_Fill": "lowres, lowquality, bad,",
"SD3x_q1": "deformed and malformed with worst qualities. distortions and artifacts, low quality, bad ratings ☆☆☆☆☆, 0/10 review, 0/5 review ↓",
"SD3x_q1": "deformed and malformed with worst qualities. distortions and artifacts, low quality, bad ratings, 0/10 review, 0/5 review ↓",
"AtomeaseNoWaifus": "(3D, Adorable, Anime, CGI, Cartoon, Cartoonish, Childish, Computer Generated, Manga, Rendered)",
"BadChill": "ng_deepnegative_v1_75t, bad-picture-chill-75v, bad_prompt, bad anatomy",
"BadChill2": "bad-picture-chill-75v, ng_deepnegative_v1_75t, easynegative, verybadimagenegative_v1.3, negative_hand-neg",
Expand Down
10 changes: 5 additions & 5 deletions IF_AI/rag/settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ base_ip: localhost
port: '11434'
llm_provider: openai
llm_model: gpt-4o-mini
temperature: 1.2000000000000002
max_tokens: 2048
temperature: 0.0
max_tokens: 2061
stop: null
keep_alive: false
top_k: 40
top_p: 0.9
repeat_penalty: 1.2
seed: 558413258089916
rag_folder_name: safiro1
query_type: local
seed: 197464410746652
rag_folder_name: Safiro2
query_type: global
community_level: 2
preset: Default
external_llm_api_key: ''
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@

ComfyUI-IF_AI_tools is a set of custom nodes to Run Local and API LLMs and LMMs, Features OCR-RAG (Bialdy), nanoGraphRAG, Supervision Object Detection, supports Ollama, LlamaCPP LMstudio, Koboldcpp, TextGen, Transformers or via APIs Anthropic, Groq, OpenAI, Google Gemini, Mistral, xAI and create your own charcters assistants (SystemPrompts) with custom presets and muchmore

################# ATENTION ####################

*COPY THE IF_AI FOLDER TO YOUR USER FOLDER*

###############################################
# Prerequisite Installation (Poppler)

To ensure compatibility and functionality with all tools, you may need `poppler` for PDF-related operations. Use `scoop` to install `poppler` on Windows:
Expand Down
3 changes: 1 addition & 2 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
current_dir = os.path.dirname(os.path.abspath(__file__))
if current_dir not in sys.path:
sys.path.insert(0, current_dir)
#print(f"Current directory: {current_dir}")
#print(f"Files in current directory: {os.listdir(current_dir)}")

try:
from .omost import omost_function
print("Successfully imported omost_function from omost.py in the current directory")
Expand Down
21 changes: 18 additions & 3 deletions openai_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,25 @@ async def generate_image(

async with aiohttp.ClientSession() as session:
async with session.post(api_url, headers=headers, json=payload) as response:
response.raise_for_status()
if response.status != 200:
error_text = await response.text()
logger.error(f"OpenAI generate_image error {response.status}: {error_text}")
response.raise_for_status()
data = await response.json()
images = [item["b64_json"] for item in data.get("data", [])]
return images

# Handle different response structures
if "data" in data and isinstance(data["data"], list):
images = []
for item in data["data"]:
if "b64_json" in item:
images.append(item["b64_json"])
elif "url" in item:
# If response_format was changed or API returned URLs
images.append(item["url"])
return images
else:
logger.error("Unexpected response format in generate_image")
raise ValueError("Unexpected response format")

async def edit_image(
image_base64: str,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[project]
name = "comfyui-if_ai_tools"
description = "Run Local and API LLMs, Features OCR-RAG (Bialdy), nanoGraphRAG, Supervision Object Detection, Conditioning manipulation via Omost, supports Ollama, LlamaCPP LMstudio, Koboldcpp, TextGen, Transformers or via APIs Anthropic, Groq, OpenAI, Google Gemini, Mistral, xAI and create your own charcters assistants (SystemPrompts) with custom presets and muchmore"
version = "1.0.7"
version = "1.0.6"
license = { file = "LICENSE.txt" }
dependencies = ["anthropic",
"groq",
Expand Down
91 changes: 55 additions & 36 deletions send_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from .vllm_api import send_vllm_request
from .gemini_api import send_gemini_request
from .transformers_api import TransformersModelManager # Import the manager
from .utils import format_images_for_provider, convert_images_for_api, format_response
from .utils import convert_images_for_api, format_response
# Set up logging
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -101,8 +101,6 @@ async def send_request(
Union[str, Dict[str, Any]]: Unified response format.
"""
try:
#formatted_images = format_images_for_provider(images, llm_provider) if images is not None else None
#formatted_mask = format_images_for_provider(mask, llm_provider) if mask is not None else None
# Define aspect ratio to size mapping
aspect_ratio_mapping = {
"1:1": "1024x1024",
Expand Down Expand Up @@ -141,7 +139,7 @@ async def send_request(
else:
# For other providers, convert to base64 only if images exist
formatted_images = convert_images_for_api(images, target_format='base64') if images is not None and len(images) > 0 else None
formatted_mask = convert_images_for_api(mask, target_format='base64') if mask is not None and len(mask) > 0 else None
#formatted_masks = convert_images_for_api(mask, target_format='base64') if mask is not None and len(mask) > 0 else None

api_functions = {
"groq": send_groq_request,
Expand Down Expand Up @@ -233,39 +231,60 @@ async def send_request(
}
elif llm_provider == "openai":
if llm_model.startswith("dall-e"):
if strategy == "create":
# Generate image
generated_images = await generate_image(
prompt=user_message,
model=llm_model,
n=batch_count,
size=size,
api_key=llm_api_key
)
return {"images": generated_images}
elif strategy == "edit":
try:
# Handle image formatting for edit/variations
formatted_image = None
formatted_mask = None

if images is not None and (strategy == "edit" or strategy == "variations"):
# Convert to base64 and take first image only
formatted_images = convert_images_for_api(images[0:1], target_format='base64')
if formatted_images:
formatted_image = formatted_images[0]

# Edit image
edited_images = await edit_image(
image_base64=formatted_images[0],
mask_base64=formatted_mask,
prompt=user_message,
model=llm_model,
n=batch_count,
size=size,
api_key=llm_api_key
)
return {"images": edited_images}
elif strategy == "variations":
# Generate variations
variations_images = await generate_image_variations(
image_base64=formatted_images[0],
model=llm_model,
n=batch_count,
size=size,
api_key=llm_api_key
)
return {"images": variations_images}
# Handle mask for edit strategy
if strategy == "edit" and mask is not None:
formatted_masks = convert_images_for_api(mask[0:1], target_format='base64')
if formatted_masks:
formatted_mask = formatted_masks[0]

# Make appropriate API call based on strategy
if strategy == "create":
response = await generate_image(
prompt=user_message,
model=llm_model,
n=batch_count,
size=size,
api_key=llm_api_key
)
elif strategy == "edit":
response = await edit_image(
image_base64=formatted_image,
mask_base64=formatted_mask,
prompt=user_message,
model=llm_model,
n=batch_count,
size=size,
api_key=llm_api_key
)
elif strategy == "variations":
response = await generate_image_variations(
image_base64=formatted_image,
model=llm_model,
n=batch_count,
size=size,
api_key=llm_api_key
)
else:
raise ValueError(f"Invalid strategy: {strategy}")

# Return the response directly - it will be a list of base64 strings
return {"images": response}

except Exception as e:
error_msg = f"Error in DALL·E {strategy}: {str(e)}"
logger.error(error_msg)
return {"error": error_msg}
else:
api_url = f"https://api.openai.com/v1/chat/completions"
kwargs = {
Expand Down
Loading

0 comments on commit 5ab5975

Please sign in to comment.