A dynamic, AI-powered grading system that uses semantic analysis to automatically grade student answers with customizable rules, user authentication, and persistent session management.
- User registration and login with secure password hashing
- JWT-based session management with configurable timeouts
- Persistent sessions that survive page reloads and browser navigation
- Multi-layer session validation (Session State + Query Parameters + MongoDB)
- User-specific data isolation - each user can only access their own data
- Input validation and sanitization
- Hybrid matching algorithms:
- π Exact Phrase: Matches specific formulas, terms, or mentions
- π Keyword Matching: Identifies important concepts with lemmatization
- π§ Semantic: Uses AI embeddings for conceptual understanding
- Auto-detection of rule types based on natural language
- Content-agnostic - works with any subject or domain
- Configurable grading thresholds per user
- Create comprehensive tests with multiple questions
- Upload test answers via CSV or manual entry
- Batch grading for entire tests
- Test statistics and grade distribution analysis
- Export/Import functionality for data management
- Customizable grade thresholds (A, B, C, D, F)
- Quick preset options (Standard, Strict, Lenient)
- Real-time preview of threshold changes
- Rule-based scoring with sample answer bonuses
- Test-specific grading with overall scores
- Streamlit web interface with responsive design
- Intuitive navigation with clear sections
- Debug mode for detailed grading analysis
- Real-time feedback and error handling
- Session status indicators showing persistence and expiry
- CSV import/export for bulk operations
- Template downloads for easy data entry
- Bulk operations for data cleanup
- Test answer management with structured uploads
- Python 3.8+
- MongoDB (local or cloud)
- Internet connection (for AI model download)
-
Clone the repository
git clone <repository-url> cd semantic_grader_mvp
-
Create virtual environment
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies
pip install -r requirements.txt
-
Set up MongoDB
- Install MongoDB locally or use MongoDB Atlas
- Update
config.py
with your MongoDB URI if needed
-
Configure environment (optional)
# Create .env file for production echo "JWT_SECRET=your-super-secret-key-here" > .env
-
Run the application
streamlit run app.py
- Register with username, email, and password
- Login to access your personal workspace
- Sessions persist across page reloads and browser navigation
- Session status is displayed in the UI
- Write question text and sample answer
- Add marking rules (auto-detected types):
"mentions F = ma"
β Exact phrase"contains protons, electrons"
β Keyword matching"explains the relationship"
β Semantic understanding
- Create Tests: Combine multiple questions into comprehensive tests
- Upload Test Answers: Use CSV templates or manual entry
- Grade Tests: Batch process all test submissions
- View Results: See detailed statistics and grade distributions
- Select a question
- Enter student name, roll number, and answer
- Submit for grading
- CSV Import: Bulk upload multiple answers
- Customize grade thresholds (A: 85%, B: 70%, etc.)
- Use presets or set custom values
- Preview changes before saving
- Execute semantic analysis on all answers
- View detailed results with matched/missed rules
- Enable debug mode for detailed analysis
- Test Grading: Process entire tests with overall scores
- Export Data: Download all data as CSV ZIP
- Import Answers: Bulk upload student responses
- Templates: Download CSV templates for easy data entry
- Bulk Operations: Clear data when needed
semantic_grader_mvp/
βββ app.py # Main Streamlit application
βββ config.py # Configuration and settings
βββ requirements.txt # Python dependencies
βββ core/
β βββ db.py # Database operations
β βββ grader.py # Grading algorithms
βββ services/
β βββ auth_service.py # Authentication & session management
β βββ grading_service.py # Grading orchestration
β βββ test_grading_service.py # Test-specific grading
β βββ import_export_service.py # Data import/export
βββ tests/ # Test files
- Session Timeout: Default: 24 hours (configurable)
- Refresh Window: 10 minutes before expiry
- MongoDB Cleanup: 30 days for old sessions
- Persistence Layers: Session State + Query Parameters + MongoDB
- Semantic weights: Direct similarity vs concept overlap
- Rule thresholds: Matching sensitivity for each rule type
- Scoring weights: Rule-based vs sample answer influence
- MongoDB URI: Connection string
- Database name: Default: "semantic_grader"
- Collections: users, questions, answers, grades, settings, sessions, tests, test_answers, test_grades
- JWT Secret: Session token encryption
- Session Timeout: Default: 24 hours
- Password Requirements: Min 6 characters
Run the test files to verify functionality:
python test_improved_grading.py
python test_final_grading.py
python test_hybrid_grading.py
python test_grading_service.py
python test_import_export.py
Enable debug mode in app.py
:
DEBUG_SESSION = True # Set to True in main() function
Enable debug mode in the "Run Grading" page to see:
- Extracted key phrases from rules
- Word-level matching details
- Semantic similarity scores
- Rule type auto-detection
- Password hashing with bcrypt
- JWT token authentication
- Multi-layer session validation
- Persistent session management
- User data isolation
- Input validation
- Error handling without exposing sensitive data
- Change default JWT secret
- Use environment variables for sensitive data
- Enable HTTPS in production
- Implement rate limiting
- Monitor session activity
- Add database indexing
- Implement caching
- Use connection pooling
- Monitor resource usage
- Optimize session queries
- Add load balancing
- Implement microservices
- Use cloud databases
- Add monitoring and logging
- Session distribution across servers
- User Authentication β Credential validation
- Token Creation β JWT token generation
- Multi-Storage β Session State + Query Parameters + MongoDB
- Session Persistence β Survives page reloads
- Token Retrieval β Session State β Query Parameters (fallback)
- MongoDB Validation β Server-side session verification
- User Data Recovery β Restore user information
- Session Update β Refresh activity timestamps
- Token Check β Validate existence and expiration
- MongoDB Verification β Confirm server-side session
- Auto Refresh β Extend session if needed
- Cleanup β Remove expired sessions
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License.
For issues and questions:
- Check the debug mode for detailed analysis
- Review the test files for examples
- Check MongoDB connection and data
- Verify all dependencies are installed
- Enable session debugging for authentication issues
Built with β€οΈ using Streamlit, MongoDB, and AI-powered semantic analysis