fakeboyinthehouse100/leetcode-solution-post-genai-backend
๐ LeetCode Solution Post Generator
AI-Powered Markdown Blog Post Generator for LeetCode Solutions
  
๐ Overview
LeetCode Solution Post GenAI is an intelligent backend service that transforms your raw LeetCode solutions into beautifully formatted, comprehensive markdown blog posts. Powered by StarCoder2-7B, this API automatically generates detailed explanations, complexity analysis, and step-by-step walkthroughs for your coding solutions.
What it does:
- ๐ Transforms raw code into professional blog posts
- ๐ Generates detailed explanations and intuition
- ๐งฎ Analyzes time and space complexity
- ๐ Creates step-by-step algorithm walkthroughs
- ๐จ Formats everything in clean, readable markdown
๐ฏ Perfect For
- ๐ฑ Frontend developers building LeetCode blog platforms
- ๐จโ๐ป Competitive programmers sharing solutions
- ๐ Technical bloggers creating educational content
- ๐ Students documenting their learning journey
- ๐ข Companies building coding interview platforms
๐ API Endpoints
Health Check
GET /health
Check if the service is running and the AI model is loaded.
curl https://your-space-name.hf.space/healthResponse:
{
"status": "healthy",
"message": "Server is running",
"model_loaded": true,
"prompt_loaded": true
}Generate Content
POST /generate
Transform your LeetCode solution into a professional blog post.
curl -X POST https://your-space-name.hf.space/generate \
-H "Content-Type: application/json" \
-d '{
"problem_id": "1",
"solution": "function twoSum(nums, target) { return []; }"
}'Request Body:
Response:
{
"markdown": "Generated markdown content..."
}๐ ๏ธ Tech Stack
- Python 3.9 - Core runtime
- FastAPI - Modern web framework
- Transformers - HuggingFace model integration
- PyTorch - Deep learning backend
- StarCoder2-7B - Code generation AI model
- Docker - Containerization
- HuggingFace Spaces - Cloud hosting
๐จ Generated Content Features
The AI generates comprehensive blog posts with:
- ๐ฏ Catchy titles with emojis and technique tags
- ๐ก Intuition section explaining the problem approach
- ๐ Detailed approach with step-by-step breakdowns
- ๐ Code walkthroughs with concrete examples
- ๐ Complexity analysis (time & space)
- โ Clean formatting ready for publishing
Example Output Preview
### Easy Hash Map | Two Sum Magic ๐ฏ | TS Solution | LeetCode - 1
# Intuition
We need to find two numbers in an array that sum to a target value.
# Approach
Goal: Find indices of two numbers that sum to target
Strategy: One-pass hash map lookup
# Complexity
- Time complexity: O(n)
- Space complexity: O(n)๐ฑ Frontend Integration
JavaScript Example
const generateBlogPost = async (problemId, solution) => {
const response = await fetch('https://your-space-name.hf.space/generate', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
problem_id: problemId,
solution: solution,
}),
});
const data = await response.json();
return data.markdown;
};React Example
const [markdown, setMarkdown] = useState('');
const handleGenerate = async () => {
try {
const response = await fetch('/api/generate', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ problem_id, solution }),
});
const data = await response.json();
setMarkdown(data.markdown);
} catch (error) {
console.error('Generation failed:', error);
}
};๐งช Testing with Postman
1. Health Check
- Method: GET
- URL:
https://your-space-name.hf.space/health
2. Generate Content
- Method: POST
- URL:
https://your-space-name.hf.space/generate - Headers:
Content-Type: application/json - Body:
{
"problem_id": "1",
"solution": "function twoSum(nums, target) { return []; }"
}โก Performance & Limits
Response Times
- First request: 10-30 seconds (model loading)
- Subsequent requests: 3-8 seconds
- Concurrent requests: Supported with queuing
Resource Usage
- Model size: ~7B parameters
- Memory usage: ~14GB VRAM (recommended)
- CPU fallback: Available but slower
Input Limits
- Solution code: Up to 2000 characters
- Problem ID: Any valid string
- Output: ~1000-2000 characters markdown
๐ง Local Development
Prerequisites
pip install fastapi uvicorn transformers torch accelerateRun Locally
git clone https://huggingface.co/spaces/YOUR_USERNAME/leetcode-solution-post-genai
cd leetcode-solution-post-genai
python app.py๐ค Contributing
We welcome contributions! You can help by:
- ๐ Reporting bugs
- ๐ก Suggesting features
- ๐ Improving documentation
- ๐งช Testing with different solutions
- โก Optimizing performance
๐ License
This project is licensed under the MIT License.
๐ Acknowledgments
- ๐ค HuggingFace for Transformers library and hosting
- ๐ BigCode Team for StarCoder2 model
- โก FastAPI for the web framework
- ๐ป LeetCode for inspiration
Made with โค๏ธ for the coding community
โญ Star this project if you find it useful!
