Spaces:
Running
Running
add sex and race groups
Browse files
app.py
CHANGED
@@ -50,15 +50,15 @@ save_name = "dataset/customized_neuro_synth.csv"
|
|
50 |
example_df = pd.read_csv(file_name)
|
51 |
|
52 |
|
53 |
-
def infer(num_sample):
|
54 |
num_sample = int(num_sample)
|
55 |
col_dict = np.load("model/col_dict.npz", allow_pickle=True)['dict'].item()
|
56 |
-
input = np.load("model/
|
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}',
|
62 |
new_data = np.concatenate([cov_list, sample], axis=1)
|
63 |
cols=['PTID','Sex','Race','Age']
|
64 |
cols.extend([col_dict[i] for i in fnmatch.filter(cols_names,'H_*')])
|
@@ -79,7 +79,22 @@ with gr.Blocks() as demo:
|
|
79 |
gr.Markdown("## Customized data generation")
|
80 |
gr.Interface(
|
81 |
fn=infer,
|
82 |
-
inputs= [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
label='Generate samples',
|
84 |
show_label=True,
|
85 |
placeholder='Enter sample number (in integer)...'
|
|
|
50 |
example_df = pd.read_csv(file_name)
|
51 |
|
52 |
|
53 |
+
def infer(sex, race, num_sample):
|
54 |
num_sample = int(num_sample)
|
55 |
col_dict = np.load("model/col_dict.npz", allow_pickle=True)['dict'].item()
|
56 |
+
input = np.load("model/kde_{}_{}.npz".format(race.lower(), sex.lower()), allow_pickle=True)['model'].item() # "model/kde_white_female.npz"
|
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}', sex[0], race] for i in range(num_sample)]) # 'F', 'White'
|
62 |
new_data = np.concatenate([cov_list, sample], axis=1)
|
63 |
cols=['PTID','Sex','Race','Age']
|
64 |
cols.extend([col_dict[i] for i in fnmatch.filter(cols_names,'H_*')])
|
|
|
79 |
gr.Markdown("## Customized data generation")
|
80 |
gr.Interface(
|
81 |
fn=infer,
|
82 |
+
inputs= [
|
83 |
+
gr.Radio(
|
84 |
+
choices=['Female', 'Male'],
|
85 |
+
value='Female',
|
86 |
+
type='index',
|
87 |
+
label='Gender',
|
88 |
+
interactive=True,
|
89 |
+
),
|
90 |
+
gr.Radio(
|
91 |
+
choices=['White', 'Black', 'Asian'],
|
92 |
+
value='Asian',
|
93 |
+
type='index',
|
94 |
+
label='Race',
|
95 |
+
interactive=True,
|
96 |
+
),
|
97 |
+
gr.Textbox(
|
98 |
label='Generate samples',
|
99 |
show_label=True,
|
100 |
placeholder='Enter sample number (in integer)...'
|