A small SaaS-style web app that explains and fixes errors in code. You paste a code snippet and the error it produces, and a chat model deployed on Azure OpenAI explains what went wrong and returns a corrected version. Each visitor gets a few free requests, after which the app asks for a payment through Stripe.
- Paste code and its error message to get a plain explanation of the error and a fixed version of the code.
- Two separate prompts are sent to the model: one explains the error without fixing it, the other returns only the fixed code.
- Usage is tracked per visitor in a local SQLite database (a SHA-256 hash of the IP address and user agent). Each visitor gets four free requests.
- When the free requests are used up, a payment page collects card details with Stripe Elements and charges a fixed fee through a Stripe PaymentIntent. A successful payment resets the visitor's counter, which gives them four more requests.
- Python, Flask, Jinja2 templates
- Azure OpenAI through the
openaiPython SDK - Stripe (Stripe.js on the page,
stripePython library on the server) - SQLite
- HTML, CSS and a little JavaScript
app.py Flask routes, model calls, usage tracking and payment
config.py Reads settings from environment variables or a .env file
templates/ Landing, bug fixer, payment and confirmation pages
static/style.css Page styles
.env.example Example environment variables
requirements.txt Python dependencies
You need Python 3.10 or newer, an Azure OpenAI resource with a chat model deployment, and a Stripe account (test mode is enough).
-
Clone the repository and install the dependencies:
git clone https://github.com/Hamza-Tahirr/Bug-Fixer-Using-Generative-AI.git cd Bug-Fixer-Using-Generative-AI python -m venv venv source venv/bin/activate # on Windows: venv\Scripts\activate pip install -r requirements.txt
-
Copy
.env.exampleto.envand fill in your values:Variable Description AZURE_OPENAI_API_KEYKey of your Azure OpenAI resource AZURE_OPENAI_ENDPOINTEndpoint, for example https://your-resource.openai.azure.com/AZURE_OPENAI_DEPLOYMENTName of your chat model deployment AZURE_OPENAI_API_VERSIONAPI version (defaults to 2024-10-21)STRIPE_SECRET_KEYStripe secret key ( sk_test_...)STRIPE_PUBLISHABLE_KEYStripe publishable key ( pk_test_...) -
Start the app:
python app.py
Then open http://127.0.0.1:5000. Set
FLASK_DEBUG=1to run with the Flask debugger. The SQLite databaseapp.dbis created automatically on first start.
In Stripe test mode you can pay with the card number 4242 4242 4242 4242, any future expiry date and any CVC.
- The price is set by
PRICE_CENTSinapp.py(500, which is $5.00). - The free request limit is checked in the
/homeroute inapp.py.
- Visitors are identified only by IP address and user agent, so the free limit is a simple guard and not real authentication.
- Cards that require extra authentication (3D Secure) are not handled; the payment page shows an error for them.
This project is licensed under the MIT License. See LICENSE.