A powerful AI-powered code generation tool that leverages Google's Gemini AI to generate code from natural language prompts. The application features conversation memory, allowing it to remember and build upon previous instructions for iterative code development.
- AI-Powered Code Generation: Uses Google's Gemini 2.5 Flash Lite model to generate code from natural language descriptions
- Conversational Memory: Maintains conversation history to understand context and handle follow-up instructions
- Interactive Chat Interface: User-friendly chat-based UI built with Streamlit
- Multiple Language Support: Can generate code in various programming languages (Python, JavaScript, HTML, CSS, etc.)
- Code Syntax Highlighting: Automatically displays generated code with proper syntax highlighting
- Iterative Development: Refine and modify code through natural conversation
Before you begin, ensure you have the following installed:
- Python 3.8 or higher
- pip (Python package installer)
- A Google AI API key (Get one at Google AI Studio)
-
Clone the repository
git clone https://github.com/dennisGustavsson/agent-testproject.git cd agent-testproject -
Create a virtual environment (recommended)
python -m venv venv # On Linux/macOS: source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install required dependencies
pip install -r requirements.txt
Or install manually:
pip install streamlit google-generativeai python-dotenv
-
Create a
.envfile in the project root directory:touch .env
-
Add your Google AI API key to the
.envfile:GOOGLE_API_KEY=your_api_key_hereSecurity Note: Never commit your
.envfile to version control. It's already included in.gitignore. -
Alternative: Set the API key as an environment variable:
# On Linux/macOS: export GOOGLE_API_KEY='your_api_key_here' # On Windows: set GOOGLE_API_KEY=your_api_key_here
-
Start the application
streamlit run app.py
-
Access the web interface
- The application will automatically open in your default browser
- If not, navigate to
http://localhost:8501
-
Generate code
- Type your code generation request in the chat input
- Press Enter to submit
- The AI will generate code based on your request
- Continue the conversation to refine or modify the code
Here are some example prompts to get you started:
"Write a Python function to calculate the factorial of a number."
"Now, modify that function to handle negative inputs by raising a ValueError."
"Add type hints and docstrings to the factorial function."
"Generate a simple HTML page with a heading 'My Page' and a paragraph 'Welcome!'."
"Create a JavaScript snippet to change the background color to blue when a button is clicked."
"Refactor the previous JavaScript to use an event listener instead of inline onclick."
"Write a Python function to read a CSV file and calculate the average of a specific column."
"Add error handling for missing files and invalid data."
- Frontend: Streamlit - Python framework for building data apps
- AI Model: Google Gemini 2.5 Flash Lite - Advanced language model for code generation
- Environment Management: python-dotenv - For managing environment variables
- Language: Python 3.8+
agent-testproject/
├── app.py # Main application file
├── INSTRUCTIONS.md # Detailed implementation guide
├── requirements.txt # Python dependencies
├── .env # Environment variables (not tracked)
├── .gitignore # Git ignore rules
└── README.md # This file
- API Keys: Always store API keys in environment variables or
.envfiles, never in source code - Code Review: Always review and test AI-generated code before using it in production
- Rate Limits: Be mindful of API rate limits and costs associated with AI model usage
- Input Validation: The AI may generate code that needs validation and testing
Contributions are welcome! Here's how you can help:
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is open source and available for educational and commercial use.
Issue: "API key not found" error
- Solution: Ensure your
.envfile exists and containsGOOGLE_API_KEY=your_key - Verify the
.envfile is in the same directory asapp.py
Issue: "Module not found" errors
- Solution: Make sure all dependencies are installed:
pip install streamlit google-generativeai python-dotenv
Issue: Streamlit won't start
- Solution: Check if port 8501 is already in use. You can specify a different port:
streamlit run app.py --server.port 8502
- Google AI Documentation
- Streamlit Documentation
- INSTRUCTIONS.md - Detailed implementation guide
Dennis Gustavsson
- Google AI for providing the Gemini API
- Streamlit team for the excellent UI framework
- The AI/ML community for inspiration and best practices