This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
pip install -r requirements.txtCreate .env file with:
GEMINI_API_KEY="your_gemini_api_key_here"
FLASK_SECRET_KEY="optional_custom_secret_key"
python preprocess_programs.pyConverts PDF/Markdown party programs to JSON cache. The cache is included in git repository for fast deployments. Only run this when adding/updating party programs, then commit the updated cache.
python app.pyStarts the Flask web server on port 8080. Will use cached programs if available, fallback to direct loading if not.
python main.pyRuns analysis with predefined answers against party programs using Gemini API.
- app.py: Main Flask application with two distinct modes - political quiz and Q&A chat
- utils.py: File processing utilities for loading PDF and Markdown party programs
- main.py: Testing script for analyzing predefined answers against party programs
The application uses a two-tier loading system:
- Pre-built Cache: JSON cache in
./cache/directory is included in git repository (6MB) for instant deployments - Lazy Loading:
PartyProgramCacheclass loads programs on-demand from JSON cache, with fallback to direct file loading
The cache includes topic extraction for faster content retrieval. When party programs are updated, run preprocess_programs.py locally and commit the updated cache.
-
Quiz Mode: 5-question political stance assessment with session management
- Generates dynamic questions using Gemini
- Tracks user answers in Flask sessions
- Analyzes political stance and matches to best-fitting party
-
Chat Mode: Direct Q&A about specific parties or general political topics
- Detects party names from user messages using comprehensive mapping system
- Extracts relevant content sections (max 20k chars) based on question keywords
- Supports both single-party and multi-party comparisons
The system includes intelligent content extraction that:
- Maps political topics to relevant keywords (taxes, immigration, environment, etc.)
- Extracts only relevant paragraphs for efficient LLM processing
- Limits content to 20,000 characters per party to manage API costs
Complex fuzzy matching system in detect_parties_from_message() handles:
- Norwegian party name variations and abbreviations
- Word boundary matching to avoid false positives
- Longest-match-first algorithm for accurate detection
- Special handling for generic terms like "partiene" (the parties)
Quiz functionality uses Flask sessions to maintain state across:
- User answers collection
- Question generation tracking
- Quiz completion status
- Temporary session cleanup after analysis