A web application that generates new programming task levels based on existing examples from Code.org's curriculum. Uses Google's Gemini AI to analyze example levels and create similar new tasks with instructions and starter code.
- Web-based Interface: User-friendly frontend for adding and managing example levels
- Batch Processing: Generate multiple levels at once from JSON or CSV files
- Multiple Level Support: Add multiple example levels to generate more contextually relevant results
- Bubble Choice Support: Automatically expands bubble choice levels to include all sub-levels
- Real-time Generation: Uses Gemini AI to generate new tasks on-demand
- Easy Copy-Paste: One-click copy functionality for instructions and starter code
- Editable Results: Edit generated instructions and starter code before saving
- Save Functionality: Download generated levels as JSON files locally
- Responsive Design: Works on desktop and mobile browsers
- Python 3.8+
- Google API Key (Get one here)
-
Install dependencies:
pip install -r backend/requirements.txt
-
Set your Google API Key: Create a .env file and use GEMINI_API_KEY=
-
Run the application:
Windows:
run.bat
macOS/Linux:
chmod +x run.sh ./run.sh
-
Open the frontend:
- Open
frontend/index.htmlin your web browser - Or visit
http://localhost:8000if using a local server
- Open
-
Add Example Levels
- Click "Add Level" to add level input fields
- Enter the level name (e.g.,
programming-fundamentals-lesson6-level1_2025-launch_2025) - Select the level type (Level or Bubble Choice)
- Add multiple examples for better results
- Use "Remove" to delete individual levels
- Use "Clear All" to start over
-
Generate New Level
- Click "Generate New Level" button
- Wait 10-30 seconds for processing
- View generated results (may include multiple examples)
- Each result card shows instructions and starter code
-
Edit Generated Content
- Click "Edit" on any instruction or code block to modify
- Click "Lock" to save your changes
- Edits are preserved when saving
-
Save Results
- Individual Save: Click "Save This Example" on any result card
- Bulk Save: Enter a base filename and click "Save All Examples"
- Files are downloaded as JSON to your computer
- Multiple examples are numbered automatically (e.g.,
my-level-1.json,my-level-2.json)
-
Load Existing Levels
- Click "📁 Load JSON File" to load previously generated levels
- View and edit loaded content
- Save modifications as needed
-
Copy to Clipboard
- Click "Copy" on any instruction or code block
- Paste content directly into Code.org or other tools
For generating multiple levels at once, use the batch_generate.py command-line tool.
# Generate from JSON file
python batch_generate.py batch.json
# Generate from CSV file
python batch_generate.py test_levels.csv{
"functions-define-1": [
{"name": "programming-fundamentals-lesson4-level2_2025-launch_2025", "type": "level"},
{"name": "programming-fundamentals-lesson4-level3_2025-launch_2025", "type": "bubble_choice"}
],
"variables-intro-1": [
{"name": "programming-fundamentals-lesson2-level1_2025-launch_2025", "type": "level"}
]
}- Key: Base filename for the generated level (without
.jsonextension) - Value: Array of source levels to analyze and generate from
- Fields:
name: The level name from Code.org repositorytype: Eitherlevelorbubble_choice
name,level_name,type
functions-define-1,programming-fundamentals-lesson4-level2_2025-launch_2025,level
functions-define-1,programming-fundamentals-lesson4-level3_2025-launch_2025,bubble_choice
variables-intro-1,programming-fundamentals-lesson2-level1_2025-launch_2025,level- Columns:
name: Base filename for the generated levellevel_name: The level name from Code.org repositorytype: Eitherlevelorbubble_choice
Note: When you provide a CSV file, it's automatically converted to JSON format and saved with the same base name (e.g., test_levels.csv → test_levels.json)
Generated levels are saved in the saved/ directory with the filenames specified in your input file:
saved/
├── functions-define-1.json
└── variables-intro-1.json
- Automatic Conversion: CSV files are automatically converted to JSON
- Skip Existing: Files in
saved/directory are skipped if they already exist - Progress Tracking: Real-time progress output for each batch item
- Summary Report: Complete summary showing successes and failures
- Error Handling: Continues processing even if individual items fail
- Create a batch request file (
my_levels.csvormy_levels.json) - Run the batch generator:
python batch_generate.py my_levels.csv - Find generated levels in the
saved/directory - Review and use the generated levels in your curriculum
level-generator/
├── backend/
│ ├── app.py # Flask API server
│ ├── requirements.txt # Python dependencies
│ └── .env # Environment variables (GEMINI_API_KEY)
├── frontend/
│ ├── index.html # Main UI
│ ├── styles.css # Styling
│ └── app.js # Frontend logic
├── saved/ # Generated levels from batch processing
├── batch_generate.py # Batch generation CLI tool
├── level_generator.py # Core generation functions
├── utils.py # Shared utility functions
├── batch.json # Example batch request file (JSON)
├── test_levels.csv # Example batch request file (CSV)
├── SETUP.md # Detailed setup guide
├── TEST_GUIDE.md # Testing documentation
├── run.bat # Windows startup script
└── run.sh # macOS/Linux startup script
-
Frontend (
frontend/)- User-friendly interface for adding example levels
- Real-time form validation
- Multiple result cards for generated examples
- Edit functionality for instructions and starter code
- Copy to clipboard and save to file features
- Load previously generated JSON files
-
Backend (
backend/app.py)POST /api/generate: Processes level generation requestsPOST /api/save: Saves generated levels to serverGET /api/health: Health check endpoint- Uses CORS for cross-origin requests
- Returns multiple examples when appropriate
-
Core Logic (
level_generator.py)fetch_all_levels(): Fetches level data from Code.org repositoryanalyze_and_generate_file(): Uses Gemini AI to generate new examples- Handles both single levels and bubble choice expansion
- Shared by both web interface and batch processing
-
CLI Tool (
batch_generate.py)- Processes JSON or CSV batch files
- Automatically converts CSV to JSON
- Generates multiple levels sequentially
- Saves results to
saved/directory - Provides progress tracking and summary report
-
Utility Functions (
utils.py)save_level_json(): Saves generated levels with conflict handlingsave_json_format(): Converts API response to level file format- Shared utilities for consistent file operations
Generate a new level based on examples.
Request:
{
"levels": [
{
"name": "programming-fundamentals-lesson6-level1_2025-launch_2025",
"type": "level"
}
]
}Response:
{
"success": true,
"generated": "{\"instructions\": \"...\", \"starter_code\": \"...\"}",
"examples_used": 3
}python backend/app.pyServer runs on http://localhost:5000
cd frontend
python -m http.server 8000Access at http://localhost:8000
Input:
- Level 1:
programming-fundamentals-lesson6-level1_2025-launch_2025(type: level) - Level 2:
programming-fundamentals-lesson6-level2_2025-launch_2025(type: level) - Level 3:
programming-fundamentals-lesson6-level3_2025-launch_2025(type: level)
Output:
- One or more generated examples
- New instructions in markdown format
- New starter code in Python
- Contextually similar to the input examples
- Downloadable as JSON files
Input File (batch.json):
{
"loops-intro-1": [
{"name": "programming-fundamentals-lesson8-level1_2025-launch_2025", "type": "level"},
{"name": "programming-fundamentals-lesson8-level2_2025-launch_2025", "type": "level"}
],
"functions-practice-1": [
{"name": "programming-fundamentals-lesson4-level5_2025-launch_2025", "type": "level"}
]
}Command:
python batch_generate.py batch.jsonOutput:
saved/loops-intro-1.json
saved/functions-practice-1.json
Backend won't start?
- Verify
GEMINI_API_KEYis set inbackend/.env - Check Python version:
python --version(requires 3.8+) - Install dependencies:
pip install -r backend/requirements.txt
CORS errors?
- Ensure backend is running on port 5000
- Try using a local server for frontend
- Check browser console for specific error messages
No results generated?
- Verify level names exactly match Code.org repository
- Check backend console for API errors
- Ensure you have internet connection
- Verify your Gemini API key is valid
Can't save files?
- Browser may block downloads - check browser settings
- Ensure you've entered a valid filename
- Check browser's download location
batch_generate.py fails to run?
- Verify
GEMINI_API_KEYis set inbackend/.env - Check file path to batch JSON/CSV file
- Ensure Python dependencies are installed
CSV conversion errors?
- Verify CSV has required columns:
name,level_name,type - Check for malformed CSV (missing commas, quotes)
- Ensure CSV encoding is UTF-8
Some batch items fail?
- Check that level names exist in Code.org repository
- Review console output for specific error messages
- Verify API rate limits aren't exceeded
- Failed items don't stop processing of other items
Files not saving?
- Check permissions on
saved/directory - Ensure disk space is available
- Verify filenames don't contain invalid characters
See SETUP.md for detailed setup instructions and troubleshooting.
- Level names must exactly match those in Code.org's GitHub repository
- Bubble choice levels automatically expand to include sub-levels
- API key (GEMINI_API_KEY) is required for Gemini AI to function
- Generated levels can be edited in the web interface before saving
- Batch generation automatically skips files that already exist in
saved/directory - CSV files are automatically converted to JSON format during batch processing
- Both web interface and batch generation use the same core
level_generator.pyfunctions
This project uses the Code.org curriculum data and Google's Gemini AI.