KashyapiNagaHarshitha commited on
Commit
7047e43
·
verified ·
1 Parent(s): 85a1d12

Setup Page

Browse files
Files changed (1) hide show
  1. app0.py +198 -0
app0.py ADDED
@@ -0,0 +1,198 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # coding: utf-8
3
+ import panel as pn
4
+ import os
5
+ import pandas as pd
6
+ import json
7
+ pn.extension()
8
+
9
+ # Global variables to store the input values
10
+ input_path = ""
11
+ set_path = ""
12
+ ls_samples = []
13
+ metadata_files = []
14
+ selected_metadata_files = []
15
+
16
+ # Define a callback to store values when the button is clicked
17
+ def store_values(event):
18
+ global input_path, set_path, ls_samples, metadata_files
19
+ input_path = file_input.value
20
+ set_path = set_name.value
21
+
22
+ # Update the global variables
23
+ global base_dir, input_data_dir, output_data_dir, output_images_dir, metadata_dir, metadata_images_dir
24
+
25
+ base_dir = input_path
26
+ project_name = set_path
27
+ step_suffix = 'qc_eda'
28
+ previous_step_suffix_long = ""
29
+
30
+ input_data_dir = os.path.join(base_dir, project_name + "_data")
31
+ output_data_dir = os.path.join(base_dir, project_name + "_" + step_suffix)
32
+ output_images_dir = os.path.join(output_data_dir, "images")
33
+ metadata_dir = os.path.join(base_dir, project_name + "_metadata")
34
+ metadata_images_dir = os.path.join(metadata_dir, "images")
35
+
36
+ # Create directories if they don't already exist
37
+ for d in [base_dir, input_data_dir, output_data_dir, output_images_dir, metadata_dir, metadata_images_dir]:
38
+ if not os.path.exists(d):
39
+ print(f"Creation of the {d} directory...")
40
+ os.makedirs(d)
41
+ else:
42
+ print(f"The {d} directory already exists!")
43
+
44
+ os.chdir(input_data_dir)
45
+
46
+ # Create a DataFrame with the directory paths
47
+ data = {
48
+ 'Directory': ['Base Directory', 'Input Data Directory', 'Output Data Directory', 'Output Images Directory', 'Metadata Directory', 'Metadata Images Directory'],
49
+ 'Path': [base_dir, input_data_dir, output_data_dir, output_images_dir, metadata_dir, metadata_images_dir]
50
+ }
51
+ df = pd.DataFrame(data)
52
+
53
+ # List CSV files in the input_data_dir
54
+ ls_samples = [sample for sample in os.listdir(input_data_dir) if sample.endswith(".csv")]
55
+ print(f"The following CSV files were detected:\n\n{ls_samples}\n\nin {input_data_dir} directory.")
56
+
57
+ # List CSV files in the metadata_dir
58
+ metadata_files = [file for file in os.listdir(metadata_dir) if file.endswith(".tif.csv")]
59
+ print(f"The following metadata CSV files were detected:\n\n{metadata_files}\n\nin {metadata_dir} directory.")
60
+
61
+ # Update the CheckBoxGroup options
62
+ checkbox_group.options = ls_samples
63
+ metadata_checkbox_group.options = metadata_files
64
+
65
+ # Create a DataFrame with the CSV files
66
+ csv_files = pd.DataFrame({'CSV Files': ls_samples})
67
+ metadata_files_df = pd.DataFrame({'Metadata Files': metadata_files})
68
+
69
+ # Update the output panes
70
+ output_pane_1.object = f"**File Path:** {input_path}\n\n**Set Name:** {set_path}"
71
+ output_pane_2.object = df.to_html(index=False)
72
+ output_pane_3.object = csv_files.to_html(index=False)
73
+ output_pane_4.object = metadata_files_df.to_html(index=False)
74
+
75
+ # Define a callback to save the selected CSV files when the button is clicked
76
+ def save_selected_files(event):
77
+ # Store the variables in a JSON file
78
+ with open('stored_variables.json', 'w') as file:
79
+ json.dump({'base_dir': base_dir, 'set_path': set_path}, file)
80
+
81
+ # Define a callback to update the ls_samples list based on the selected options
82
+ def update_ls_samples(event):
83
+ global ls_samples
84
+ ls_samples = event.new
85
+
86
+ # Define a callback to update the metadata_files list based on the selected options
87
+ def update_metadata_files(event):
88
+ global metadata_files, selected_metadata_files
89
+ metadata_files = event.new
90
+ selected_metadata_files = event.new
91
+
92
+ # Define a callback to save the selected metadata files when the button is clicked
93
+ def save_selected_metadata_files(event):
94
+ with open('stored_variables.json', 'w') as file:
95
+ json.dump({'selected_metadata_files': selected_metadata_files}, file)
96
+
97
+ # Define the widgets
98
+ file_input = pn.widgets.TextInput(
99
+ name="File Path",
100
+ placeholder="Enter the path to your directory"
101
+ )
102
+
103
+ # Define the set name
104
+ set_name = pn.widgets.TextInput(
105
+ name="Set Name",
106
+ placeholder="Enter the Set"
107
+ )
108
+
109
+ # Button to trigger storing values
110
+ store_button = pn.widgets.Button(name='Store Values')
111
+ store_button.on_click(store_values)
112
+
113
+ # CheckBoxGroup to select CSV files
114
+ checkbox_group = pn.widgets.CheckBoxGroup(name='Select CSV Files', options=[], value=[])
115
+ checkbox_group.param.watch(update_ls_samples, 'value')
116
+
117
+ # CheckBoxGroup to select metadata files
118
+ metadata_checkbox_group = pn.widgets.CheckBoxGroup(name='Select Metadata Files', options=[], value=[])
119
+ metadata_checkbox_group.param.watch(update_metadata_files, 'value')
120
+
121
+ # Button to save selected CSV files
122
+ save_button = pn.widgets.Button(name='Save Files')
123
+ save_button.on_click(save_selected_files)
124
+
125
+ # Button to save selected metadata files
126
+ save_metadata_button = pn.widgets.Button(name='Save Metadata Files')
127
+ save_metadata_button.on_click(save_selected_metadata_files)
128
+
129
+ output_pane_1 = pn.pane.Markdown("")
130
+ output_pane_2 = pn.pane.HTML("")
131
+ output_pane_3 = pn.pane.HTML("")
132
+ output_pane_4 = pn.pane.HTML("")
133
+
134
+ # Create the cards
135
+ card_1 = pn.Card(
136
+ pn.Column(
137
+ pn.pane.Markdown("### Input Form"),
138
+ file_input,
139
+ set_name,
140
+ store_button,
141
+ output_pane_1,
142
+ sizing_mode="stretch_width"
143
+ ),
144
+ title="Input Form",
145
+ sizing_mode="stretch_width"
146
+ )
147
+
148
+ card_2 = pn.Card(
149
+ pn.Column(
150
+ pn.pane.Markdown("### Directory Paths"),
151
+ output_pane_2,
152
+ sizing_mode="stretch_width"
153
+ ),
154
+ title="Directory Paths",
155
+ sizing_mode="stretch_width"
156
+ )
157
+
158
+ card_3 = pn.Card(
159
+ pn.Column(
160
+ pn.pane.Markdown("### CSV Files"),
161
+ output_pane_3,
162
+ pn.pane.Markdown("### Selection of CSV files for the further analysis"),
163
+ checkbox_group,
164
+ save_button,
165
+ sizing_mode="stretch_width"
166
+ ),
167
+ title="CSV Files",
168
+ sizing_mode="stretch_width"
169
+ )
170
+
171
+ card_4 = pn.Card(
172
+ pn.Column(
173
+ pn.pane.Markdown("### Metadata Files"),
174
+ output_pane_4,
175
+ pn.pane.Markdown("### Selection of Metadata Files"),
176
+ metadata_checkbox_group,
177
+ save_metadata_button,
178
+ sizing_mode="stretch_width"
179
+ ),
180
+ title="Metadata Files",
181
+ sizing_mode="stretch_width"
182
+ )
183
+
184
+ # Create the main column with the cards
185
+ main_column = pn.Column(card_1, card_2, card_3, card_4)
186
+
187
+ # Create the GoldenTemplate with the main column
188
+ app = pn.template.GoldenTemplate(
189
+ site="Cyc-IF",
190
+ title="Setup",
191
+ main=[main_column],
192
+ header_color="black",
193
+ )
194
+
195
+ app.servable()
196
+
197
+ if __name__ == "__main__":
198
+ pn.serve(app, port=5006)