khirodsahoo93's picture
Upload 3 files
af21194 verified
|
raw
history blame
4.26 kB
metadata
title: Python to C++ Code Optimizer
emoji: πŸš€
colorFrom: purple
colorTo: blue
sdk: gradio
sdk_version: 4.44.0
app_file: app.py
pinned: false
license: mit

πŸš€ Python to C++ Code Optimizer

An AI-powered tool that converts Python code to high-performance C++ using GPT-4o and Claude-3.5-Sonnet.

🎯 What It Does

This application takes Python code as input and uses frontier AI models to automatically convert it to optimized C++ code. It then allows you to:

  • Compare the generated C++ code side-by-side with the original Python
  • Execute both versions and compare performance
  • See real-world speedups (typically 10-100x faster)

πŸ” Password Protection

This Space is password-protected. To access:

  1. Username: user
  2. Password: Contact the Space owner for the password

The password helps limit access while keeping the Space publicly discoverable.

⚠️ Security Warning

IMPORTANT: This application executes arbitrary code (both Python and C++).

  • Only run code from trusted sources
  • Malicious code can harm the system
  • Use at your own risk
  • Not recommended for production use without proper sandboxing

πŸ”§ Setup Instructions

For Hugging Face Spaces

  1. Fork or duplicate this Space
  2. Go to Settings β†’ Repository secrets
  3. Add the following secrets:

For Local Development

  1. Clone the repository
  2. Install dependencies:
    pip install -r requirements.txt
    
  3. Set environment variables:
    export OPENAI_API_KEY="your-openai-key"
    export ANTHROPIC_API_KEY="your-anthropic-key"
    
  4. Run the app:
    python app.py
    

For C++ Compilation

The app requires a C++ compiler:

  • Linux: g++ (usually pre-installed)
  • macOS: Install Xcode Command Line Tools
  • Windows: Install MinGW or use WSL

The default compilation command uses g++. You may need to adjust the compiler flags in app.py for your platform.

πŸŽ“ Educational Use

This project is designed for educational purposes to demonstrate:

  • AI-powered code generation and optimization
  • Performance differences between Python and C++
  • Real-time streaming from AI models
  • Interactive code execution environments

πŸ“Š Example Performance

Pi Calculation (100M iterations):

  • Python: ~6.3 seconds
  • C++ (optimized): ~0.6 seconds
  • Speedup: ~10x

Maximum Subarray (10K elements, 20 runs):

  • Python: ~45 seconds
  • C++ (optimized): ~0.4 seconds
  • Speedup: ~110x

πŸ›‘οΈ Safety Features

  • Execution timeouts (30 seconds)
  • Error handling for compilation failures
  • Clear security warnings in UI
  • Sandboxed execution recommended for production

πŸ“ Model Options

Choose between two frontier models:

  1. GPT-4o (OpenAI)

    • Excellent at code generation
    • Good optimization strategies
    • Fast streaming responses
  2. Claude-3.5-Sonnet (Anthropic)

    • Strong code understanding
    • Detailed optimization
    • High-quality output

πŸ’° Cost Considerations

Both models are paid APIs:

  • GPT-4o: ~$5 per million input tokens
  • Claude-3.5-Sonnet: ~$3 per million input tokens

For ultra-low cost, modify the code to use:

  • gpt-4o-mini (20x cheaper)
  • claude-3-haiku (15x cheaper)

🀝 Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Submit a pull request

πŸ“„ License

MIT License - feel free to use and modify as needed.

⚑ Credits

Created as part of an LLM Engineering course demonstrating practical applications of frontier AI models.

πŸ”— Resources


Disclaimer: This tool is for educational and research purposes. Always review generated code before using in production. The developers assume no liability for damages caused by code execution.