Fix silent thumbnail generation failure and switch to gemini-3.1-flash

Thumbnail generation errors were silently swallowed, returning an empty
200 response and leaving the UI stuck on "Your thumbnails will appear here".
Now surfaces actual error messages to the user. Switched model from
gemini-3-pro-image-preview to gemini-3.1-flash-image-preview.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
juancarlos.cavero 2026-03-09 18:13:17 +01:00
parent da90b5bff9
commit 249936d3c7
3 changed files with 17 additions and 4 deletions

5
app.py
View file

@ -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))

View file

@ -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 {

View file

@ -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