SnaxFix: Advanced Syntax Error Fixer
SnaxFix is an AI-powered tool designed to automatically fix syntax errors in code across multiple programming languages. Built on top of the google/flan-t5-base
model and fine-tuned by wizcodes12, this tool supports 11 programming languages: Python, JavaScript, Java, C, C++, C#, Rust, PHP, HTML, CSS, and SQL. The model is hosted on Hugging Face at wizcodes12/snaxfix-model.
This repository contains a Gradio-based web application for interactively testing the syntax error fixing capabilities of the model. The application is designed to run in a Hugging Face Space or locally, providing a user-friendly interface with features like syntax highlighting, language selection, example code loading, and history tracking.
Features
- Multi-Language Support: Fix syntax errors in Python, JavaScript, Java, C, C++, C#, Rust, PHP, HTML, CSS, and SQL.
- Interactive Interface: Built with Gradio, featuring a clean UI with code input/output, language selection, and history tracking.
- Example Snippets: Load pre-defined broken code examples for each supported language to test the model.
- History Tracking: View a history of all fixes performed during a session.
- Syntax Highlighting: Code input and output areas support syntax highlighting for better readability.
- Responsive Design: The Gradio interface is styled with a modern theme for an enhanced user experience.
Installation
To run the SnaxFix application locally or in a Hugging Face Space, follow these steps:
Prerequisites
- Python 3.8+
- A compatible GPU (optional but recommended for faster inference)
- Git (for cloning the repository)
Steps
Clone the Repository (if applicable):
git clone https://github.com/wizcodes12/snaxfix-model.git cd snaxfix-model
Install Dependencies: Create a virtual environment and install the required packages:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate pip install -r requirements.txt
Run the Application: Start the Gradio app:
python app.py
This will launch a web interface accessible at
http://localhost:7860
(or another port if specified).
Usage
- Select a Language: Choose a programming language from the dropdown menu (e.g., Python, JavaScript).
- Enter Code: Input code with syntax errors in the code editor. The editor supports syntax highlighting for the selected language.
- Fix Syntax: Click the "Fix Syntax" button to process the code and view the corrected version in the output editor.
- Load Example: Click the "Load Example" button to populate the input editor with a sample broken code snippet for the selected language.
- Clear Input: Use the "Clear Input" button to reset the input editor.
- View History: Expand the "History of Fixes" accordion to see a log of all fixes, including timestamps, input code, and corrected code.
- Clear History: Click the "Clear History" button to reset the fix history.
- Learn More: Expand the "About & License" accordion to view information about the project and its MIT License.
Example
Below is a Python script demonstrating how to use the wizcodes12/snaxfix-model
to fix syntax errors programmatically:
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
# Model configuration
model_id = "wizcodes12/snaxfix-model"
print("๐ฆ Loading model...")
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForSeq2SeqLM.from_pretrained(model_id)
# Prepare input
language = "python"
broken_code = "def hello()\n print('hi')"
input_text = f"<{language.upper()}> Fix the syntax errors in this {language} code: {broken_code}"
# Run inference
inputs = tokenizer(input_text, return_tensors="pt", truncation=True, max_length=512)
print("โ๏ธ Generating fix...")
outputs = model.generate(
**inputs,
max_length=512,
num_beams=4,
early_stopping=True,
temperature=0.7,
pad_token_id=tokenizer.pad_token_id,
use_cache=True
)
# Show results
fixed_code = tokenizer.decode(outputs[0], skip_special_tokens=True)
print("\n๐งช Input:")
print(input_text)
print("\nโ
Fixed:")
print(fixed_code)
Expected Output:
๐ฆ Loading model...
โ๏ธ Generating fix...
๐งช Input:
<PYTHON> Fix the syntax errors in this python code: def hello()
print('hi')
โ
Fixed:
def hello():
print('hi')
This script loads the model, prepares an input with a syntax error (missing colon in a Python function definition), and generates the corrected code. The model expects input in the format <LANGUAGE> Fix the syntax errors in this <language> code: <broken_code>
. Adjust the language
and broken_code
variables to test other languages and errors.
Requirements
The requirements.txt
file includes the following dependencies:
gradio==4.44.0
transformers==4.30.2
torch==2.0.1
sentencepiece==0.1.99
These versions are pinned to ensure compatibility with the model and Gradio interface.
Model Details
- Model Name:
wizcodes12/snaxfix-model
- Base Model:
google/flan-t5-base
- Training Data: 15,000 synthetic examples of broken and correct code across 11 programming languages, generated using custom error patterns.
- Supported Languages: Python, JavaScript, Java, C, C++, C#, Rust, PHP, HTML, CSS, SQL
- Max Input Length: 512 tokens
- Training Environment: Optimized for Kaggle with mixed precision training and memory management
The model was fine-tuned to recognize and fix common syntax errors, such as missing semicolons, incorrect brackets, wrong keyword cases, and more. It uses special tokens (e.g., <PYTHON>
, <JAVASCRIPT>
) to handle language-specific contexts.
Hosting on Hugging Face Spaces
To deploy this application on a Hugging Face Space:
- Create a new Space on Hugging Face.
- Upload the following files:
app.py
requirements.txt
README.md
(optional, for documentation)
- Ensure the Space uses a Python environment with GPU support (if available).
- The Space will automatically install dependencies from
requirements.txt
and runapp.py
.
Contributing
Contributions are welcome! Please open an issue or pull request on the GitHub repository for bug reports, feature requests, or improvements.
License
This project is licensed under the MIT License. See the LICENSE file for details.
MIT License
Copyright (c) 2025 wizcodes12
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Contact
For questions or support, contact wizcodes12 or open an issue on the GitHub repository.
Happy coding with SnaxFix!
- Downloads last month
- 15
Model tree for wizcodes12/snaxfix-model
Base model
google/flan-t5-base