import sklearn import fnmatch import numpy as np import gradio as gr import pandas as pd description = """ # 🧠 Neuro-Synth M-SYNTH is a synthetic digital mammography (DM) dataset with four breast fibroglandular density distributions imaged using Monte Carlo x-ray simulations with the publicly available [Virtual Imaging Clinical Trial for Regulatory Evaluation (VICTRE)](https://github.com/DIDSR/VICTRE) toolkit. ## Dataset Details The dataset has the following characteristics: * Breast density: dense, heterogeneously dense, scattered, fatty * Mass radius (mm): 5.00, 7.00, 9.00 * Mass density: 1.0, 1.06, 1.1 (ratio of radiodensity of the mass to that of fibroglandular tissue) * Relative dose: 20%, 40%, 60%, 80%, 100% of the clinically recommended dose for each density ## Dataset Download * For Safari users, please right click on the "Download" button below and select "Download Linked File" * Other browser users can directly click on the "Download" button to save the data * Download via command line: ``` wget https://john6688-neuro-synth.hf.space/file=dataset/synth_kde_white_female.csv ``` * You can also customize the number of samples by generating online in the below panels. The synthesized data will be showing in the lower right panel, and then, you can save the data by clicking on the "Download" button. """ citation = """ ## Citation ``` @article{sizikova2023knowledge, title={Knowledge-based in silico models and dataset for the comparative evaluation of mammography AI for a range of breast characteristics, lesion conspicuities and doses}, author={Sizikova, Elena and Saharkhiz, Niloufar and Sharma, Diksha and Lago, Miguel and Sahiner, Berkman and Delfino, Jana G. and Badano, Aldo}, journal={Advances in Neural Information Processing Systems}, volume={}, pages={}, year={2023} } ``` """ file_name = "dataset/synth_kde_white_female.csv" save_name = "dataset/customized_neuro_synth.csv" example_df = pd.read_csv(file_name) def infer(num_sample): num_sample = int(num_sample) input = np.load("model/kde_white_female.npz", allow_pickle=True)['model'].item() kde, scaler, cols_names = input['model'], input['scaler'], input['columns'] sample = kde.sample(num_sample, random_state=0) sample = scaler.inverse_transform(sample) cov_list = np.array([[f'Synth_{i+1}', 'F', 'White'] for i in range(num_sample)]) new_data = np.concatenate([cov_list, sample], axis=1) cols=['PTID','Sex','Race','Age'] cols.extend(fnmatch.filter(cols_names,'H_*')) df_kde_synth = pd.DataFrame(new_data, columns=cols) df_kde_synth.to_csv(save_name, index=False) return gr.Dataframe(df_kde_synth.head(), label='Results (only showing the first few rows)', show_label=True), gr.Button("Download", link="/file="+save_name) with gr.Blocks() as demo: gr.Markdown(description) with gr.Group(): example = gr.Dataframe(example_df.head(), label='Example data (only showing the first five rows, download to check the full table)', show_label=True) gr.Button("Download", link="/file="+file_name) gr.Markdown("## Customized data generation") gr.Interface( fn=infer, inputs= [gr.Textbox( label='Generate samples', show_label=True, placeholder='Enter sample number (in integer)...' )], #title='Customized data generation', outputs=["dataframe", "button"], #description='', cache_examples=False ) gr.Markdown(citation) if __name__ == "__main__": demo.launch(debug=True, allowed_paths=["dataset/"])