Merge pull request #1 from karl0ss/secondtopic

Secondtopic
This commit is contained in:
Karl0ss 2025-10-31 15:32:03 +00:00 committed by GitHub
commit 6a6802472c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 44 additions and 15 deletions

View File

@ -1,5 +1,5 @@
[tool.bumpversion] [tool.bumpversion]
current_version = "0.5.0" current_version = "0.5.3"
parse = "(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)" parse = "(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)"
serialize = ["{major}.{minor}.{patch}"] serialize = ["{major}.{minor}.{patch}"]
replace = "{new_version}" replace = "{new_version}"

View File

@ -4,7 +4,7 @@ FROM python:3.11-slim
# Set the working directory in the container # Set the working directory in the container
WORKDIR /app WORKDIR /app
# Set version label # Set version label
ARG VERSION="0.5.0" ARG VERSION="0.5.3"
LABEL version=$VERSION LABEL version=$VERSION
# Copy project files into the container # Copy project files into the container

View File

@ -79,12 +79,19 @@ The application is configured via the `user_config.cfg` file.
| `[comfyui]` | `width` | The width of the generated image. | `1568` | | `[comfyui]` | `width` | The width of the generated image. | `1568` |
| `[comfyui]` | `height` | The height of the generated image. | `672` | | `[comfyui]` | `height` | The height of the generated image. | `672` |
| `[comfyui]` | `topics` | A comma-separated list of topics to generate prompts from. | | | `[comfyui]` | `topics` | A comma-separated list of topics to generate prompts from. | |
| `[comfyui]` | `FLUX` | Enable FLUX models (`True`/`False`). | `False` | | `[comfyui]` | `secondary_topic` | A secondary topic for prompt generation. | |
| `[comfyui]` | `ONLY_FLUX` | Only use FLUX models (`True`/`False`). | `False` | | `[comfyui]` | `flux` | Enable FLUX models (`True`/`False`). | `False` |
| `[comfyui]` | `qwen` | Enable Qwen models (`True`/`False`). | `False` |
| `[comfyui]` | `only_flux` | Only use FLUX models (`True`/`False`). | `False` |
| `[comfyui:flux]` | `models` | A comma-separated list of FLUX models. | `flux1-dev-Q4_0.gguf,flux1-schnell-Q4_0.gguf` | | `[comfyui:flux]` | `models` | A comma-separated list of FLUX models. | `flux1-dev-Q4_0.gguf,flux1-schnell-Q4_0.gguf` |
| `[comfyui:qwen]` | `models` | A comma-separated list of Qwen models. | `qwen-image-Q4_K_S.gguf, qwen-image-Q2_K.gguf` |
| `[openwebui]` | `base_url` | The base URL for OpenWebUI. | `https://openwebui` | | `[openwebui]` | `base_url` | The base URL for OpenWebUI. | `https://openwebui` |
| `[openwebui]` | `api_key` | The API key for OpenWebUI. | `sk-` | | `[openwebui]` | `api_key` | The API key for OpenWebUI. | `sk-` |
| `[openwebui]` | `models` | A comma-separated list of models for OpenWebUI. | `llama3:latest,cogito:14b,gemma3:12b` | | `[openwebui]` | `models` | A comma-separated list of models for OpenWebUI. | `llama3:latest,cogito:14b,gemma3:12b` |
| `[openrouter]` | `enabled` | Enable OpenRouter integration (`True`/`False`). | `False` |
| `[openrouter]` | `api_key` | The API key for OpenRouter. | |
| `[openrouter]` | `models` | A comma-separated list of models for OpenRouter. | `mistralai/mistral-7b-instruct:free,google/gemma-7b-it:free,meta-llama/llama-3.1-8b-instruct:free` |
| `[openrouter]` | `list_all_free_models` | List all free models (`True`/`False`). | `False` |
## Usage ## Usage

View File

