diff --git a/app.py b/app.py index 57983bd..dbe73ff 100644 --- a/app.py +++ b/app.py @@ -1234,8 +1234,13 @@ async def thumbnail_generate( video_context ) + if not thumbnails: + raise HTTPException(status_code=500, detail="Thumbnail generation failed. Please check your Gemini API key has access to image generation (gemini-3.1-flash-image-preview model).") + return {"thumbnails": thumbnails} + except HTTPException: + raise except Exception as e: print(f"❌ Thumbnail Generate Error: {e}") raise HTTPException(status_code=500, detail=str(e)) diff --git a/dashboard/src/components/ThumbnailStudio.jsx b/dashboard/src/components/ThumbnailStudio.jsx index 5d99249..5663972 100644 --- a/dashboard/src/components/ThumbnailStudio.jsx +++ b/dashboard/src/components/ThumbnailStudio.jsx @@ -298,12 +298,15 @@ export default function ThumbnailStudio({ geminiApiKey, uploadPostKey, uploadUse }); if (!res.ok) { - const err = await res.text(); - throw new Error(err); + const errData = await res.json().catch(() => null); + throw new Error(errData?.detail || `Server error ${res.status}`); } const data = await res.json(); - setGeneratedThumbnails(data.thumbnails || []); + if (!data.thumbnails || data.thumbnails.length === 0) { + throw new Error('No thumbnails were generated. Your Gemini API key may not have access to image generation.'); + } + setGeneratedThumbnails(data.thumbnails); } catch (e) { alert(`Generation failed: ${e.message}`); } finally { diff --git a/thumbnail.py b/thumbnail.py index f913e5b..e9cd4d5 100644 --- a/thumbnail.py +++ b/thumbnail.py @@ -236,11 +236,12 @@ DESIGN REQUIREMENTS: prompt_parts.append(text_prompt) thumbnails = [] + last_error = None for i in range(count): print(f"🎨 [Thumbnail] Generating thumbnail {i + 1}/{count}...") try: response = client.models.generate_content( - model="gemini-3-pro-image-preview", + model="gemini-3.1-flash-image-preview", contents=prompt_parts, config=types.GenerateContentConfig( response_modalities=["TEXT", "IMAGE"], @@ -263,8 +264,12 @@ DESIGN REQUIREMENTS: break except Exception as e: + last_error = str(e) print(f"❌ [Thumbnail] Generation {i + 1} failed: {e}") + if not thumbnails and last_error: + raise RuntimeError(f"All thumbnail generations failed. Last error: {last_error}") + return thumbnails