A comprehensive platform for crawling mathematical Q&A websites and automatically formalizing problems into Lean 4.
- Multi-Site Crawling: Support for Math StackExchange, MathOverflow, AMM, and custom sites
- LLM Preprocessing: GLM-4V for image OCR, GLM-4 for content validation and correction
- Dual Lean Converter System: Two independent Lean converters with different strengths
- Kimina Legacy: Fast local conversion using Kimina-Autoformalizer-7B via VLLM
- GLM LLM Agent: High-quality conversion using GLM-4.7 with iterative correction
- Lean Verification: Verify Lean code against kimina-lean-server for correctness
- Independent Converter Tracking: Each converter maintains its own conversion results
- Web Control Platform: Full-featured Vue 3 frontend for monitoring and control
- Scheduled Tasks: APScheduler-based automation for crawling and processing
/datadisk/Web2Lean/
├── backend/ # Python backend (Flask + SQLAlchemy)
│ ├── api/ # REST API endpoints
│ ├── core/ # Crawler implementations
│ ├── database/ # Database models and management
│ ├── processing/ # LLM processing & Lean conversion
│ └── utils/ # Utilities (image handling, LLM clients)
├── frontend/ # Vue 3 frontend (Element Plus + ECharts)
├── data/ # SQLite databases & images
└── legacy/ # Original codebase (preserved)
Backend:
pip install -r requirements.txtFrontend:
cd frontend
npm installSet the Zhipu API key:
export ZHIPU_API_KEY="your-api-key-here"Configure GLM models (optional, defaults provided):
# For LLM-based Lean converter
export GLM_LEAN_MODEL="glm-4.7" # or "glm-4" for faster conversion
export LEAN_MAX_ITERATIONS=1 # Max correction iterations (default: 1)Or configure in the Web UI at Configuration > Models.
vllm serve /root/Kimina-Autoformalizer-7B --tensor-parallel-size 1 --port 8000 --host 0.0.0.0Or use the built-in command:
python main.py --vllm-startThe verification feature requires kimina-lean-server running:
# Default: http://127.0.0.1:9000
# Configure in backend/config/settings.py if differentpython main.py --init-dbpython main.pyAPI will be available at http://localhost:5000
cd frontend
npm run devFrontend will be available at http://localhost:3000
- Open
http://localhost:3000 - Navigate to Crawlers to start/stop site crawlers
- Navigate to Processing to:
- Trigger LLM preprocessing (GLM-4V + GLM-4)
- Start Lean conversion with selected converter:
- Kimina (Legacy): Fast conversion using local model
- GLM LLM Agent: High-quality conversion with iterative correction
- Verify converted Lean code
- Navigate to Database to:
- Browse and view processed content
- View Lean code split by converter (Question/Answer Lean code)
- Compare results from different converters
- Check verification status for each converter
- Clear data by converter or stage
- Navigate to Configuration to:
- Manage sites, prompts, and scheduled tasks
- Configure GLM models and Lean conversion settings
Example: Start a crawler
curl -X POST http://localhost:5000/api/crawlers/start \
-H "Content-Type: application/json" \
-d '{"site_name": "math_stackexchange", "mode": "incremental"}'Example: Trigger Lean conversion with specific converter
# Using Kimina Legacy converter
curl -X POST http://localhost:5000/api/processing/start-lean \
-H "Content-Type: application/json" \
-d '{"limit": 10, "converter": "kimina"}'
# Using GLM LLM Agent converter
curl -X POST http://localhost:5000/api/processing/start-lean \
-H "Content-Type: application/json" \
-d '{"limit": 10, "converter": "llm"}'Example: Verify all Lean-converted questions
curl -X POST http://localhost:5000/api/verification/verify-all \
-H "Content-Type: application/json" \
-d '{"limit": 100, "async": true}'Edit backend/config/sites.json to configure crawl targets:
{
"sites": {
"math_stackexchange": {
"site_type": "math_se",
"base_url": "https://math.stackexchange.com",
"enabled": true,
"pages_per_run": 10,
"request_delay": 8.0
}
}
}Edit backend/config/prompts.json to customize LLM behavior:
image_ocr_decision: Prompt for GLM-4V image analysiscontent_correction: Prompt for GLM-4 content validationlean_conversion: Prompt for Kimina-Autoformalizer-7B
- Raw Data: Questions/answers crawled from web
- OCR (GLM-4V): Images analyzed, text extracted when possible
- Preprocessing (GLM-4): Content validated and corrected
- Deduplication (interface only, not implemented)
- Lean Conversion: Two independent converter options
- Kimina Legacy Converter:
- Uses local Kimina-Autoformalizer-7B via VLLM
- Fast conversion speed
- Requires VLLM server running
- GLM LLM Agent Converter:
- Uses GLM-4.7 API for high-quality conversion
- Generates Question Lean Code (theorem declaration with
:= by sorry) - Generates Answer Lean Code (complete theorem with rigorous proof)
- Iterative correction with Lean verifier feedback (configurable iterations)
- Automatically fixes errors based on verifier output
- Independent Operation: Each converter processes only questions it hasn't converted
- Comparison: View results from both converters side-by-side
- Kimina Legacy Converter:
- Lean Verification: kimina-lean-server validates generated code
- Independent verification status per converter
- Track verification history (passed/warning/failed)
| Endpoint | Method | Description |
|---|---|---|
/api/crawlers/start |
POST | Start a crawler |
/api/crawlers/stop/:site |
POST | Stop a crawler |
/api/crawlers/status |
GET | Get all crawler statuses |
/api/processing/start-lean |
POST | Start Lean conversion (supports converter param: kimina or llm) |
/api/processing/preprocess |
POST | Start LLM preprocessing |
/api/processing/task/:type/progress |
GET | Get progress for a task type |
/api/verification/verify/:id |
POST | Verify a single question's Lean code |
/api/verification/verify-all |
POST | Batch verify all Lean-converted questions |
/api/verification/status/:id |
GET | Get verification status for a question |
/api/database/questions |
GET | List/search questions |
/api/database/questions/:id/lean-conversions |
GET | Get all Lean conversions for a question |
/api/database/clear |
POST | Clear data by stage (lean/preprocess/verification) |
/api/statistics/overview |
GET | Get overall statistics |
/api/config/sites |
GET/POST | Manage site configurations |
/api/config/models |
GET/PUT | Manage model configurations |
Choose the right converter for your use case:
Kimina Legacy Converter:
- ✅ Fast conversion speed (local model)
- ✅ No API costs
- ✅ Good for batch processing
- ❌ Requires VLLM server setup
- ❌ Less accurate on complex problems
GLM LLM Agent Converter:
- ✅ Higher quality output
- ✅ Better at understanding context
- ✅ Iterative error correction
- ✅ No local model setup needed
- ❌ API costs apply
- ❌ Slower than local model
Use the interactive test tool to test Lean conversion without going through the full pipeline:
python test_lean_converter.pyThis allows you to:
- Test question conversion (theorem declaration only)
- Test answer conversion (complete theorem with proof)
- Quickly iterate on prompts and see results
- Compare converter outputs side-by-side
- Create a new crawler class in
backend/core/extendingBaseCrawler - Implement abstract methods:
fetch_questions_page(page)parse_question(raw_data)fetch_answers(question_id)
- Import and register in
backend/api/routes/crawlers.py
- Edit prompts via Web UI at Configuration > Prompts
- Or edit
backend/config/prompts.jsondirectly
The dual converter system allows you to leverage both converters:
-
Initial Processing with Kimina:
- Process large batches quickly with Kimina Legacy
- Get baseline Lean code for all questions
-
Selective Enhancement with GLM:
- Use GLM LLM Agent for questions that failed verification
- Apply GLM converter to complex problems needing higher accuracy
- Compare outputs from both converters
-
Verification and Selection:
- Run verification on both converter outputs
- Select the best result based on verification status
- Track which converter produced verified code
-
Parallel Processing:
- Both converters can run simultaneously
- Each maintains independent progress tracking
- No interference between converters
Problem: Kimina converter fails to start
- Solution: Ensure VLLM server is running on port 8000
- Check:
curl http://localhost:8000/v1/models
Problem: GLM converter returns errors
- Solution: Verify ZHIPU_API_KEY is set correctly
- Check: API key has sufficient quota
Problem: Conversion produces invalid Lean code
- Solution:
- For Kimina: Check VLLM model is loaded correctly
- For GLM: Increase
LEAN_MAX_ITERATIONSfor more correction attempts - Check kimina-lean-server is running for verification
Problem: Verification timeout
- Solution: Ensure kimina-lean-server is running on port 9000
- Check:
curl http://127.0.0.1:9000/health
Problem: All conversions fail verification
- Solution:
- Try different converter (Kimina vs GLM)
- Increase max iterations for GLM converter
- Check preprocessing quality (theorem names, content)
MIT License - See LICENSE file for details