An AI-powered Code Analyzer Chatbot that helps developers understand, debug, and improve their code.
The chatbot can analyze code, identify possible errors, explain problems in simple language, and provide suggestions for improving the code. It uses Generative AI to interact with the user through a conversational interface.
- π Analyze Python code
- π Identify errors and possible bugs
- π‘ Explain errors in simple language
- π οΈ Suggest possible fixes
- π Explain how the code works
- π¬ Interactive chatbot interface
- π€ Powered by Generative AI
- β‘ Streamlit-based web interface
- π API key stored using environment variables
- Python
- Streamlit β Web application interface
- LangChain β LLM application framework
- LangGraph β Agent/workflow management
- Groq β LLM API
- python-dotenv β Environment variable management
CodeAnalyzer-Chatbot/
β
βββ app.py
βββ .env
βββ .gitignore
βββ requirements.txt
βββ README.md
The filenames may be different depending on your project. Update the structure above if your main Python file has another name.
Make sure you have the following installed:
- Python 3.10 or higher
- pip
- Git
- A Groq API key
git clone https://github.com/prasana-developer/CodeAnalyzer-Chatbot.gitMove into the project directory:
cd CodeAnalyzer-ChatbotWindows:
python -m venv venvActivate it:
venv\Scripts\activateIf you are using PowerShell:
.\venv\Scripts\Activate.ps1If requirements.txt is available:
pip install -r requirements.txtIf you don't have a requirements.txt yet, install the required packages:
pip install streamlit langchain langchain-groq langgraph python-dotenvThis project requires a Groq API key.
Create a file named:
.env
Inside the .env file, add:
GROQ_API_KEY=your_groq_api_key_here
The application should load the key using environment variables rather than placing the API key directly inside the Python source code.
Example:
import os
from dotenv import load_dotenv
load_dotenv()
api_key = os.getenv("GROQ_API_KEY")Never upload your .env file to GitHub.
Your .gitignore should contain:
.env
venv/
__pycache__/
*.pyc
If an API key has already been uploaded publicly, revoke/rotate that key immediately and replace it with a new one.
After installing the dependencies and configuring your API key, run:
streamlit run app.pyIf your main Python file has a different name, replace app.py with that filename.
For example:
streamlit run main.pyStreamlit will start a local web server.
Open the URL shown in the terminal, usually:
http://localhost:8501
- Start the Streamlit application.
- Enter or provide your Python code.
- Ask the chatbot to analyze the code.
- The AI analyzes the provided code.
- It explains errors or potential problems.
- It provides suggestions or corrected code when appropriate.
- You can continue the conversation with follow-up questions.
Input:
numbers = [10, 20, 30, 40, 50]
total = 0
for number in numbers:
total += number
print(total)
print(total / len(number))The chatbot can identify that number is a single value from the loop rather than the complete list and explain how to correct the calculation.
The basic workflow is:
User
β
βΌ
Streamlit Interface
β
βΌ
Code Input
β
βΌ
AI / LLM
β
βββ Analyze Code
βββ Detect Possible Errors
βββ Explain the Problem
βββ Suggest Improvements
β
βΌ
Chatbot Response
The user provides source code or asks a programming-related question.
The application sends the user's request to the AI model.
The model examines the code for:
- Syntax problems
- Variable mistakes
- Logical issues
- Incorrect function usage
- Potential improvements
The chatbot explains the problem in an understandable way.
The chatbot can provide corrected or improved code and explain why the change is required.
Typical dependencies used by the project include:
streamlit
langchain
langchain-groq
langgraph
python-dotenv
If your project has a requirements.txt, install everything using:
pip install -r requirements.txtAPI keys should never be hard-coded in the source code.
β Don't do this:
api_key = "gsk_your_secret_key"β Use an environment variable:
api_key = os.getenv("GROQ_API_KEY")And keep .env inside .gitignore.
Try:
python -m streamlit run app.pyInstall the missing package:
pip install package-nameOr reinstall all dependencies:
pip install -r requirements.txtCheck that:
.envexists in the project directory.- The variable is named
GROQ_API_KEY. - The API key is valid.
load_dotenv()is being called.
Run Streamlit on another port:
streamlit run app.py --server.port 8502Possible future enhancements include:
- π Support for multiple programming languages
- π Upload source-code files
- π§ͺ Automatic test-case generation
- π Advanced static code analysis
- π Code quality scoring
- π§ Automatic code refactoring
- π Code documentation generation
- π» GitHub repository analysis
- π§ Improved AI agent workflow
- π Code complexity analysis
This project was created to demonstrate how Generative AI, LLMs, LangChain, LangGraph, and Streamlit can be combined to build a practical developer-focused AI application.
It can be useful for:
- Students learning programming
- Developers debugging code
- Understanding programming errors
- Learning Generative AI
- Experimenting with AI agents and LLM applications
Prasana Developer
GitHub: https://github.com/prasana-developer
Contributions, suggestions, and improvements are welcome.
To contribute:
- Fork the repository.
- Create a new branch.
- Make your changes.
- Commit your changes.
- Open a Pull Request.
This project is available for educational and development purposes.
β If you find this project useful, consider giving the repository a Star!