wizcodes12 commited on
Commit
6f5f5db
·
verified ·
1 Parent(s): f90bc08

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +212 -3
README.md CHANGED
@@ -1,3 +1,212 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ language:
4
+ - en
5
+ metrics:
6
+ - accuracy
7
+ base_model:
8
+ - google/flan-t5-base
9
+ library_name: transformers
10
+ tags:
11
+ - '#ai'
12
+ - '#codefixing'
13
+ - '#programming'
14
+ - '#syntax'
15
+ - '#gptmodel'
16
+ - '#gpt'
17
+ - '#free'
18
+ - '#multilanguage'
19
+ - '#latest'
20
+ ---
21
+ # SnaxFix: Advanced Syntax Error Fixer
22
+
23
+ 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](https://huggingface.co/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](https://huggingface.co/wizcodes12/snaxfix-model).
24
+
25
+ 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.
26
+
27
+ [![Gradio app](https://img.shields.io/badge/%F0%9F%91%BB%20Demo-Gradio-000?logo=gradio&logoColor=white&style=flat-square)](https://huggingface.co/spaces/wizcodes/snaxfix-app)
28
+
29
+ ## Features
30
+
31
+ - **Multi-Language Support**: Fix syntax errors in Python, JavaScript, Java, C, C++, C#, Rust, PHP, HTML, CSS, and SQL.
32
+ - **Interactive Interface**: Built with Gradio, featuring a clean UI with code input/output, language selection, and history tracking.
33
+ - **Example Snippets**: Load pre-defined broken code examples for each supported language to test the model.
34
+ - **History Tracking**: View a history of all fixes performed during a session.
35
+ - **Syntax Highlighting**: Code input and output areas support syntax highlighting for better readability.
36
+ - **Responsive Design**: The Gradio interface is styled with a modern theme for an enhanced user experience.
37
+
38
+ ## Installation
39
+
40
+ To run the SnaxFix application locally or in a Hugging Face Space, follow these steps:
41
+
42
+ ### Prerequisites
43
+ - Python 3.8+
44
+ - A compatible GPU (optional but recommended for faster inference)
45
+ - Git (for cloning the repository)
46
+
47
+ ### Steps
48
+ 1. **Clone the Repository** (if applicable):
49
+ ```bash
50
+ git clone https://github.com/wizcodes12/snaxfix-model.git
51
+ cd snaxfix-model
52
+ ```
53
+
54
+ 2. **Install Dependencies**:
55
+ Create a virtual environment and install the required packages:
56
+ ```bash
57
+ python -m venv venv
58
+ source venv/bin/activate # On Windows: venv\Scripts\activate
59
+ pip install -r requirements.txt
60
+ ```
61
+
62
+ 3. **Run the Application**:
63
+ Start the Gradio app:
64
+ ```bash
65
+ python app.py
66
+ ```
67
+
68
+ This will launch a web interface accessible at `http://localhost:7860` (or another port if specified).
69
+
70
+ ## Usage
71
+
72
+ 1. **Select a Language**: Choose a programming language from the dropdown menu (e.g., Python, JavaScript).
73
+ 2. **Enter Code**: Input code with syntax errors in the code editor. The editor supports syntax highlighting for the selected language.
74
+ 3. **Fix Syntax**: Click the "Fix Syntax" button to process the code and view the corrected version in the output editor.
75
+ 4. **Load Example**: Click the "Load Example" button to populate the input editor with a sample broken code snippet for the selected language.
76
+ 5. **Clear Input**: Use the "Clear Input" button to reset the input editor.
77
+ 6. **View History**: Expand the "History of Fixes" accordion to see a log of all fixes, including timestamps, input code, and corrected code.
78
+ 7. **Clear History**: Click the "Clear History" button to reset the fix history.
79
+ 8. **Learn More**: Expand the "About & License" accordion to view information about the project and its MIT License.
80
+
81
+ ## Example
82
+
83
+ Below is a Python script demonstrating how to use the `wizcodes12/snaxfix-model` to fix syntax errors programmatically:
84
+
85
+ ```python
86
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
87
+
88
+ # Model configuration
89
+ model_id = "wizcodes12/snaxfix-model"
90
+
91
+ print("📦 Loading model...")
92
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
93
+ model = AutoModelForSeq2SeqLM.from_pretrained(model_id)
94
+
95
+ # Prepare input
96
+ language = "python"
97
+ broken_code = "def hello()\n print('hi')"
98
+ input_text = f"<{language.upper()}> Fix the syntax errors in this {language} code: {broken_code}"
99
+
100
+ # Run inference
101
+ inputs = tokenizer(input_text, return_tensors="pt", truncation=True, max_length=512)
102
+
103
+ print("⚙️ Generating fix...")
104
+ outputs = model.generate(
105
+ **inputs,
106
+ max_length=512,
107
+ num_beams=4,
108
+ early_stopping=True,
109
+ temperature=0.7,
110
+ pad_token_id=tokenizer.pad_token_id,
111
+ use_cache=True
112
+ )
113
+
114
+ # Show results
115
+ fixed_code = tokenizer.decode(outputs[0], skip_special_tokens=True)
116
+
117
+ print("\n🧪 Input:")
118
+ print(input_text)
119
+
120
+ print("\n✅ Fixed:")
121
+ print(fixed_code)
122
+ ```
123
+
124
+ **Expected Output**:
125
+ ```
126
+ 📦 Loading model...
127
+ ⚙️ Generating fix...
128
+
129
+ 🧪 Input:
130
+ <PYTHON> Fix the syntax errors in this python code: def hello()
131
+ print('hi')
132
+
133
+ ✅ Fixed:
134
+ def hello():
135
+ print('hi')
136
+ ```
137
+
138
+ 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.
139
+
140
+ ## Requirements
141
+
142
+ The `requirements.txt` file includes the following dependencies:
143
+ ```
144
+ gradio==4.44.0
145
+ transformers==4.30.2
146
+ torch==2.0.1
147
+ sentencepiece==0.1.99
148
+ ```
149
+
150
+ These versions are pinned to ensure compatibility with the model and Gradio interface.
151
+
152
+ ## Model Details
153
+
154
+ - **Model Name**: `wizcodes12/snaxfix-model`
155
+ - **Base Model**: `google/flan-t5-base`
156
+ - **Training Data**: 15,000 synthetic examples of broken and correct code across 11 programming languages, generated using custom error patterns.
157
+ - **Supported Languages**: Python, JavaScript, Java, C, C++, C#, Rust, PHP, HTML, CSS, SQL
158
+ - **Max Input Length**: 512 tokens
159
+ - **Training Environment**: Optimized for Kaggle with mixed precision training and memory management
160
+
161
+ 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.
162
+
163
+ ## Hosting on Hugging Face Spaces
164
+
165
+ To deploy this application on a Hugging Face Space:
166
+ 1. Create a new Space on [Hugging Face](https://huggingface.co/spaces).
167
+ 2. Upload the following files:
168
+ - `app.py`
169
+ - `requirements.txt`
170
+ - `README.md` (optional, for documentation)
171
+ 3. Ensure the Space uses a Python environment with GPU support (if available).
172
+ 4. The Space will automatically install dependencies from `requirements.txt` and run `app.py`.
173
+
174
+ ## Contributing
175
+
176
+ Contributions are welcome! Please open an issue or pull request on the [GitHub repository](https://github.com/wizcodes12/snaxfix-model) for bug reports, feature requests, or improvements.
177
+
178
+ ## License
179
+
180
+ This project is licensed under the MIT License. See the [LICENSE](https://github.com/wizcodes12/snaxfix-model/blob/main/LICENSE) file for details.
181
+
182
+ ```plaintext
183
+ MIT License
184
+
185
+ Copyright (c) 2025 wizcodes12
186
+
187
+ Permission is hereby granted, free of charge, to any person obtaining a copy
188
+ of this software and associated documentation files (the "Software"), to deal
189
+ in the Software without restriction, including without limitation the rights
190
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
191
+ copies of the Software, and to permit persons to whom the Software is
192
+ furnished to do so, subject to the following conditions:
193
+
194
+ The above copyright notice and this permission notice shall be included in all
195
+ copies or substantial portions of the Software.
196
+
197
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
198
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
199
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
200
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
201
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
202
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
203
+ SOFTWARE.
204
+ ```
205
+
206
+ ## Contact
207
+
208
+ For questions or support, contact [wizcodes12](https://huggingface.co/wizcodes12) or open an issue on the [GitHub repository](https://github.com/wizcodes12/snaxfix-model).
209
+
210
+ ---
211
+
212
+ Happy coding with SnaxFix!