{"id":22843242,"url":"https://github.com/asma-hachaichi/automl-builder","last_synced_at":"2026-05-04T21:32:08.168Z","repository":{"id":253958431,"uuid":"826228501","full_name":"asma-hachaichi/AutoML-Builder","owner":"asma-hachaichi","description":"AutoML-Builder is an API that automates the generation of machine learning models for regression or classification tasks from provided datasets.","archived":false,"fork":false,"pushed_at":"2024-08-30T09:58:45.000Z","size":2638,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-26T11:49:33.281Z","etag":null,"topics":["asyncio","automl","fastapi","h2o","h2o-automl","ngrok","queue-tasks","streamlit","uvicorn"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/asma-hachaichi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-09T10:01:09.000Z","updated_at":"2024-12-16T19:01:42.000Z","dependencies_parsed_at":"2025-02-06T09:33:34.875Z","dependency_job_id":"3cbe6ebf-523b-4d9b-8195-e782ad04a011","html_url":"https://github.com/asma-hachaichi/AutoML-Builder","commit_stats":null,"previous_names":["asma-hachaichi/automl-builder"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/asma-hachaichi/AutoML-Builder","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asma-hachaichi%2FAutoML-Builder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asma-hachaichi%2FAutoML-Builder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asma-hachaichi%2FAutoML-Builder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asma-hachaichi%2FAutoML-Builder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/asma-hachaichi","download_url":"https://codeload.github.com/asma-hachaichi/AutoML-Builder/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asma-hachaichi%2FAutoML-Builder/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32625968,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-04T10:08:07.713Z","status":"ssl_error","status_checked_at":"2026-05-04T10:08:02.005Z","response_time":58,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["asyncio","automl","fastapi","h2o","h2o-automl","ngrok","queue-tasks","streamlit","uvicorn"],"created_at":"2024-12-13T02:13:35.995Z","updated_at":"2026-05-04T21:32:08.153Z","avatar_url":"https://github.com/asma-hachaichi.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AutoML API with Queue Management\n\n## Overview\n\nThis project provides an **AutoML API** built using **H2O.ai** and **FastAPI**.\nThe API supports training models asynchronously, monitors their status, and makes predictions on new data using the trained models.\nThe system employs **queue management** to handle model training requests, ensuring each task is processed in order (FIFO: First-In-First-Out).\nThe interface for interacting with the API is implemented using **Streamlit**.\n\n## Features\n\n- **Model Training**: Accepts a CSV file as input, automatically preprocesses the data, and trains an H2O AutoML model.\n- **Task Queue Management**: Ensures that model training tasks are handled sequentially. Each task is assigned a unique `task_id` and processed in the order they are received.\n- **Monitor Training Status**: Allows users to check the status of their model training task.\n- **Make Predictions**: Once a model has finished training, users can upload new data for predictions.\n\n## Technologies Used\n\n- **H2O.ai**: For automated machine learning model training.\n- **FastAPI**: For building the REST API.\n- **Streamlit**: For the frontend user interface.\n- **Uvicorn**: For ASGI server management.\n- **PyNgrok**: For exposing the FastAPI application to the internet.\n- **Python's `sched` and `asyncio`**: For managing asynchronous tasks in a queue.\n- **Pandas**: For data manipulation.\n- **UUID**: For generating unique task identifiers.\n\n---\n\n## Detailed Explanation\n\n### 1. Queue Management\n\n- **Task Queue**: The backend uses an in-memory queue (`tasks` dictionary) to manage tasks. When a training request is made, it is assigned a unique `task_id` using `uuid.uuid4()`. Each task is added to the queue with an initial status of `waiting`.\n- **Scheduler**: We use Python’s `sched.scheduler` to manage the execution of tasks. Each task is scheduled with a delay of `0`, ensuring that tasks are processed as soon as possible but still maintaining a First-In-First-Out (FIFO) order. The scheduler is run in a separate asyncio task, allowing the main FastAPI thread to handle other requests while tasks are being processed.\n\n- **Asyncio**: The `asyncio.create_task()` function ensures that the task scheduling is non-blocking. This is essential for handling multiple simultaneous API requests without freezing the server.\n\n### 2. Model Training\n\n- **Data Preprocessing**: Before training, the system limits the number of rows in the dataset to `500` to reduce training time. This is done using a simple sampling method (`limit_rows` function).\n\n- **H2O AutoML**: The API uses H2O’s `AutoML` for model training. By default, the system trains models using three algorithms (`GLM`, `GBM`, `XGBoost`). If the performance of the model is unsatisfactory based on predefined metrics (logloss for classification, R² for regression), the system may include Deep Learning models in the training.\n\n- **Model Saving**: Once a model is trained, it is saved, and its path is stored in the task's `model_details` dictionary along with the relevant metrics (`AUC`, `MSE`, `logloss`... ).\n\n### 3. Task Monitoring\n\n- **Monitor Status**: The `monitor_task` endpoint allows the client to check the status of their task using the `task_id`. The task's status is updated as it progresses from `waiting` to `in_progress`, then to `done` or `error`.\n\n### 4. Prediction\n\n- **Prediction API**: Once a model is successfully trained, the user can make predictions by providing the `task_id` and a new CSV file for prediction. The API loads the previously saved model and makes predictions on the new data, returning the results as a JSON response.\n\n![bloc_diagram_stage drawio](https://github.com/user-attachments/assets/8e66dd69-c910-49e3-bb9d-4316567d2db3)\n\n---\n\n## Streamlit Interface\n\n- **Train Model**: In the \"Train Model\" tab, upload a CSV file and click \"Train Model\". The `task_id` will be displayed once training starts.\n- **Monitor Training**: In the \"Monitor Training\" tab, input the `task_id` and click \"Check Status\" to see if your model has finished training.\n- **Make Predictions**: In the \"Make Predictions\" tab, input the `task_id` and upload a CSV file for predictions. The results will be displayed in a table format.\n\n---\n\n## How to Run the Project\n\n### Backend Setup (FastAPI + H2O + Uvicorn)\n\n1. **Install dependencies:**\n   Install the required Python packages by running the following code cell in the notebook autoML_builder.ipynb :\n\n   ```bash\n   !pip install fastapi uvicorn h2o pandas requests python-multipart pyngrok\n   ```\n\n2. **Create an Ngrok Profile:**\n   To use Ngrok for exposing your local server, you need to create an Ngrok account and set up a profile.\n   Once signed up, you'll receive an authentication token. Add this token in the second cell of the notebook :\n\n   ```bash\n   !ngrok authtoken 'YOUR_NGROK_AUTHTOKEN'\n   ```\n\n   This will allow you to create secure tunnels for your FastAPI application.\n\n3. **Run the FastAPI Application:**\n   Instead of running the FastAPI application via a Python file, simply execute the cells of the notebook autoML_builder.ipynb.\n   This notebook contains all the necessary logic for model training, task monitoring, and predictions.\n\n   When the application starts, you will see a public Ngrok URL in the last cell's output:\n\n   ```bash\n   Public URL: https://\u003cyour-ngrok-url\u003e.ngrok-free.app\n   ```\n\n4. **API Endpoints:**\n   - **Train Model**: `POST /train`\n     - Input: CSV file (multipart/form-data)\n     - Output: A unique `task_id` for monitoring the task status.\n   - **Monitor Task**: `GET /monitor/{task_id}`\n     - Input: `task_id` (path parameter)\n     - Output: Task status (waiting, in_progress, done, error) and model metrics if training is complete.\n   - **Make Predictions**: `POST /predict`\n     - Input: `task_id` (form data), CSV file for predictions (multipart/form-data)\n     - Output: JSON predictions for the uploaded dataset.\n\n### Frontend Setup (Streamlit)\n\n1. **Install dependencies for Streamlit**:\n\n   ```bash\n   pip install streamlit\n   ```\n\n2. **Run the Streamlit Interface**:\n   You can run the Streamlit app with the following command:\n\n   ```bash\n   streamlit run app.py\n   ```\n\n   Before running the app, make sure to paste the Ngrok URL obtained from the notebook's cell output into the BASE_URL variable in app.py.\n   This URL will be used to connect the Streamlit frontend to the FastAPI backend.\n\n3. **Interface Tabs**:\n   - **Train Model**: Upload a CSV file to train a new model.\n   - **Monitor Training**: Enter the `task_id` to check the training progress.\n   - **Make Predictions**: After training, use the `task_id` and upload a CSV file for predictions.\n\n---\n\n## Notes\n\n- This implementation uses **in-memory storage for tasks**, which means all task data will be lost when the server restarts.\n- The **queue management** system ensures that model training tasks are handled sequentially.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fasma-hachaichi%2Fautoml-builder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fasma-hachaichi%2Fautoml-builder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fasma-hachaichi%2Fautoml-builder/lists"}