The Synthetic Data Generation API Project provides an API for generating synthetic tabular data. It offers functionalities for training generative models (CT-GAN and T-VAE), performing inference, and reporting bugs. This README provides detailed documentation of the backend methods used for API key security and CORS configuration.
To start the Synthetic Data Generation API Project, follow these steps:
- Clone the Repository: Clone the project repository from GitHub using the following command: https://github.com/M-ballabio1/syntethic-data-backend.git
- Install Dependencies: Navigate to the project directory and install the required dependencies using pip: cd synthetic-data-api | pip install -r requirements.txt
- Set Environment Variables: Set the required environment variables, including the API key (
API_KEY
), if necessary. - Run the Application: Start the FastAPI application by running the following command: uvicorn main:app --reload
- Access the API: Once the application is running, you can access the API endpoints at the specified URLs.
The API implements API key security to restrict access to authorized users. Here's how it works:
- API Key Management: The API key is stored securely as an environment variable (
API_KEY
). It is loaded into the application at startup. - Authentication: Each API request must include an API key for authentication. The API compares the provided API key with the stored key to verify the user's identity.
- Unauthorized Access Handling: If the provided API key does not match the stored key, the API returns a
401 Unauthorized
error, indicating unauthorized access.
Cross-Origin Resource Sharing (CORS) is configured to allow secure communication between the frontend and backend of the application. Here's how CORS is configured:
- Middleware Integration: The FastAPI framework provides a middleware for CORS handling (
CORSMiddleware
). It is added to the application to enable CORS support. - Allowed Origins: The API specifies a list of allowed origins from which requests can originate. This prevents unauthorized cross-origin requests.
- Allowed Methods and Headers: The API allows specific HTTP methods and headers in CORS requests. This ensures that only permitted operations are allowed.
- Method: POST
- Description: Initiates the training process for the CTGAN model using the provided training data.
- Security: Requires API key authentication.
- Parameters:
background_tasks
: BackgroundTasks object for executing tasks in the background.epochs
: Number of epochs for CTGAN model training.file_training_data
: File containing the training data.api_key
: API key for authentication.
- Response: Returns a confirmation of the successful initiation of the training process.
- Method: POST
- Description: Performs inference using the CTGAN and TVAE models to generate synthetic data.
- Security: Requires API key authentication.
- Parameters:
model_id
: ID of the model used for inference (CTGAN or TVAE).sample_num
: Number of samples to generate.api_key
: API key for authentication.
- Response: Returns the synthetic data in CSV format.
- Method: POST
- Description: Initiates the training process for the TVAE model using the adult dataset.
- Security: Requires API key authentication.
- Parameters:
background_tasks
: BackgroundTasks object for executing tasks in the background.epochs
: Number of epochs for TVAE model training.api_key
: API key for authentication.
- Response: Returns a confirmation of the successful initiation of the training process.
- Method: POST
- Description: Performs inference using the TVAE model (GPU required) to generate synthetic data.
- Security: Requires API key authentication.
- Parameters:
unique_id
: Unique ID of the TVAE model.num_rows
: Number of synthetic data rows to generate.api_key
: API key for authentication.
- Response: Returns the synthetic data in CSV format.
This project is licensed under the Apache License 2.0. For more details, see the LICENSE file.