Skip to content

erlandrivero/PythonApp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🐍 Python Code Generator

A production-ready Streamlit application that generates Python code using Together AI's language models.

🌟 Features

  • Multiple AI Models: Choose from Llama 3.1, CodeLlama, and Mixtral models
  • Advanced Controls: Fine-tune temperature and token limits
  • Example Prompts: 8 pre-built prompts for quick testing
  • Code Download: One-click download of generated code
  • Professional UI: Clean, responsive interface with syntax highlighting
  • Session Management: Maintains state between interactions

🚀 Quick Start

Prerequisites

  1. Together AI API Key - Get it here
  2. Python 3.8+ installed
  3. Git (for deployment)

Local Development

  1. Clone or download this repository

  2. Install dependencies

    pip install -r requirements.txt
  3. Set up environment variable

    # Windows (PowerShell)
    $env:TOGETHER_API_KEY="your_api_key_here"
    
    # Windows (CMD)
    set TOGETHER_API_KEY=your_api_key_here
    
    # Linux/Mac
    export TOGETHER_API_KEY=your_api_key_here
  4. Run the application

    streamlit run app.py
  5. Open in browser - Navigate to http://localhost:8501

📦 Deployment to Streamlit Cloud

Step 1: Upload to GitHub

  1. Create a new GitHub repository
  2. Upload the following files:
    • app.py
    • requirements.txt
    • README.md
    • .gitignore

Step 2: Deploy on Streamlit Cloud

  1. Go to share.streamlit.io
  2. Sign in with GitHub
  3. Click "New app"
  4. Configure:
    • Repository: Your GitHub repository
    • Branch: main
    • Main file: app.py
  5. Click "Advanced settings"
  6. In Secrets, add:
    TOGETHER_API_KEY = "your_api_key_here"
  7. Click "Deploy!"

Your app will be live in 2-3 minutes! 🎉

🎯 Usage

  1. Select a Model - Choose from the sidebar (Llama, CodeLlama, or Mixtral)
  2. Adjust Settings (Optional) - Fine-tune temperature and max tokens
  3. Enter a Prompt - Describe the code you want to generate
  4. Generate Code - Click the generate button
  5. Download - Save the generated code to a .py file

Example Prompts

  • "Write a function to reverse a string"
  • "Create a class for a binary search tree with insert and search methods"
  • "Write a script to read a CSV file and calculate statistics"
  • "Create a decorator for timing function execution"
  • "Write a function to validate email addresses using regex"

🔧 Configuration

Available Models

Model ID Best For
Llama 3.1 8B meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo Fast responses
Llama 3.1 70B meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo Complex tasks
CodeLlama 34B codellama/CodeLlama-34b-Instruct-hf Code-specialized
Mixtral 8x7B mistralai/Mixtral-8x7B-Instruct-v0.1 Balanced performance

Parameters

  • Temperature (0.0-1.0): Controls creativity
    • Lower = More deterministic
    • Higher = More creative
  • Max Tokens (500-4000): Controls response length

📁 Project Structure

Value App/
├── app.py              # Main Streamlit application
├── requirements.txt    # Python dependencies
├── README.md          # Documentation (this file)
├── .gitignore         # Git ignore rules
└── Research/          # Documentation and reference materials

🔒 Security

  • ✅ API keys via environment variables
  • ✅ No secrets in repository
  • ✅ Streamlit secrets management
  • .gitignore configured

🧪 Testing

Manual Testing

  1. Test basic code generation
  2. Try different models
  3. Adjust parameters
  4. Test example prompts
  5. Verify download functionality

Test Prompts

See the Research/ folder for comprehensive test prompts across various categories:

  • Basic functions
  • Data structures
  • Algorithms
  • File operations
  • Web development
  • OOP concepts

🆘 Troubleshooting

Common Issues

"API key not found"

  • Check environment variable is set correctly
  • For Streamlit Cloud: Verify secrets are configured
  • Ensure key name is exactly TOGETHER_API_KEY

"Module not found"

  • Run pip install -r requirements.txt
  • Check Python version is 3.8+

App won't load

  • Check console for error messages
  • Verify all files are in the same directory
  • Check internet connection (for API calls)

Code generation fails

  • Verify API key is valid
  • Check Together AI service status
  • Try a simpler prompt first

📚 Resources

📄 License

This project is created for educational purposes as part of CAP 4767 Data Mining course.

🎓 Assignment Information

Course: CAP 4767 - Data Mining
Module: 5
Topic: AI Code Generation with Together AI

Requirements Met

  • ✅ Streamlit application deployed
  • ✅ Together AI integration
  • ✅ Clean user interface
  • ✅ API key management via secrets
  • ✅ Complete documentation
  • ✅ GitHub repository

🙏 Acknowledgments


Made with ❤️ for CAP 4767

Last Updated: October 2025

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages