Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 

Repository files navigation

πŸ€– CodeAnalyzer Chatbot

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.

πŸš€ Features

  • πŸ” 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

πŸ—οΈ Technologies Used

  • Python
  • Streamlit – Web application interface
  • LangChain – LLM application framework
  • LangGraph – Agent/workflow management
  • Groq – LLM API
  • python-dotenv – Environment variable management

πŸ“‚ Project Structure

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.

βš™οΈ Requirements

Make sure you have the following installed:

  • Python 3.10 or higher
  • pip
  • Git
  • A Groq API key

πŸ”§ Installation

1. Clone the repository

git clone https://github.com/prasana-developer/CodeAnalyzer-Chatbot.git

Move into the project directory:

cd CodeAnalyzer-Chatbot

2. Create a virtual environment

Windows:

python -m venv venv

Activate it:

venv\Scripts\activate

If you are using PowerShell:

.\venv\Scripts\Activate.ps1

3. Install dependencies

If requirements.txt is available:

pip install -r requirements.txt

If you don't have a requirements.txt yet, install the required packages:

pip install streamlit langchain langchain-groq langgraph python-dotenv

πŸ”‘ API Key Setup

This 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")

⚠️ Important

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.

▢️ How to Run

After installing the dependencies and configuring your API key, run:

streamlit run app.py

If your main Python file has a different name, replace app.py with that filename.

For example:

streamlit run main.py

Streamlit will start a local web server.

Open the URL shown in the terminal, usually:

http://localhost:8501

πŸ’¬ How to Use

  1. Start the Streamlit application.
  2. Enter or provide your Python code.
  3. Ask the chatbot to analyze the code.
  4. The AI analyzes the provided code.
  5. It explains errors or potential problems.
  6. It provides suggestions or corrected code when appropriate.
  7. You can continue the conversation with follow-up questions.

Example

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.

🧠 How It Works

The basic workflow is:

User
  β”‚
  β–Ό
Streamlit Interface
  β”‚
  β–Ό
Code Input
  β”‚
  β–Ό
AI / LLM
  β”‚
  β”œβ”€β”€ Analyze Code
  β”œβ”€β”€ Detect Possible Errors
  β”œβ”€β”€ Explain the Problem
  └── Suggest Improvements
  β”‚
  β–Ό
Chatbot Response

πŸ”„ Application Workflow

1. User Input

The user provides source code or asks a programming-related question.

2. Code Analysis

The application sends the user's request to the AI model.

3. Error Detection

The model examines the code for:

  • Syntax problems
  • Variable mistakes
  • Logical issues
  • Incorrect function usage
  • Potential improvements

4. Explanation

The chatbot explains the problem in an understandable way.

5. Suggested Solution

The chatbot can provide corrected or improved code and explain why the change is required.

πŸ“¦ Dependencies

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.txt

πŸ” Security

API 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.

πŸ› οΈ Troubleshooting

streamlit is not recognized

Try:

python -m streamlit run app.py

ModuleNotFoundError

Install the missing package:

pip install package-name

Or reinstall all dependencies:

pip install -r requirements.txt

API key error

Check that:

  • .env exists in the project directory.
  • The variable is named GROQ_API_KEY.
  • The API key is valid.
  • load_dotenv() is being called.

Port already in use

Run Streamlit on another port:

streamlit run app.py --server.port 8502

🚧 Future Improvements

Possible 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

🎯 Purpose

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

πŸ‘¨β€πŸ’» Author

Prasana Developer

GitHub: https://github.com/prasana-developer

⭐ Contributing

Contributions, suggestions, and improvements are welcome.

To contribute:

  1. Fork the repository.
  2. Create a new branch.
  3. Make your changes.
  4. Commit your changes.
  5. Open a Pull Request.

πŸ“„ License

This project is available for educational and development purposes.


⭐ If you find this project useful, consider giving the repository a Star!

About

An AI-powered chatbot that analyzes code, identifies errors, explains issues, and provides helpful suggestions to improve code quality and understanding. Built using Python and Generative AI technologies.

Resources

Stars

12 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages