Analyze clusters and generate blog titles, descriptions, and content strategies
Using AI, we analyze clean clusters to evaluate content potential, generate blog titles and descriptions, and identify which topics are worth creating content for.
# Step 5: Blog Topic Generation & Cluster Analysis
@app.post("/keywords/generate-topics")
async def generate_topics(
file: UploadFile = File(...),
min_cluster_size: int = Form(4),
max_workers: int = Form(10),
model_name: str = Form("gpt-4o-mini"),
) -> TopicGenerationResponse:
"""
Generate blog topics and analyze clusters from denoised keywords.
Process:
1. Load denoised CSV from Step 4
2. Filter out noise rows (is_noise == "no")
3. Group by ParentCluster and FinalArticleCluster
4. Send each cluster to GPT for analysis
5. GPT returns:
- Cluster label
- Good for blog (Yes/No)
- Reason
- Needs review flag
- 3 suggested titles
- 3 article descriptions
- Additional noise keywords
6. Remove identified noise keywords
7. Calculate cluster metrics (search volume, keyword count)
8. Remove clusters with < min_cluster_size keywords
9. Sort results (problematic clusters to bottom)
10. Save output and removed keywords
"""
...
# GPT Prompt:
# - Analyzes clusters for SMB invoicing/finance content potential
# - Generates blog titles and descriptions
# - Identifies noise keywords
# - Flags inconsistent clusters for review
# - Returns structured JSON with all fields