rongguangw commited on
Commit
b4fb2c2
1 Parent(s): 259f537
README.md CHANGED
@@ -1,13 +1,13 @@
1
  ---
2
  title: Neuro Synth
3
- emoji:
4
- colorFrom: yellow
5
- colorTo: green
6
  sdk: gradio
7
- sdk_version: 4.12.0
8
  app_file: app.py
9
  pinned: false
10
  license: mit
11
  ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
  title: Neuro Synth
3
+ emoji: 🧠
4
+ colorFrom: blue
5
+ colorTo: purple
6
  sdk: gradio
7
+ sdk_version: 4.11.0
8
  app_file: app.py
9
  pinned: false
10
  license: mit
11
  ---
12
 
13
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sklearn
2
+ import fnmatch
3
+ import numpy as np
4
+ import gradio as gr
5
+ import pandas as pd
6
+
7
+
8
+ description = """
9
+ # 🧠 Neuro-Synth
10
+
11
+ <!-- Provide a quick summary of the dataset. -->
12
+
13
+ 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.
14
+
15
+ ## Dataset Details
16
+
17
+ The dataset has the following characteristics:
18
+
19
+ * Breast density: dense, heterogeneously dense, scattered, fatty
20
+ * Mass radius (mm): 5.00, 7.00, 9.00
21
+ * Mass density: 1.0, 1.06, 1.1 (ratio of radiodensity of the mass to that of fibroglandular tissue)
22
+ * Relative dose: 20%, 40%, 60%, 80%, 100% of the clinically recommended dose for each density
23
+
24
+ ## Dataset Download
25
+
26
+ * For Safari users, please right click on the "Download" button below and select "Download Linked File"
27
+ * Other browser users can directly click on the "Download" button to save the data
28
+ * Download via command line:
29
+ ```
30
+ wget https://john6688-neuro-synth.hf.space/file=dataset/synth_kde_white_female.csv
31
+ ```
32
+ * 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.
33
+ """
34
+
35
+ citation = """
36
+ ## Citation
37
+ ```
38
+ @article{sizikova2023knowledge,
39
+ 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},
40
+ author={Sizikova, Elena and Saharkhiz, Niloufar and Sharma, Diksha and Lago, Miguel and Sahiner, Berkman and Delfino, Jana G. and Badano, Aldo},
41
+ journal={Advances in Neural Information Processing Systems},
42
+ volume={},
43
+ pages={},
44
+ year={2023}
45
+ }
46
+ ```
47
+ """
48
+
49
+ file_name = "dataset/synth_kde_white_female.csv"
50
+ save_name = "dataset/customized_neuro_synth.csv"
51
+ example_df = pd.read_csv(file_name)
52
+
53
+
54
+ def infer(num_sample):
55
+ num_sample = int(num_sample)
56
+ input = np.load("model/kde_white_female.npz", allow_pickle=True)['model'].item()
57
+ kde, scaler, cols_names = input['model'], input['scaler'], input['columns']
58
+
59
+ sample = kde.sample(num_sample, random_state=0)
60
+ sample = scaler.inverse_transform(sample)
61
+ cov_list = np.array([[f'Synth_{i+1}', 'F', 'White'] for i in range(num_sample)])
62
+ new_data = np.concatenate([cov_list, sample], axis=1)
63
+ cols=['PTID','Sex','Race','Age']
64
+ cols.extend(fnmatch.filter(cols_names,'H_*'))
65
+ df_kde_synth = pd.DataFrame(new_data, columns=cols)
66
+ df_kde_synth.to_csv(save_name, index=False)
67
+ 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)
68
+
69
+ with gr.Blocks() as demo:
70
+ gr.Markdown(description)
71
+
72
+ with gr.Group():
73
+ example = gr.Dataframe(example_df.head(),
74
+ label='Example data (only showing the first five rows, download to check the full table)',
75
+ show_label=True)
76
+ gr.Button("Download", link="/file="+file_name)
77
+
78
+ gr.Markdown("## Customized data generation")
79
+ gr.Interface(
80
+ fn=infer,
81
+ inputs= [gr.Textbox(
82
+ label='Generate samples',
83
+ show_label=True,
84
+ placeholder='Enter sample number (in integer)...'
85
+ )],
86
+ #title='Customized data generation',
87
+ outputs=["dataframe", "button"],
88
+ #description='',
89
+ cache_examples=False
90
+ )
91
+
92
+ gr.Markdown(citation)
93
+
94
+ if __name__ == "__main__":
95
+ demo.launch(debug=True, allowed_paths=["dataset/"])
dataset/synth_kde_white_female.csv ADDED
The diff for this file is too large to render. See raw diff
 
model/kde_white_female.npz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3689a6a15098544e60713ac9325d83ef22470da605985189b3fa72d173856922
3
+ size 133
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ scikit-learn==1.0.2
2
+ pandas
3
+ numpy