From f77226532efb4b8ac475b2844d302f98927962f8 Mon Sep 17 00:00:00 2001 From: Michele Date: Tue, 7 Apr 2026 17:35:00 +0200 Subject: [PATCH] feat: image generation integrated into content creation flow Backend: - When content_types includes "image", generate image via configured image provider (DALL-E, Replicate) after text generation - Image prompt built from character niche + topic + visual style - Graceful fallback: if image generation fails, post is text-only - Post content_type set to "text+image" when image is attached Frontend: - ContentPage preview shows generated image above text when present - Image displayed with full width and border Co-Authored-By: Claude Opus 4.6 (1M context) --- backend/app/routers/content.py | 25 ++++++++++++++++++++++++- frontend/src/components/ContentPage.jsx | 4 ++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/backend/app/routers/content.py b/backend/app/routers/content.py index 5bc2cb6..072d2d3 100644 --- a/backend/app/routers/content.py +++ b/backend/app/routers/content.py @@ -171,12 +171,35 @@ def generate_content( text, affiliate_link_dicts, character.topics or [] ) + # Generate image if requested + image_url = None + content_types = request.content_types if request.content_types else [request.content_type] + if "image" in content_types: + img_provider_name = _get_setting(db, "image_provider", current_user.id) + img_api_key = _get_setting(db, "image_api_key", current_user.id) + if img_provider_name and img_api_key: + try: + img_provider = get_image_provider(img_provider_name, img_api_key) + visual_style = character.visual_style or {} + style_desc = visual_style.get("description", "") + img_prompt = ( + f"Social media image for a {character.niche} content creator. " + f"Topic: {request.topic_hint or text[:100]}. " + f"Style: {style_desc} professional, clean, engaging.".strip() + ) + image_url = img_provider.generate(img_prompt, size="1024x1024") + except Exception: + pass # Image generation failed, continue with text only + + effective_type = "text+image" if image_url else "text" + post = Post( batch_id=batch_id, character_id=character.id, user_id=current_user.id, - content_type=request.content_type, + content_type=effective_type, text_content=text, + image_url=image_url, hashtags=hashtags, affiliate_links_used=affiliate_links_used, llm_provider=provider_name, diff --git a/frontend/src/components/ContentPage.jsx b/frontend/src/components/ContentPage.jsx index 2099b99..2b68ef9 100644 --- a/frontend/src/components/ContentPage.jsx +++ b/frontend/src/components/ContentPage.jsx @@ -442,6 +442,10 @@ export default function ContentPage() { ) : (
+ {generated.image_url && ( + Immagine generata + )}

{generated.text_content}