CodeExplain is a beginner-friendly code explanation tool that helps students understand code snippets in plain English. It provides a line-by-line breakdown, complexity analysis, suggested improvements, and comprehension quizzes.
- Multi-Model Support: Use Gemini API, Ollama (local), or LM Studio (local) as the underlying LLM.
- Structured Explanation: Provides summary, plain English explanation, line-by-line breakdown, time/space complexity, improvements, and quizzes in clearly separated sections.
- Language Support: Supports explaining code in English or Hinglish (and potentially other languages).
- No Complex Setup: A simple Streamlit interface that just works.
- Clone the repository.
- Install the requirements:
python -m venv venv .\venv\Scripts\pip install -r requirements.txt
- Set up your environment variables by editing the
.envfile (see example structure below):GEMINI_API_KEY=your_api_key_here GEMINI_MODEL=gemini-2.5-flash OLLAMA_MODEL=llama3 LMSTUDIO_MODEL=gemma4-e4b LMSTUDIO_URL=http://localhost:1234/v1 OLLAMA_URL=http://localhost:11434
Run the Streamlit application:
.\venv\Scripts\streamlit run app.py- Open the application in your browser (usually http://localhost:8501).
- Select your Model Provider from the sidebar.
- Choose the target language for the explanation.
- Select the code language of the snippet you're pasting.
- Paste your code snippet and click Explain Code.
You can easily swap out the AI model powering your code explanations via the .env file configuration:
By default, the app is configured to use gemini-2.5-flash. If you want to use a different Gemini model (like gemini-2.5-pro):
- Open your
.envfile. - Edit the
GEMINI_MODELline:GEMINI_MODEL=gemini-2.5-pro - Ensure your
GEMINI_API_KEYis set correctly.
Ollama lets you run models completely offline on your own computer.
- Make sure you have pulled your desired model locally (e.g.,
ollama run llama3.2). - Open your
.envfile. - Edit the
OLLAMA_MODELline to match:OLLAMA_MODEL=model_name - Select Ollama from the sidebar dropdown in the Streamlit app.
LM Studio is another local AI manager with a graphical interface.
- Open LM Studio, search for a model (like
gemma4-e4b), download it, and load it. - Go to the Local Server tab in LM Studio and click Start Server.
- Edit the
LMSTUDIO_MODELline in.envto match the exact name of the loaded model:LMSTUDIO_MODEL=model_name - Select LM Studio from the sidebar dropdown in the Streamlit app.
Important
Remember to restart your Streamlit server (press Ctrl+C in the terminal and run streamlit run app.py again) whenever you make changes to your .env file so the app loads the new settings!
- The application heavily relies on the LLM's ability to return valid JSON. If the model fails to return properly formatted JSON, the parsing will fail. Using capable models like
gemini-2.5-flashorqwen2.5-coderlocally is recommended. - Code execution is not supported.