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.
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:
python
1from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
23# Model configuration4model_id ="wizcodes12/snaxfix-model"56print("📦 Loading model...")7tokenizer = AutoTokenizer.from_pretrained(model_id)8model = AutoModelForSeq2SeqLM.from_pretrained(model_id)910# Prepare input11language ="python"12broken_code ="def hello()\n print('hi')"13input_text =f"<{language.upper()}> Fix the syntax errors in this {language} code: {broken_code}"1415# Run inference16inputs = tokenizer(input_text, return_tensors="pt", truncation=True, max_length=512)1718print("⚙️ Generating fix...")19outputs = model.generate(20**inputs,21 max_length=512,22 num_beams=4,23 early_stopping=True,24 temperature=0.7,25 pad_token_id=tokenizer.pad_token_id,26 use_cache=True27)2829# Show results30fixed_code = tokenizer.decode(outputs[0], skip_special_tokens=True)3132print("\n🧪 Input:")33print(input_text)3435print("\n✅ Fixed:")36print(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:
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:
Ensure the Space uses a Python environment with GPU support (if available).
The Space will automatically install dependencies from requirements.txt and run app.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.
plaintext
1MIT License
23Copyright (c) 2025 wizcodes12
45Permission is hereby granted, free of charge, to any person obtaining a copy
6of this software and associated documentation files (the "Software"), to deal
7in the Software without restriction, including without limitation the rights
8to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9copies of the Software, and to permit persons to whom the Software is
10furnished to do so, subject to the following conditions:
1112The above copyright notice and this permission notice shall be included in all
13copies or substantial portions of the Software.
1415THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21SOFTWARE.