An intelligent tool that reads code and explains it in plain English using State-of-the-Art NLP models.
- About the Project
- Key Features
- Tech Stack
- Folder Structure
- Installation & Setup
- Usage
- Future Enhancements
- Troubleshooting
LogicLens is a developer tool designed to bridge the gap between complex code syntax and human readability. By leveraging the Salesforce CodeT5 model (based on the T5 architecture), LogicLens can analyze Python code snippets and generate accurate, human-readable summaries.
Additionally, it calculates Cyclomatic Complexity to provide a "Risk Score," helping developers identify code that is prone to bugs or difficult to maintain.
- 🤖 AI Code Summarization: Instantly converts Python functions into clear English explanations.
- 📉 Complexity Analysis: visualizes the risk level of code using industry-standard metrics (Cyclomatic Complexity).
- ⚡ Real-Time Processing: Powered by
st.cache_resourcefor fast inference after the initial model load. - 🎨 Clean UI: Built with Streamlit for a responsive and modern user interface.
| Component | Technology | Description |
|---|---|---|
| Frontend | Streamlit | Web application framework |
| AI Model | CodeT5 (Salesforce) | Text-to-Text Transformer specialized for Code |
| ML Engine | PyTorch & Transformers | Deep learning backend |
| Analysis | Radon | Static code analysis tool for metrics |
LogicLens/
│
├── app.py # Main Streamlit application entry point
├── requirements.txt # Python dependencies
├── README.md # Project documentation
│
└── src/ # Source code package
├── __init__.py # Package initializer
├── model_loader.py # Model caching and inference logic
└── analyzer.py # Complexity calculation algorithms
Follow these steps to set up the project locally.
git clone [https://github.com/your-username/LogicLens.git](https://github.com/your-username/LogicLens.git)
cd LogicLens
# Windows
python -m venv venv
venv\Scripts\activate
# Mac/Linux
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
Note: This will install PyTorch and Transformers. The download size may be approx 1-2GB.
streamlit run app.py
- Open the link provided in your terminal (usually
http://localhost:8501). - Wait for the model to download (only happens on the first run).
- Paste a Python function into the text area.
- Click "Analyze Code 🚀".
- View the AI Explanation on the left and the Bug Probability on the right.
These are features planned for V2.0 to make LogicLens a production-grade tool:
- Multi-Language Support: Extend support to C++, Java, and JavaScript using the
CodeT5-multimodel capabilities. - IDE Extension: Wrap this logic into a VS Code Extension so developers can get explanations directly in their editor.
- Code Optimization Suggestions: Upgrade the AI to not just explain, but also refactor the code (e.g., "Suggest changing O(n²) loop to O(n)").
- GitHub Integration: Allow users to paste a GitHub URL instead of raw code to analyze entire files.
- Dark Mode & Syntax Highlighting: Improve the UI to auto-detect language syntax for better readability.
Q: The app crashes with NameError: name 'st' is not defined. A: Ensure you have import streamlit as st at the top of your src/model_loader.py file.
Q: The model download is stuck. A: Check your internet connection. The model is large (~800MB). If it fails, delete the cache and try again.
Q: "Out of Memory" (OOM) error? A: If you are on a machine with low RAM, try using a smaller model version like Salesforce/codet5-small in model_loader.py.
Contributions are welcome!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Distributed under the MIT License. See LICENSE for more information.
LogicLens • Created by Dharm Patel