--- language: - code library_name: transformers tags: - code-generation - code-repair - auto-fix - programming - huggingface - gradio - fastapi datasets: - custom model-index: - name: AutoCodeFix-AI results: [] pretty_name: AutoCodeFix AI pipeline_tag: text-generation --- # ๐Ÿง  AutoCodeFix-AI: Transformer-Powered Automatic Code Repair **AutoCodeFix-AI** is an advanced yet lightweight AI system that automatically **detects, explains, and fixes code errors** in Python and C-style languages using transformer-based models such as **StarCoder2** and **CodeT5+**. It provides: - โš™๏ธ A **FastAPI backend** for scalable inference - ๐ŸŽ›๏ธ A **Gradio web demo** for live interaction and testing - ๐Ÿ“š Notebooks for model finetuning and evaluation --- ### ๐Ÿงฉ Key Features โœ… Automated code error detection and correction โœ… Natural-language explanations of fixes โœ… Transformer-based fine-tuning (StarCoder2 / CodeT5+) โœ… Ready-to-use REST API (`FastAPI`) โœ… Interactive Hugging Face demo via `Gradio` โœ… Modular and lightweight (~40 MB project) --- ### ๐Ÿ“ Project Structure ``` autocodefix-ai/ โ”‚ โ”œโ”€โ”€ README.md โ”œโ”€โ”€ requirements.txt โ”œโ”€โ”€ setup.py โ”œโ”€โ”€ LICENSE โ”‚ โ”œโ”€โ”€ data/ โ”‚ โ”œโ”€โ”€ raw/ โ”‚ โ”œโ”€โ”€ processed/ โ”‚ โ””โ”€โ”€ samples/ โ”‚ โ”œโ”€โ”€ notebooks/ โ”‚ โ”œโ”€โ”€ 01_data_exploration.ipynb โ”‚ โ”œโ”€โ”€ 02_preprocessing.ipynb โ”‚ โ”œโ”€โ”€ 03_model_finetuning.ipynb โ”‚ โ”œโ”€โ”€ 04_evaluation.ipynb โ”‚ โ””โ”€โ”€ 05_inference_demo.ipynb โ”‚ โ”œโ”€โ”€ src/ โ”‚ โ”œโ”€โ”€ config/ โ”‚ โ”‚ โ”œโ”€โ”€ model_config.yaml โ”‚ โ”‚ โ””โ”€โ”€ training_args.yaml โ”‚ โ”œโ”€โ”€ data/ โ”‚ โ”‚ โ”œโ”€โ”€ data_loader.py โ”‚ โ”‚ โ””โ”€โ”€ preprocessing.py โ”‚ โ”œโ”€โ”€ model/ โ”‚ โ”‚ โ”œโ”€โ”€ model_builder.py โ”‚ โ”‚ โ”œโ”€โ”€ train_model.py โ”‚ โ”‚ โ”œโ”€โ”€ evaluate_model.py โ”‚ โ”‚ โ””โ”€โ”€ inference.py โ”‚ โ”œโ”€โ”€ utils/ โ”‚ โ”‚ โ”œโ”€โ”€ logger.py โ”‚ โ”‚ โ”œโ”€โ”€ metrics.py โ”‚ โ”‚ โ””โ”€โ”€ helper.py โ”‚ โ””โ”€โ”€ app/ โ”‚ โ”œโ”€โ”€ main.py # FastAPI backend โ”‚ โ””โ”€โ”€ gradio_demo.py # Local Gradio UI โ”‚ โ”œโ”€โ”€ deployment/ โ”‚ โ”œโ”€โ”€ Dockerfile โ”‚ โ”œโ”€โ”€ api_service.py โ”‚ โ”œโ”€โ”€ gradio_service.py โ”‚ โ””โ”€โ”€ huggingface_spaces/ โ”‚ โ””โ”€โ”€ app.py โ”‚ โ””โ”€โ”€ tests/ โ”œโ”€โ”€ test_data.py โ”œโ”€โ”€ test_model.py โ”œโ”€โ”€ test_inference.py โ””โ”€โ”€ test_api.py ``` --- ### โš™๏ธ Installation ```bash git clone https://huggingface.co/spaces/hmnshudhmn24/autocodefix-ai cd autocodefix-ai pip install -r requirements.txt ``` --- ### ๐Ÿง  Model Support | Model | Task | Source | |-------|------|--------| | ๐Ÿช **StarCoder2** | Code completion & repair | [Hugging Face](https://huggingface.co/bigcode/starcoder2) | | โš™๏ธ **CodeT5+** | Code understanding & generation | [Hugging Face](https://huggingface.co/Salesforce/codet5p) | Models and configurations are defined in: ``` src/config/model_config.yaml src/config/training_args.yaml ``` --- ### ๐Ÿงฉ Usage #### ๐Ÿ”น Run the FastAPI Backend ```bash uvicorn src.app.main:app --reload ``` Access it at: [http://localhost:8000/docs](http://localhost:8000/docs) #### ๐Ÿ”น Launch Gradio Web Demo ```bash python deployment/huggingface_spaces/app.py ``` Then open the local or Hugging Face demo URL. --- ### ๐Ÿงช Example API Request ```bash curl -X POST "http://localhost:8000/fix" -H "Content-Type: application/json" -d '{"code": "def add(a,b) return a+b"}' ``` **Response:** ```json { "fixed_code": "def add(a, b): return a + b", "explanation": "Added missing colon and indentation." } ``` --- ### ๐Ÿ“Š Training & Evaluation 1. **Data Exploration:** `notebooks/01_data_exploration.ipynb` 2. **Preprocessing:** `notebooks/02_preprocessing.ipynb` 3. **Model Finetuning:** `notebooks/03_model_finetuning.ipynb` 4. **Evaluation:** `notebooks/04_evaluation.ipynb` 5. **Inference Demo:** `notebooks/05_inference_demo.ipynb` All experiment outputs are stored under: ``` experiments/logs/ experiments/checkpoints/ experiments/results/ ```