mirror of
https://github.com/karl0ss/ai_image_frame_server.git
synced 2025-11-13 05:19:42 +00:00
Compare commits
No commits in common. "main" and "0.4.0" have entirely different histories.
@ -1,5 +1,5 @@
|
|||||||
[tool.bumpversion]
|
[tool.bumpversion]
|
||||||
current_version = "0.5.6"
|
current_version = "0.4.0"
|
||||||
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}"
|
||||||
|
|||||||
@ -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.6"
|
ARG VERSION="0.4.0"
|
||||||
LABEL version=$VERSION
|
LABEL version=$VERSION
|
||||||
|
|
||||||
# Copy project files into the container
|
# Copy project files into the container
|
||||||
|
|||||||
43
README.md
43
README.md
@ -4,19 +4,12 @@ This project is a Flask-based web server designed to generate and display images
|
|||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
* **Web Interface:** A simple web interface to view generated images, manage favourites, and monitor job queues.
|
* **Web Interface:** A simple web interface to view generated images.
|
||||||
* **Image Generation:** Integrates with ComfyUI to generate images using SDXL, FLUX, and Qwen models based on given prompts.
|
* **Image Generation:** Integrates with ComfyUI to generate images based on given prompts and models.
|
||||||
* **Prompt Generation:** Automatic prompt generation using OpenWebUI or OpenRouter APIs with topic-based theming.
|
|
||||||
* **Scheduled Generation:** Automatically generates new images at a configurable time.
|
* **Scheduled Generation:** Automatically generates new images at a configurable time.
|
||||||
* **Favourites System:** Mark and manage favourite images.
|
|
||||||
* **Job Queue Management:** View and cancel running/pending image generation jobs.
|
|
||||||
* **Thumbnail Generation:** Automatic thumbnail creation for generated images.
|
|
||||||
* **Prompt Logging:** Maintains a log of recent prompts to avoid repetition.
|
|
||||||
* **Settings Management:** Web-based configuration editor for all settings.
|
|
||||||
* **Docker Support:** Comes with a `Dockerfile` and `docker-compose.yml` for easy setup and deployment.
|
* **Docker Support:** Comes with a `Dockerfile` and `docker-compose.yml` for easy setup and deployment.
|
||||||
* **Configurable:** Most options can be configured through a `user_config.cfg` file or web interface.
|
* **Configurable:** Most options can be configured through a `user_config.cfg` file.
|
||||||
* **Authentication:** Optional password protection for image creation.
|
* **Authentication:** Optional password protection for image creation.
|
||||||
* **Version Management:** Uses bump-my-version for version tracking.
|
|
||||||
|
|
||||||
## Prerequisites
|
## Prerequisites
|
||||||
|
|
||||||
@ -40,8 +33,8 @@ This project is a Flask-based web server designed to generate and display images
|
|||||||
```
|
```
|
||||||
|
|
||||||
3. **Configure the application:**
|
3. **Configure the application:**
|
||||||
* The `user_config.cfg` file will be automatically created from `user_config.cfg.sample` on first run if it doesn't exist.
|
* Copy the `user_config.cfg.sample` to `user_config.cfg`.
|
||||||
* Edit `user_config.cfg` with your settings, or use the web-based settings page accessible by clicking the version number in the bottom right corner of the home page. See the [Configuration](#configuration) section for more details.
|
* Edit `user_config.cfg` with your settings. See the [Configuration](#configuration) section for more details.
|
||||||
|
|
||||||
4. **Run the application:**
|
4. **Run the application:**
|
||||||
```bash
|
```bash
|
||||||
@ -58,8 +51,8 @@ This project is a Flask-based web server designed to generate and display images
|
|||||||
```
|
```
|
||||||
|
|
||||||
2. **Configure the application:**
|
2. **Configure the application:**
|
||||||
* The `user_config.cfg` file will be automatically created from `user_config.cfg.sample` on first run if it doesn't exist.
|
* Copy the `user_config.cfg.sample` to `user_config.cfg`.
|
||||||
* Edit `user_config.cfg` with your settings, or use the web-based settings page accessible by clicking the version number in the bottom right corner of any page. The `comfyui_url` should be the address of your ComfyUI instance, accessible from within the Docker network (e.g., `http://host.docker.internal:8188` or your server's IP).
|
* Edit `user_config.cfg` with your settings. The `comfyui_url` should be the address of your ComfyUI instance, accessible from within the Docker network (e.g., `http://host.docker.internal:8188` or your server's IP).
|
||||||
|
|
||||||
3. **Build and run with Docker Compose:**
|
3. **Build and run with Docker Compose:**
|
||||||
```bash
|
```bash
|
||||||
@ -86,27 +79,17 @@ 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]` | `secondary_topic` | A secondary topic for prompt generation. | |
|
| `[comfyui]` | `FLUX` | Enable FLUX models (`True`/`False`). | `False` |
|
||||||
| `[comfyui]` | `flux` | Enable FLUX models (`True`/`False`). | `False` |
|
| `[comfyui]` | `ONLY_FLUX` | Only use FLUX models (`True`/`False`). | `False` |
|
||||||
| `[comfyui]` | `qwen` | Enable Qwen 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
|
||||||
|
|
||||||
* **Gallery:** Open your browser to `http://<server_ip>:<port>` to see the gallery of generated images.
|
* **Gallery:** Open your browser to `http://<server_ip>:<port>` to see the gallery of generated images.
|
||||||
* **Create Image:** Navigate to `/create` or `/create_image` to manually trigger image generation with various model options.
|
* **Create Image:** Navigate to `/create` to manually trigger image generation.
|
||||||
* **Job Queue:** Monitor and cancel running/pending jobs via the gallery interface.
|
|
||||||
* **API Endpoints:**
|
|
||||||
* `/api/queue` - Get current job queue details (JSON)
|
|
||||||
* `/cancel` - Cancel the current running job
|
|
||||||
|
|
||||||
## Dependencies
|
## Dependencies
|
||||||
|
|
||||||
@ -114,12 +97,6 @@ The application is configured via the `user_config.cfg` file.
|
|||||||
* comfy_api_simplified
|
* comfy_api_simplified
|
||||||
* APScheduler
|
* APScheduler
|
||||||
* Pillow
|
* Pillow
|
||||||
* tenacity
|
|
||||||
* nest_asyncio
|
|
||||||
* openai
|
|
||||||
* websockets
|
|
||||||
* bump-my-version
|
|
||||||
* openwebui-chat-client
|
|
||||||
* And others, see `requirements.txt`.
|
* And others, see `requirements.txt`.
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|||||||
@ -5,7 +5,6 @@ import sys
|
|||||||
import time
|
import time
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
import shutil
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
import nest_asyncio
|
import nest_asyncio
|
||||||
import json
|
import json
|
||||||
@ -39,21 +38,10 @@ def save_prompt(prompt):
|
|||||||
|
|
||||||
|
|
||||||
def load_config() -> configparser.ConfigParser:
|
def load_config() -> configparser.ConfigParser:
|
||||||
"""Loads user configuration from ./user_config.cfg. If it doesn't exist, copies from user_config.cfg.sample."""
|
"""Loads user configuration from ./user_config.cfg."""
|
||||||
user_config = configparser.ConfigParser()
|
user_config = configparser.ConfigParser()
|
||||||
config_path = "./user_config.cfg"
|
|
||||||
sample_path = "./user_config.cfg.sample"
|
|
||||||
|
|
||||||
if not os.path.exists(config_path):
|
|
||||||
if os.path.exists(sample_path):
|
|
||||||
shutil.copy(sample_path, config_path)
|
|
||||||
logging.info("Configuration file copied from sample.")
|
|
||||||
else:
|
|
||||||
logging.error("Neither user_config.cfg nor user_config.cfg.sample found.")
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
user_config.read(config_path)
|
user_config.read("./user_config.cfg")
|
||||||
logging.debug("Configuration loaded successfully.")
|
logging.debug("Configuration loaded successfully.")
|
||||||
return user_config
|
return user_config
|
||||||
except KeyError as e:
|
except KeyError as e:
|
||||||
@ -199,45 +187,6 @@ def load_prompt_models_from_config():
|
|||||||
return prompt_models
|
return prompt_models
|
||||||
|
|
||||||
|
|
||||||
def build_user_content(topic: str = "random") -> str:
|
|
||||||
"""Build the user content string for prompt generation, including topic instructions and recent prompts avoidance."""
|
|
||||||
config = load_config()
|
|
||||||
topic_instruction = ""
|
|
||||||
selected_topic = ""
|
|
||||||
secondary_topic_instruction = ""
|
|
||||||
# Unique list of recent prompts
|
|
||||||
recent_prompts = list(set(load_recent_prompts()))
|
|
||||||
|
|
||||||
if topic == "random":
|
|
||||||
topics = [t.strip() for t in config["comfyui"]["topics"].split(",") if t.strip()]
|
|
||||||
selected_topic = random.choice(topics) if topics else ""
|
|
||||||
elif topic != "":
|
|
||||||
selected_topic = topic
|
|
||||||
else:
|
|
||||||
# Decide on whether to include a topic (e.g., 30% chance to include)
|
|
||||||
topics = [t.strip() for t in config["comfyui"]["topics"].split(",") if t.strip()]
|
|
||||||
if random.random() < 0.3 and topics:
|
|
||||||
selected_topic = random.choice(topics)
|
|
||||||
|
|
||||||
if selected_topic != "":
|
|
||||||
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."
|
|
||||||
|
|
||||||
user_content = (
|
|
||||||
"Can you generate me a really random image idea, Do not exceed 20 words. Use clear language, not poetic metaphors."
|
|
||||||
+ topic_instruction
|
|
||||||
+ secondary_topic_instruction
|
|
||||||
+ "Avoid prompts similar to the following:"
|
|
||||||
+ "\n".join(f"{i+1}. {p}" for i, p in enumerate(recent_prompts))
|
|
||||||
)
|
|
||||||
|
|
||||||
return user_content
|
|
||||||
|
|
||||||
|
|
||||||
def create_prompt_with_random_model(base_prompt: str, topic: str = "random"):
|
def create_prompt_with_random_model(base_prompt: str, topic: str = "random"):
|
||||||
"""Create a prompt using a randomly selected model from OpenWebUI or OpenRouter.
|
"""Create a prompt using a randomly selected model from OpenWebUI or OpenRouter.
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import random
|
|||||||
import logging
|
import logging
|
||||||
from openai import OpenAI, RateLimitError
|
from openai import OpenAI, RateLimitError
|
||||||
import nest_asyncio
|
import nest_asyncio
|
||||||
from libs.generic import load_recent_prompts, load_config, build_user_content
|
from libs.generic import load_recent_prompts, load_config
|
||||||
from libs.openwebui import create_prompt_on_openwebui
|
from libs.openwebui import create_prompt_on_openwebui
|
||||||
import re
|
import re
|
||||||
nest_asyncio.apply()
|
nest_asyncio.apply()
|
||||||
@ -33,14 +33,34 @@ 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 config["openrouter"].get("enabled", "False").lower() != "true":
|
if user_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 ""
|
||||||
|
|
||||||
user_content = build_user_content(topic)
|
topic_instruction = ""
|
||||||
|
selected_topic = ""
|
||||||
|
# Unique list of recent prompts
|
||||||
|
recent_prompts = list(set(load_recent_prompts()))
|
||||||
|
if topic == "random":
|
||||||
|
topics = [t.strip() for t in user_config["comfyui"]["topics"].split(",") if t.strip()]
|
||||||
|
selected_topic = random.choice(topics) if topics else ""
|
||||||
|
elif topic != "":
|
||||||
|
selected_topic = topic
|
||||||
|
else:
|
||||||
|
# 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()]
|
||||||
|
if random.random() < 0.3 and topics:
|
||||||
|
selected_topic = random.choice(topics)
|
||||||
|
if selected_topic != "":
|
||||||
|
topic_instruction = f" Incorporate the theme of '{selected_topic}' into the new prompt."
|
||||||
|
|
||||||
|
user_content = (
|
||||||
|
"Can you generate me a really random image idea, Do not exceed 10 words. Use clear language, not poetic metaphors."
|
||||||
|
+ topic_instruction
|
||||||
|
+ "Avoid prompts similar to the following:"
|
||||||
|
+ "\n".join(f"{i+1}. {p}" for i, p in enumerate(recent_prompts))
|
||||||
|
)
|
||||||
|
|
||||||
# Load configured models
|
# Load configured models
|
||||||
configured_models = [m.strip() for m in user_config["openrouter"]["models"].split(",") if m.strip()]
|
configured_models = [m.strip() for m in user_config["openrouter"]["models"].split(",") if m.strip()]
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import random
|
import random
|
||||||
import logging
|
import logging
|
||||||
import nest_asyncio
|
import nest_asyncio
|
||||||
from libs.generic import load_recent_prompts, load_config, build_user_content
|
from libs.generic import load_recent_prompts, load_config
|
||||||
import re
|
import re
|
||||||
from openwebui_chat_client import OpenWebUIClient
|
from openwebui_chat_client import OpenWebUIClient
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
@ -17,9 +17,29 @@ 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
|
topic_instruction = ""
|
||||||
config = load_config()
|
selected_topic = ""
|
||||||
user_content = build_user_content(topic)
|
# Unique list of recent prompts
|
||||||
|
recent_prompts = list(set(load_recent_prompts()))
|
||||||
|
if topic == "random":
|
||||||
|
topics = [t.strip() for t in user_config["comfyui"]["topics"].split(",") if t.strip()]
|
||||||
|
selected_topic = random.choice(topics)
|
||||||
|
elif topic != "":
|
||||||
|
selected_topic = topic
|
||||||
|
else:
|
||||||
|
# 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()]
|
||||||
|
if random.random() < 0.3 and topics:
|
||||||
|
selected_topic = random.choice(topics)
|
||||||
|
if selected_topic != "":
|
||||||
|
topic_instruction = f" Incorporate the theme of '{selected_topic}' into the new prompt."
|
||||||
|
|
||||||
|
user_content = (
|
||||||
|
"Can you generate me a really random image idea, Do not exceed 10 words. Use clear language, not poetic metaphors."
|
||||||
|
+ topic_instruction
|
||||||
|
+ "Avoid prompts similar to the following:"
|
||||||
|
+ "\n".join(f"{i+1}. {p}" for i, p in enumerate(recent_prompts))
|
||||||
|
)
|
||||||
|
|
||||||
if model:
|
if model:
|
||||||
# Use the specified model
|
# Use the specified model
|
||||||
|
|||||||
@ -14,14 +14,10 @@ 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
|
||||||
qwen = False
|
ONLY_FLUX = 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
|
||||||
|
|
||||||
|
|||||||
@ -167,7 +167,7 @@
|
|||||||
"38": {
|
"38": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"unet_name": "flux1-dev-Q4_0.gguf",
|
"unet_name": "flux1-dev-Q4_0.gguf",
|
||||||
"device": "cuda:0",
|
"device": "cuda:1",
|
||||||
"virtual_vram_gb": 0,
|
"virtual_vram_gb": 0,
|
||||||
"use_other_vram": true,
|
"use_other_vram": true,
|
||||||
"expert_mode_allocations": ""
|
"expert_mode_allocations": ""
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user