v1.2.0: Prefer Gemini 2.x models, improve cover generation and Docker health

Model selection (ai.py):
- get_optimal_model() now scores Gemini 2.5 > 2.0 > 1.5 when ranking candidates
- get_default_models() fallbacks updated to gemini-2.0-pro-exp (logic) and gemini-2.0-flash (writer/artist)
- AI selection prompt rewritten: includes Gemini 2.x pricing context, guidance to avoid 'thinking' models for writer/artist roles, and instructions to prefer 2.x over 1.5
- Added image_model_name and image_model_source globals for UI visibility
- init_models() now reads MODEL_IMAGE_HINT; tries imagen-3.0-generate-001 then imagen-3.0-fast-generate-001 on both Gemini API and Vertex AI paths

Cover generation (marketing.py):
- Fixed display bug: "Attempt X/5" now correctly reads "Attempt X/3"
- Added imagen-3.0-fast-generate-001 as intermediate fallback before legacy Imagen 2
- Quality threshold: images with score < 5 are only kept if nothing better exists
- Smarter prompt refinement on retry: deformity, blur, and watermark critique keywords each append targeted corrections to the art prompt
- Fixed missing sys import (sys.platform check for macOS was silently broken)

Config / Docker:
- config.py: added MODEL_IMAGE_HINT env var, bumped version to 1.2.0
- docker-compose.yml: added MODEL_IMAGE environment variable
- Dockerfile: added libpng-dev and libfreetype6-dev for better font/PNG rendering; added HEALTHCHECK so Portainer detects unhealthy containers

System status UI:
- system_status.html: added Image row showing active Imagen model and provider (Gemini API / Vertex AI)
- Added cache expiry countdown with colour-coded badges

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-20 10:31:02 -05:00
parent 5e0def99c1
commit 2a9a605800
7 changed files with 171 additions and 70 deletions

View File

@@ -56,6 +56,22 @@
</tr>
{% endif %}
{% endfor %}
<tr>
<td class="fw-bold text-uppercase">Image</td>
<td>
{% if image_model %}
<span class="badge bg-success">{{ image_model }}</span>
{% else %}
<span class="badge bg-danger">Unavailable</span>
{% endif %}
</td>
<td>
<span class="badge bg-light text-dark border">{{ image_source or 'None' }}</span>
</td>
<td class="small text-muted">
{% if image_model %}Imagen model used for book cover generation.{% else %}No image generation model could be initialized. Check GCP credentials or Gemini API key.{% endif %}
</td>
</tr>
{% else %}
<tr>
<td colspan="3" class="text-center py-4 text-muted">
@@ -139,15 +155,32 @@
<h5 class="mb-0"><i class="fas fa-clock me-2"></i>Cache Status</h5>
</div>
<div class="card-body">
<p class="mb-0">
<strong>Last Scan:</strong>
<p class="mb-1">
<strong>Last Scan:</strong>
{% if cache and cache.timestamp %}
{{ datetime.fromtimestamp(cache.timestamp).strftime('%Y-%m-%d %H:%M:%S') }}
{{ datetime.fromtimestamp(cache.timestamp).strftime('%Y-%m-%d %H:%M:%S') }} UTC
{% else %}
Never
{% endif %}
</p>
<p class="text-muted small mb-0">Model selection is cached for 24 hours to save API calls.</p>
<p class="mb-0">
<strong>Next Refresh:</strong>
{% if cache and cache.timestamp %}
{% set expires = cache.timestamp + 86400 %}
{% set now_ts = datetime.utcnow().timestamp() %}
{% if expires > now_ts %}
{% set remaining = (expires - now_ts) | int %}
{% set h = remaining // 3600 %}{% set m = (remaining % 3600) // 60 %}
in {{ h }}h {{ m }}m
<span class="badge bg-success ms-1">Cache Valid</span>
{% else %}
<span class="badge bg-warning text-dark">Expired — click Refresh &amp; Optimize</span>
{% endif %}
{% else %}
<span class="badge bg-warning text-dark">No cache — click Refresh &amp; Optimize</span>
{% endif %}
</p>
<p class="text-muted small mt-2 mb-0">Model selection is cached for 24 hours to save API calls.</p>
</div>
</div>
{% endblock %}