Spaces:
Running
Running
change column names
Browse files
app.py
CHANGED
@@ -52,6 +52,7 @@ example_df = pd.read_csv(file_name)
|
|
52 |
|
53 |
def infer(num_sample):
|
54 |
num_sample = int(num_sample)
|
|
|
55 |
input = np.load("model/kde_white_female.npz", allow_pickle=True)['model'].item()
|
56 |
kde, scaler, cols_names = input['model'], input['scaler'], input['columns']
|
57 |
|
@@ -60,8 +61,9 @@ def infer(num_sample):
|
|
60 |
cov_list = np.array([[f'Synth_{i+1}', 'F', 'White'] for i in range(num_sample)])
|
61 |
new_data = np.concatenate([cov_list, sample], axis=1)
|
62 |
cols=['PTID','Sex','Race','Age']
|
63 |
-
cols.extend(fnmatch.filter(cols_names,'H_*'))
|
64 |
df_kde_synth = pd.DataFrame(new_data, columns=cols)
|
|
|
65 |
df_kde_synth.to_csv(save_name, index=False)
|
66 |
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)
|
67 |
|
|
|
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/kde_white_female.npz", allow_pickle=True)['model'].item()
|
57 |
kde, scaler, cols_names = input['model'], input['scaler'], input['columns']
|
58 |
|
|
|
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([col_dict[i] for i in fnmatch.filter(cols_names,'H_*')])
|
65 |
df_kde_synth = pd.DataFrame(new_data, columns=cols)
|
66 |
+
df_kde_synth['Age'] = round(df_kde_synth['Age'].astype('float'))
|
67 |
df_kde_synth.to_csv(save_name, index=False)
|
68 |
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)
|
69 |
|