AI-Powered Code Analysis Using GPT-2 Transfer Learning
CodeMentor is a full-stack web application that analyzes code snippets for bugs, provides fixes, and suggests industry-standard improvements using advanced AI technology. Built with Flask (Python) backend and React frontend, it leverages Hugging Face's GPT-2 model for intelligent code analysis.
CodeMentor/
├── backend/ # Flask application (API, DB, analyzer)
├── frontend/ # React + TypeScript app (Vite + Tailwind)
└── README.md
To keep the project lean and immediately runnable, unused and duplicated files were removed/simplified:
- Removed Tailwind CDN and inline config from
frontend/public/index.htmlto rely on local Tailwind build. - Simplified
frontend/package.jsonto only essential dependencies (React, ReactDOM) and dev tooling (Vite, TypeScript, ESLint, Tailwind toolchain). - Simplified
frontend/src/App.tsxto a self-contained minimal app (no external component or context dependencies). - Suggested deletion of duplicate/unreferenced files (see Optional Cleanup below) to avoid confusion.
- Python 3.10+
- Node.js 18+
REACT_APP_BACKEND_URL=https://your-backend-url.onrender.com
- Deploy: Vercel will automatically build and deploy your frontend
CodeMentor/
├── backend/
│ ├── app.py # Main Flask application
│ ├── analyzer.py # GPT-2 code analysis logic
│ ├── requirements.txt # Python dependencies
│ ├── Dockerfile # Docker configuration
│ └── Procfile # Render deployment config
├── frontend/
│ ├── public/
│ │ └── index.html # Main HTML file
│ ├── src/
│ │ ├── components/ # React components
│ │ │ ├── CodeInput.js # Code submission form
│ │ │ ├── ResultsDisplay.js # Analysis results display
│ │ │ └── Navbar.js # Navigation component
│ │ ├── App.js # Main React component
│ │ ├── App.css # Custom styles
│ │ └── index.js # React entry point
│ ├── package.json # Node.js dependencies
│ └── vercel.json # Vercel deployment config
├── README.md # Project documentation
└── .gitignore # Git ignore file
- Code Submission: User submits code via the web interface
- Backend Processing: Flask receives the code and passes it to the analyzer
- AI Analysis: GPT-2 model analyzes the code using transfer learning
- Pattern Detection: Identifies bugs, potential issues, and improvement opportunities
- Results Generation: Creates structured analysis with bugs, fixes, and suggestions
- Response: Returns comprehensive results to the frontend
- Model: GPT-2 (pre-trained on diverse text data)
- Transfer Learning: Fine-tuned for code analysis tasks
- Analysis Types:
- Syntax error detection
- Logical issue identification
- Code quality assessment
- Best practice suggestions
- Performance optimization tips
cd backend
python -m pytest tests/ # If tests are implementedcd frontend
npm test # If tests are implemented- Input Validation: All code inputs are validated and sanitized
- CORS Protection: Configured for secure cross-origin requests
- Error Handling: Comprehensive error handling without exposing sensitive information
- Rate Limiting: Built-in protection against abuse (can be enhanced)
- Model Size: GPT-2 model requires significant memory (~500MB)
- Analysis Depth: Focuses on structural and pattern-based analysis
- Language Support: Primarily optimized for Python, with basic support for other languages
- Performance: First analysis may be slower due to model loading
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Hugging Face: For providing the GPT-2 model and transformers library
- Flask: For the robust Python web framework
- React: For the powerful frontend library
- Tailwind CSS: For the beautiful utility-first CSS framework
- Render & Vercel: For free hosting services
- Issues: Create an issue on GitHub
- Discussions: Use GitHub Discussions for questions
- Documentation: Check the code comments and this README
- Support for more programming languages
- Advanced code optimization suggestions
- Integration with IDEs and code editors
- Custom model training capabilities
- Real-time collaborative analysis
- Code review workflow integration
Built with ❤️ using React, Flask, and GPT-2 AI technology
CodeMentor - Your AI-powered coding companion