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 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} return {"thumbnails": thumbnails}
except HTTPException:
raise
except Exception as e: except Exception as e:
print(f"❌ Thumbnail Generate Error: {e}") print(f"❌ Thumbnail Generate Error: {e}")
raise HTTPException(status_code=500, detail=str(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) { if (!res.ok) {
const err = await res.text(); const errData = await res.json().catch(() => null);
throw new Error(err); throw new Error(errData?.detail || `Server error ${res.status}`);
} }
const data = await res.json(); 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) { } catch (e) {
alert(`Generation failed: ${e.message}`); alert(`Generation failed: ${e.message}`);
} finally { } finally {

View file

@ -236,11 +236,12 @@ DESIGN REQUIREMENTS:
prompt_parts.append(text_prompt) prompt_parts.append(text_prompt)
thumbnails = [] thumbnails = []
last_error = None
for i in range(count): for i in range(count):
print(f"🎨 [Thumbnail] Generating thumbnail {i + 1}/{count}...") print(f"🎨 [Thumbnail] Generating thumbnail {i + 1}/{count}...")
try: try:
response = client.models.generate_content( response = client.models.generate_content(
model="gemini-3-pro-image-preview", model="gemini-3.1-flash-image-preview",
contents=prompt_parts, contents=prompt_parts,
config=types.GenerateContentConfig( config=types.GenerateContentConfig(
response_modalities=["TEXT", "IMAGE"], response_modalities=["TEXT", "IMAGE"],
@ -263,8 +264,12 @@ DESIGN REQUIREMENTS:
break break
except Exception as e: except Exception as e:
last_error = str(e)
print(f"❌ [Thumbnail] Generation {i + 1} failed: {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 return thumbnails