Skip to content

DearPratipal/python-ai-compiler-engine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

Python AI Compiler Engine

A Multi-Output Python Runner with AI Assistance
© 2025 **Pratipal Kumar Singh

🚀 Overview

This project is a lightweight Python compiler/runner that executes user-provided code in a safe, sandboxed environment and returns structured output.
It also supports saving results as PNG or JPG images, along with optional Gemini-powered AI features such as:

  • Code explanation
  • Error debugging
  • Smart test-case suggestions
  • Code formatting

This system is ideal for internship platforms, coding assessments, training portals, and project-based learning.


🔧 Features

  • Execute Python code safely
  • Capture stdout, stderr, runtime, and exit codes
  • Save output as PNG/JPG using Pillow
  • Download results as .txt
  • Sandbox restrictions: limited resources, isolated execution
  • AI Integration (optional)
    • Error explanation
    • Code enhancement
    • Test-case generation
  • REST API + CLI support
  • Industrial use-case ready

📂 Folder Structure (Suggested)

PYTHON-COMPILER-ENGINE/
├─ README.md
├─ LICENSE
├─ requirements.txt
└─ index.html

🛠️ Installation

Requirements

  • Python 3.10+
  • pip
  • (Optional) Gemini AI API Key

Install dependencies

python -m venv .venv      # Windows: .venv\Scripts\activate
pip install -r requirements.txt

🔐 Environment Variables

Create a .env file:

GEMINI_API_KEY=your_key_here
GEMINI_ENDPOINT=https://api.gemini.example/v1
APP_SECRET_KEY=random_string

Never commit .env to GitHub.


▶️ Usage

🖥️ CLI Example

python run_code.py --file main.py --save-image output.png

🌐 REST API Example

POST /run

{
  "language": "python",
  "source": "print('Hello AI Compiler!')",
  "save_image": true,
  "image_format": "png"
}

🖼️ Output Image Handling

  • Outputs rendered using Pillow
  • Monospaced fonts for clarity
  • Optionally render in HTML and capture screenshot using headless browser

🤖 AI Integration (Optional)

import requests, os

resp = requests.post(
    f"{os.getenv('GEMINI_ENDPOINT')}/v1/assist",
    headers={"Authorization": f"Bearer {os.getenv('GEMINI_API_KEY')}"},
    json={"prompt": "Explain this Python error: ..."}
)

🔒 Security

To safely execute untrusted code:

  • Use Docker/Firecracker sandbox
  • Strict timeouts
  • Disable network
  • Memory and CPU limits
  • Isolate filesystem

🤝 Contributing

  1. Fork repo
  2. Create feature branch
  3. Submit PR
  4. Ensure tests pass

📜 License

Released under the MIT License.
© 2025 Pratipal Kumar Singh — All rights reserved where applicable.


📬 Contact

For queries or collaborations:
Pratipal Kumar Singh
kumarpratipal123@gmail.com

About

A Python-based compiler/runner that executes code securely, generates text and image outputs (PNG/JPG), and integrates optional Gemini-powered AI features for formatting, debugging, and test-case generation. Built for internship training platforms, coding assessments, and industrial service applications. © 2025 Pratipal Kumar Singh.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages