Application that implements an API in Python using the FastAPI framework, designed to predict car prices based on their characteristics, such as brand, model, mileage, among others. The machine learning model has been trained with a data set of more than 50,000 cars, allowing it to generate accurate and reliable price estimates.
In addition, the application includes a RAG (Retriever-Augmented Generation) as a virtual assistant, which helps users obtain information about cars and their characteristics in an interactive way. Additionally, it has an authentication system so that administrator users can retrain the model with new data, uploaded via CSV files.
- Price Prediction: The model predicts the price of cars based on characteristics such as make, model, mileage, etc.
- In addition to the estimated price, the API returns a list of related cars, based on the characteristics entered by the user.
- Model Retraining: The system includes an authentication system so that administrators can upload new data via a CSV file, allowing the machine learning model to be retrained with updated information.
- RAG Virtual Assistant: An intelligent assistant that answers questions related to cars and their specifications.
- Fast and Scalable API: Developed with FastAPI, guaranteeing high performance and fast response times.
- TensorFlow: Framework to create and train Machine Learning models, used for car price prediction.
- Scikit-learn: Library for creating statistical and machine learning models, complementing TensorFlow.
- Pandas: Data manipulation library, essential for preprocessing and analyzing data for price prediction.
- NumPy: Numerical computations and efficient management of multidimensional arrays, useful for preparing model input data.
- Langchain: Framework for building applications that integrate Chain-of-Thought (RAG), used in the virtual assistant to provide car-related answers based on data.
- Sentence-transformers: Models to generate vector representations of text, useful for the RAG system that improves assistant responses.
- Ollama: Integration of large language models (LLM) to enhance the virtual assistant's processing capability.
- FastAPI: Framework for building the API quickly and efficiently, with support for automatic documentation generation.
- PyJWT: Authentication based on JWT (JSON Web Tokens), enabling session token generation and validation.
- Passlib (bcrypt): Secure password management, using bcrypt for secure password storage.
- SlowAPI: Rate limiting implementation in the API to prevent abuse and protect resources.
- python-dotenv: Management of environment variables, facilitating secure configuration and credential handling.
- Python-Multipart: Handling file uploads in HTTP requests (e.g., CSV files for model retraining).
- Aiofiles: Asynchronous file reading and writing, improving API performance when handling large files efficiently.
- Requests Validations: Validation of data received in HTTP requests to ensure correct parameters are provided.
- SQLAlchemy: ORM to interact with databases, managing relationships between data in a simple manner.
- PyMySQL: Connector for MySQL databases, used to interact with the application database.
- Pydantic: Validation and management of data through models, ensuring correct input and output.
- Automatic Table Migration: Automatic migrations for all database tables, simplifying schema management.
- Seeders in JSON format: JSON files used to populate the database with initial data.
- File Storage with Pickle: File persistence using the Pickle library to store the model, scalers, encoders, and normalized data.
- ChromaDB with Persistence: ChromaDB has persistence by saving embedding files in storage, allowing data retrieval over time.
- Docker: The application includes files for deployment in Docker, making it easier to containerize and deploy across different environments.
- Websockets for Training Progress: Uses websockets to show real-time training progress of the model.
- Postman Collection: Includes a Postman file with all the endpoints of the API, allowing easy import and testing of application functionalities.
- Enums: Use of Enums in the application to define constant values clearly and simply.
- Exception Handling: A robust exception handling system implemented in the API to ensure appropriate responses in case of errors.
- Python 3.12: The application is developed using Python 3.12, taking advantage of the new features and improvements of the language.
Before running the application, ensure that you have the following installed:
- Python 3.12 - Ensure you have Python version 3.12 installed.
- SQL Database - MySQL or MariaDB is required to store application data.
- Ollama - LLM used for chatbot functionality. You can download it from Ollama's website.
- Llama3 - Another dependency for large language model functionalities.
- GPU (Graphics Card) - For running large language models (LLMs), a compatible GPU is required for optimal performance. Ensure that your system is equipped with a supported GPU and the necessary drivers installed (e.g., CUDA for NVIDIA GPUs).
git clone https://github.com/JAVI-CC/python-api-CarPriceAI.git
cd python-api-CarPriceAI
cp .env.example .env
pip install --no-cache-dir --upgrade -r requirements.txt
pip install --upgrade requests && pip install --upgrade six
fastapi run app/main.py --port 8000 --reload
sed -i '/JWT_SECRET_KEY=""/d' .env.dev && jwt_secret_key="JWT_SECRET_KEY=$(openssl rand -hex 32)" && sed -i -e "11i$jwt_secret_key" .env.dev
python -m app.db.migration
User: [email protected]
Password: Pass-1234
Key | Value |
---|---|
Authorization | {Token provided by JWT} |
Accept | application/json |
Method | Path | Description | Auth |
---|---|---|---|
POST | /auth/login | Login a user | No |
GET | /auth/me | Check if user authenticated | Yes |
Method | Path | Description | Auth |
---|---|---|---|
POST | /cars/train | Train dataset cars | Yes |
POST | /cars/chat/question | Ask and the chatbot answers | No |
POST | /car_prediction | Car prediction price and cars related | No |
GET | /brands | Show all brands | No |
GET | /fuels | Show all fuels | No |
GET | /transmissions | Show all transmissions | No |
GET | /colors | Show all colors | No |
DB_DRIVER=""
DB_HOST=""
DB_PORT=""
DB_DATABASE=""
DB_USERNAME=""
DB_PASSWORD=""
# command generate JWT_SECRET_KEY: openssl rand -hex 32
JWT_SECRET_KEY=""
JWT_ALGORITHM="HS256"
TIMEZONE=""
BASE_URL_OLLAMA="http://localhost:11434"
Docker repository: https://hub.docker.com/r/javi98/python-api-car-price-ai
- nvidia/cuda:11.8.0-cudnn8-devel-ubuntu20.04 -
:8000
- ollama/ollama:0.5.12 -
:11434
- mariadb:11.6.2 -
:3306
- phpmyadmin:5.2.2 -
:8085->80/tcp
βββ python-api-car-price-ai-app βββ python-api-car-price-ai-ollama βββ python-api-car-price-ai-db βββ python-api-car-price-ai-phpmyadmin
git clone https://github.com/JAVI-CC/python-api-CarPriceAI.git
cd python-api-CarPriceAI
cp .env.example .env
docker compose up -d
docker compose exec ollama chmod +x ./docker-config/first_start_ollama.sh
docker compose exec ollama ./first_start_ollma.sh
docker compose exec app chmod +x ./docker-config/run.sh
docker compose exec app ./docker-config/run.sh
Once you have the containers deployed, you can access the API at http://localhost:8000
JAVI-CC - CarPriceAI (2025) License MIT. LICENSE.txt for more details