Skip to content

Commit

Permalink
feat: streamlit app for ydata-synthetic (#236)
Browse files Browse the repository at this point in the history
* feat: improve example streamlit app to serve as the package interface

* chore: remove from the examples as now it is a feature

* feat: add input path to save model and save synthetic data samples

* docs: add new streamlit example and update readme

* docs: update readme with a video

* fix: udapte the setup file and readme

* fix: fix typo

* fix: remove comments

* fix: codacy code quality issues
  • Loading branch information
fabclmnt authored Feb 28, 2023
1 parent d43b5f3 commit 1618ae1
Show file tree
Hide file tree
Showing 22 changed files with 387 additions and 168 deletions.
49 changes: 45 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ Join us on [![Discord](https://img.shields.io/badge/Discord-7289DA?style=for-the

# YData Synthetic
A package to generate synthetic tabular and time-series data leveraging the state of the art generative models.

## 🎊 We have **big news**: v1.0.0 is here
> We have exciting news for you. The new version of `ydata-synthetic` include new and exciting features:
> - A conditional architecture for tabular data: CTGAN, which will make the process of synthetic data generation easier and with higher quality!
> - A new streamlit app that delivers the synthetic data generation experience with a UI interface
## Synthetic data
### What is synthetic data?
Synthetic data is artificially generated data that is not collected from real world events. It replicates the statistical components of real data without containing any identifiable information, ensuring individuals' privacy.
Expand All @@ -27,19 +33,54 @@ This repository contains material related with Generative Adversarial Networks f
It consists a set of different GANs architectures developed using Tensorflow 2.0. Several example Jupyter Notebooks and Python scripts are included, to show how to use the different architectures.

## Quickstart

The source code is currently hosted on GitHub at: https://github.com/ydataai/ydata-synthetic

Binary installers for the latest released version are available at the [Python Package Index (PyPI).](https://pypi.org/project/ydata-synthetic/)
```
```commandline
pip install ydata-synthetic
```

### The UI guide for synthetic data generation

YData synthetic has now a UI interface to guide you through the steps and inputs to generate structure tabular data.
The streamlit app is available form *v1.0.0* onwards, and supports the following flows:
- Train a synthesizer model
- Generate & profile synthetic data samples

#### Installation

```commandline
pip install ydata-syntehtic[streamlit]
```
#### Quickstart
Use the code snippet below in a python file (Jupyter Notebooks are not supported):
```python
from ydata_synthetic import streamlit_app

streamlit_app.run()
```

Or use the file streamlit_app.py that can be found in the [examples folder](https://github.com/ydataai/ydata-synthetic/tree/master/examples/streamlit_app.py).

```commandline
python -m streamlit_app
```

The below models are supported:
- CGAN
- WGAN
- WGANGP
- DRAGAN
- CRAMER
- CTGAN

[![Watch the video](assets/streamlit_app.png)](https://youtu.be/ep0PhwsFx0A)

### Examples
Here you can find usage examples of the package and models to synthesize tabular data.
- Synthesizing the minority class with VanillaGAN on credit fraud dataset [![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/ydataai/ydata-synthetic/blob/master/examples/regular/gan_example.ipynb)
- Time Series synthetic data generation with TimeGAN on stock dataset [![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/ydataai/ydata-synthetic/blob/master/examples/timeseries/TimeGAN_Synthetic_stock_data.ipynb)
- More examples are continously added and can be found in `/examples` directory.
- More examples are continuously added and can be found in `/examples` directory.

### Datasets for you to experiment
Here are some example datasets for you to try with the synthesizers:
Expand All @@ -51,7 +92,6 @@ Here are some example datasets for you to try with the synthesizers:
#### Sequential datasets
- [Stock data](https://github.com/ydataai/ydata-synthetic/tree/master/data)


## Project Resources

In this repository you can find the several GAN architectures that are used to create synthesizers:
Expand All @@ -64,6 +104,7 @@ In this repository you can find the several GAN architectures that are used to c
- [DRAGAN (On Convergence and stability of GANS)](https://arxiv.org/pdf/1705.07215.pdf)
- [Cramer GAN (The Cramer Distance as a Solution to Biased Wasserstein Gradients)](https://arxiv.org/abs/1705.10743)
- [CWGAN-GP (Conditional Wassertein GAN with Gradient Penalty)](https://cameronfabbri.github.io/papers/conditionalWGAN.pdf)
- [CTGAN (Conditional Tabular GAN)](https://arxiv.org/pdf/1907.00503.pdf)

### Sequential data
- [TimeGAN](https://papers.nips.cc/paper/2019/file/c9efe5f26cd17ba6216bbe2a7d26d490-Paper.pdf)
Expand Down
Binary file added assets/streamlit_app.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 0 additions & 5 deletions examples/regular/streamlit app/.streamlit/config.toml

This file was deleted.

23 changes: 0 additions & 23 deletions examples/regular/streamlit app/README.md

This file was deleted.

15 changes: 0 additions & 15 deletions examples/regular/streamlit app/YData_logo.svg

This file was deleted.

Binary file removed examples/regular/streamlit app/app.JPG
Binary file not shown.
Binary file removed examples/regular/streamlit app/app.gif
Binary file not shown.
113 changes: 0 additions & 113 deletions examples/regular/streamlit app/app.py

This file was deleted.

6 changes: 0 additions & 6 deletions examples/regular/streamlit app/requirements.txt

This file was deleted.

7 changes: 7 additions & 0 deletions examples/streamlit_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""
Python file example with the script to run ydata-synthetic streamlit app
"""
from ydata_synthetic import streamlit_app

if __name__ == '__main__':
streamlit_app.run()
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ easydict==1.10
pmlb==1.0.*
tqdm<5.0
typeguard==2.13.*
pytest==6.2.*
pytest==6.2.*
11 changes: 10 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,13 @@
package_dir={'':'src'},
include_package_data=True,
options={"bdist_wheel": {"universal": True}},
install_requires=requirements)
install_requires=requirements,
extras_require={
"streamlit": [
"streamlit==0.18.1",
"typing-extensions==3.10.0",
"streamlit_pandas_profiling==0.1.3",
"ydata-profiling==4.0.0"
],
},
)
3 changes: 3 additions & 0 deletions src/ydata_synthetic/streamlit_app/.streamlit/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[theme]
base="light"
primaryColor="#e32212"
83 changes: 83 additions & 0 deletions src/ydata_synthetic/streamlit_app/About.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
"""
ydata-synthetic streamlit app landing page
"""
import streamlit as st

def main():
st.set_page_config(
page_title="YData Synthetic - Synthetic data generation streamlit_app",
page_icon="👋",
layout="wide"
)
col1, col2 = st.columns([2, 4])

with col1:
st.image("https://assets.ydata.ai/oss/ydata-synthetic-_red.png", width=200)

with col2:
st.title("Welcome to YData Synthetic!")
st.text("Your application for synthetic data generation!")

st.markdown('[ydata-synthetic](https://github.com/ydataai/ydata-synthetic) is an open-source library and is used to generate synthetic data mimicking the real world data.')
st.header('What is synthetic data?')
st.markdown('Synthetic data is artificially generated data that is not collected from real-world events. It replicates the statistical components of real data containing no identifiable information, ensuring an individual’s privacy.')
st.header('Why Synthetic Data?')
st.markdown('''
Synthetic data can be used for many applications:
- Privacy
- Remove bias
- Balance datasets
- Augment datasets''')

# read the instructions in x/
st.markdown('This *streamlit_app* application can generate synthetic data for your dataset. '
'Please read all the instructions in the sidebar before you start the process.')

# read the instructions in x/
st.subheader('Select & train a synthesizer')
#Add here the example text for the end users

st.markdown('''
`ydata-synthetic` streamlit app enables the training and generation of synthetic data from generative architectures.
The current app only provides support for the generation tabular data and for the following architectures:
- GAN
- WGAN
- WGANGP
- CTGAN
''')

#best practives for synthetic data generation
st.markdown('''
##### What you should ensure before training the synthesizer:
- Make sure your dataset has no missing data.
- If missing data is a problem, no worries. Check the article and this article.
- Make sure you choose the right number of epochs and batch_size considering your dataset shape.
- The choice of these 2 parameters highly affects the results you may get.
- Make sure that you've the right data types selected.
- Only numerical and categorical values are supported.
- In case date , datetime, or text is available in the dataset, the columns should be preprocessed before the model training.''')

st.markdown('The trained synthesizer is saved to `*.trained_synth.pkl*` by default.')

st.subheader('Generate & compare synthetic samples')

st.markdown('''
The ydata-synthetic app experience allows you to:
- Generate as many samples as you want based on the provided input
- Generate a profile for the generated synthetic samples
- Save the generated samples to a local directory''')

# guidelines for sampling and
st.markdown('''
##### What you should ensure before generating synthetic samples:
- If no model file path is provided, the default location `.trained_synth.pkl` is assumed.
- Always choose the correct type of data, that corresponds to the trained model in order to avoid loading errors.''')

st.subheader('Coming soon')
st.markdown('''
- Support for time-series models: TimeGAN
- Integrate more advanced settings for CTGAN
- Side-by-side comparison real vs synthetic data sample with `ydata-profiling`''')

if __name__ == '__main__':
main()
3 changes: 3 additions & 0 deletions src/ydata_synthetic/streamlit_app/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from ydata_synthetic.streamlit_app.run import run

##
Loading

0 comments on commit 1618ae1

Please sign in to comment.