@ -33,31 +33,40 @@ def get_free_models():
def create_prompt_on_openrouter(prompt: str, topic: str = "random", model: str = None) -> str: def create_prompt_on_openrouter(prompt: str, topic: str = "random", model: str = None) -> str:
"""Sends prompt to OpenRouter and returns the generated response.""" """Sends prompt to OpenRouter and returns the generated response."""
# Reload config to get latest values
config = load_config()
# Check if OpenRouter is enabled # Check if OpenRouter is enabled
if user_config["openrouter"].get("enabled", "False").lower() != "true": if config["openrouter"].get("enabled", "False").lower() != "true":
logging.warning("OpenRouter is not enabled in the configuration.") logging.warning("OpenRouter is not enabled in the configuration.")
return "" return ""
topic_instruction = "" topic_instruction = ""
selected_topic = "" selected_topic = ""
secondary_topic_instruction = ""
# Unique list of recent prompts # Unique list of recent prompts
recent_prompts = list(set(load_recent_prompts())) recent_prompts = list(set(load_recent_prompts()))
if topic == "random": if topic == "random":
topics = [t.strip() for t in user_config["comfyui"]["topics"].split(",") if t.strip()] topics = [t.strip() for t in config["comfyui"]["topics"].split(",") if t.strip()]
selected_topic = random.choice(topics) if topics else "" selected_topic = random.choice(topics) if topics else ""
elif topic != "": elif topic != "":
selected_topic = topic selected_topic = topic
else: else:
# Decide on whether to include a topic (e.g., 30% chance to include) # Decide on whether to include a topic (e.g., 30% chance to include)
topics = [t.strip() for t in user_config["comfyui"]["topics"].split(",") if t.strip()] topics = [t.strip() for t in config["comfyui"]["topics"].split(",") if t.strip()]
if random.random() < 0.3 and topics: if random.random() < 0.3 and topics:
selected_topic = random.choice(topics) selected_topic = random.choice(topics)
if selected_topic != "": if selected_topic != "":
topic_instruction = f" Incorporate the theme of '{selected_topic}' into the new prompt." topic_instruction = f" Incorporate the theme of '{selected_topic}' into the new prompt."
# Add secondary topic if configured and not empty
secondary_topic = config["comfyui"].get("secondary_topic", "").strip()
if secondary_topic:
secondary_topic_instruction = f" Additionally incorporate the theme of '{secondary_topic}' into the new prompt, in the style of."
user_content = ( user_content = (
"Can you generate me a really random image idea, Do not exceed 10 words. Use clear language, not poetic metaphors." "Can you generate me a really random image idea, Do not exceed 20 words. Use clear language, not poetic metaphors."
+ topic_instruction + topic_instruction
+ secondary_topic_instruction
+ "Avoid prompts similar to the following:" + "Avoid prompts similar to the following:"
+ "\n".join(f"{i+1}. {p}" for i, p in enumerate(recent_prompts)) + "\n".join(f"{i+1}. {p}" for i, p in enumerate(recent_prompts))
) )

View File

@ -17,26 +17,35 @@ output_folder = user_config["comfyui"]["output_dir"]
def create_prompt_on_openwebui(prompt: str, topic: str = "random", model: str = None) -> str: def create_prompt_on_openwebui(prompt: str, topic: str = "random", model: str = None) -> str:
"""Sends prompt to OpenWebui and returns the generated response.""" """Sends prompt to OpenWebui and returns the generated response."""
# Reload config to get latest values
config = load_config()
topic_instruction = "" topic_instruction = ""
selected_topic = "" selected_topic = ""
secondary_topic_instruction = ""
# Unique list of recent prompts # Unique list of recent prompts
recent_prompts = list(set(load_recent_prompts())) recent_prompts = list(set(load_recent_prompts()))
if topic == "random": if topic == "random":
topics = [t.strip() for t in user_config["comfyui"]["topics"].split(",") if t.strip()] topics = [t.strip() for t in config["comfyui"]["topics"].split(",") if t.strip()]
selected_topic = random.choice(topics) selected_topic = random.choice(topics)
elif topic != "": elif topic != "":
selected_topic = topic selected_topic = topic
else: else:
# Decide on whether to include a topic (e.g., 30% chance to include) # Decide on whether to include a topic (e.g., 30% chance to include)
topics = [t.strip() for t in user_config["comfyui"]["topics"].split(",") if t.strip()] topics = [t.strip() for t in config["comfyui"]["topics"].split(",") if t.strip()]
if random.random() < 0.3 and topics: if random.random() < 0.3 and topics:
selected_topic = random.choice(topics) selected_topic = random.choice(topics)
if selected_topic != "": if selected_topic != "":
topic_instruction = f" Incorporate the theme of '{selected_topic}' into the new prompt." topic_instruction = f" Incorporate the theme of '{selected_topic}' into the new prompt."
# Add secondary topic if configured and not empty
secondary_topic = config["comfyui"].get("secondary_topic", "").strip()
if secondary_topic:
secondary_topic_instruction = f" Additionally incorporate the theme of '{secondary_topic}' into the new prompt, in the style of."
user_content = ( user_content = (
"Can you generate me a really random image idea, Do not exceed 10 words. Use clear language, not poetic metaphors." "Can you generate me a really random image idea, Do not exceed 20 words. Use clear language, not poetic metaphors."
+ topic_instruction + topic_instruction
+ secondary_topic_instruction
+ "Avoid prompts similar to the following:" + "Avoid prompts similar to the following:"
+ "\n".join(f"{i+1}. {p}" for i, p in enumerate(recent_prompts)) + "\n".join(f"{i+1}. {p}" for i, p in enumerate(recent_prompts))
) )

View File

@ -13,11 +13,15 @@ output_dir = ./output/
prompt = "Generate a random detailed prompt for stable diffusion." prompt = "Generate a random detailed prompt for stable diffusion."
width = 1568 width = 1568
height = 672 height = 672
topics = topics =
secondary_topic =
FLUX = False flux = False
ONLY_FLUX = False qwen = False
only_flux = False
[comfyui:qwen]
models = qwen-image-Q4_K_S.gguf, qwen-image-Q2_K.gguf
[comfyui:flux] [comfyui:flux]
models = flux1-dev-Q4_0.gguf,flux1-schnell-Q4_0.gguf models = flux1-dev-Q4_0.gguf,flux1-schnell-Q4_0.gguf