CodeGuru is a locally running AI-powered code teaching assistant built with Ollama, Python, Requests, and Gradio.
The model is designed to help users solve coding-related problems, generate code, explain programming concepts, debug code, and provide programming guidance.
You are a code teaching assistant named as CodeGuru created by Aman. Answer all the code related questions being asked.
The application sends user prompts to a locally hosted Ollama API and displays the model's response through a simple Gradio web interface.
- Runs locally using Ollama
- Uses a custom Ollama model named CodeGuru
- Designed specifically for coding-related questions and problems
- Generates code and programming explanations
- Helps with programming concepts and debugging
- Simple Gradio web interface
- Uses the local Ollama API
- No external AI API key is required for the local setup
- Python virtual environment can be stored separately from the project
Codellama/
│
├── app.py
├── modelfile
├── requirements.txt
├── README.md
├── .gitignore
│
├── images/
│ ├── codeguru-introduction-response.png
│ └── codeguru-fibonacci-response.png
│
└── venv/
└── (virtual environment stored on another drive)
Note: The
venvis shown in the project structure for documentation purposes. The actual virtual environment is stored separately on another drive to save space on the project/C: drive.
The virtual environment used for this project is stored at:
G:\Program Files\Python Environments\codellama
It does not need to be physically inside the project folder.
Activate it in PowerShell with:
& "G:\Program Files\Python Environments\codellama\Scripts\Activate.ps1"After activation, the terminal should show:
(codellama)
The virtual environment is excluded from Git using .gitignore.
- Python
- Ollama
- Gradio
- Requests
- JSON
- PowerShell
- Virtual Environment (venv)
The application communicates with the locally running Ollama API.
User Coding Problem
↓
Gradio Interface
↓
Python app.py
↓
Requests HTTP POST
↓
Ollama Local API
↓
CodeGuru Model
↓
Generated Coding Answer
↓
Gradio Output
Install Ollama on your computer and make sure the Ollama service is running.
Check that Ollama is available:
ollama --versionBefore creating the custom CodeGuru model, pull the CodeLlama base model using Ollama:
ollama pull codellamaThis downloads the CodeLlama model that is used as the base model for CodeGuru.
You can verify that CodeLlama has been downloaded with:
ollama listYou should see codellama in the list of available models.
You can also test the base model directly:
ollama run codellamaThe custom CodeGuru model is created from the project's modelfile.
Open PowerShell in the directory containing the modelfile and run:
ollama create Codeguru -f modelfileThis creates the custom Ollama model named:
Codeguru
The modelfile uses CodeLlama as the base model and adds the custom CodeGuru instructions.
Verify that the CodeGuru model exists:
ollama listYou can also test the custom model directly:
ollama run CodeguruActivate the existing virtual environment:
& "G:\Program Files\Python Environments\codellama\Scripts\Activate.ps1"Install the required Python packages:
pip install -r requirements.txtMake sure Ollama is running, activate the codellama environment, and run:
python app.pyGradio will start a local server, for example:
http://127.0.0.1:7860
Open the displayed local URL in your browser.
The application sends a request similar to:
data = {
"model": "Codeguru",
"prompt": final_prompt,
"stream": False
}The request is sent to the local Ollama generate endpoint:
http://localhost:11434/api/generate
The response is then converted from JSON and the generated text is returned to Gradio.
The response is parsed using:
data = response.json()
actual_response = data["response"]Using response.json() avoids the json.load() error that occurs when trying to load a normal string as a file object.
The project requires Python and the packages listed in requirements.txt.
Install them with:
pip install -r requirements.txtOllama must also be installed separately because it runs the local AI model.
The CodeLlama base model must be downloaded before creating CodeGuru:
ollama pull codellamaThen create the custom model:
ollama create Codeguru -f modelfile Your Computer
┌────────────────────────────────────────────────────┐
│ │
│ Browser │
│ │ │
│ ▼ │
│ Gradio :7860 │
│ │ │
│ ▼ │
│ Python app.py │
│ │ │
│ ▼ │
│ Ollama :11434 │
│ │ │
│ ▼ │
│ CodeGuru Model │
│ │
└────────────────────────────────────────────────────┘
The model inference is performed locally through Ollama.
The project includes a .gitignore file to prevent unnecessary or private files from being committed to GitHub.
Important ignored files/folders include:
venv/
.venv/
__pycache__/
.env
.vscode/
*.log
*.gguf
*.bin
*.safetensors
The virtual environment is intentionally not uploaded to GitHub because it contains installed packages and can be recreated using requirements.txt.
Make sure Ollama is installed and available in your system PATH.
Pull the base CodeLlama model:
ollama pull codellamaThen verify:
ollama listCheck the installed models:
ollama listIf CodeGuru is missing, recreate it:
ollama create Codeguru -f modelfileCheck that Ollama is running and test the model directly:
ollama run CodeguruThen restart the Python application:
python app.pyDo not use:
json.load(response)when response is a string.
Use:
data = response.json()- Add proper chat history containing both user prompts and model responses
- Add a Chatbot-style Gradio interface
- Add code syntax highlighting
- Add a clear conversation button
- Add model selection
- Add temperature and other model parameters
- Add streaming responses
- Add code execution/sandbox support
- Improve the UI and branding
This project is licensed under the MIT License.
See the LICENSE file for details.
- LinkedIn: Aman Singh
- GitHub: Aman Singh
Built as a local Generative AI project using Ollama + CodeGuru + Gradio.

