The Code Generator is a versatile GUI application that leverages either local AI models through Ollama or OpenAI's API to automatically generate code based on user prompts. It supports multiple programming languages and can create complete websites or standalone code snippets.
- Support for both local AI models (via Ollama) and OpenAI's API
- Multiple programming language support (HTML/CSS/JS, Python, Java, C++, JavaScript, SQL)
- User-friendly GUI with dark theme
- Code syntax highlighting
- Easy model selection
- Progress indication during code generation
- Option to save generated code to file
- Python 3.7+: required to execute the script. Available at Python
- Additional Python libraries: See
requirements.txt - Ollama (optional): to run local AI models. Available at Ollama
- OpenAI API key (optional): for using OpenAI models
- Install Python:
- Download and install Python 3.7 or later from Python.org.
- Clone the repository or download the script:
Or download
git clone https://github.com/daniel-inderos/Code-Generator.git cd Code-Generatormain.pyandrequirements.txtfrom this GitHub repository. - Install Required Python Libraries:
- Open a terminal or command prompt in the project directory.
- Run the following command to install the necessary Python libraries:
pip install -r requirements.txt
- (Optional) Install Ollama:
- If you plan to use local AI models, download and install Ollama from Ollama.com.
- Follow the instructions provided by Ollama after installation to properly set it up.
-
Start the application:
- Open a terminal window.
- Navigate to the directory containing
main.py. - Run
python main.py. - The Code Generator GUI should appear.
-
Choose your AI provider:
- For OpenAI:
- Check the "Use OpenAI" box.
- Enter your OpenAI API Key in the provided field.
- Click "Save API Key".
- For Ollama (local AI):
- Ensure the "Use OpenAI" box is unchecked.
- The "Use Local Models" option should be automatically checked.
- Open a separate terminal and start Ollama with your chosen model:
ollama run <model_name>
- For OpenAI:
-
Select your model:
- Click the "Select Model" button.
- Choose your preferred model from the list.
- Click the "Select" button to confirm.
-
Choose code type:
- Select the desired programming language or code type from the dropdown menu.
-
Generate code:
- In the prompt area labeled "Enter your prompt:", describe the code you want to create.
- Click the "Generate Code" button.
- Wait for the generation process to complete. Progress will be indicated by the progress bar.
-
Save the generated code:
- After generation, the code will appear in the text block with syntax highlighting.
- Click the "Save Code to File" button.
- Choose a file name and location to save the code file.
- Website (HTML/CSS/JS)
- Python
- Java
- C++
- JavaScript
- SQL
- llama3.1
- llama3
- mistral
- gemma2
- mixtral
- codegemma
- codestral
- mistral-nemo
- gpt-4o
- gpt-4o-mini
- The application uses a modern, dark-themed UI for a pleasant user experience.
- Generated code is displayed with syntax highlighting for better readability.
- The application saves your API settings in a
config.jsonfile for convenience. - You can switch between OpenAI and local models at any time.
- If any UI elements are not visible, try resizing the application window.
- For issues with local models, ensure Ollama is properly installed and running with the selected model.
- If you encounter any Python-related errors, verify that all dependencies are correctly installed using the provided
requirements.txtfile. - If the code generation seems stuck, check your internet connection and ensure the chosen AI provider (Ollama or OpenAI) is accessible.
Contributions to improve the Code Generator are welcome! Please feel free to submit pull requests or open issues for bugs and feature requests.