separate downloads from main function
Browse files
app.py
CHANGED
@@ -35,7 +35,6 @@ def load_and_predict_with_classifier(x, model_path, output_path, save):
|
|
35 |
|
36 |
return y_pred
|
37 |
|
38 |
-
|
39 |
def plot_umap(adata):
|
40 |
|
41 |
labels = pd.Categorical(adata.obs["cell_type"])
|
@@ -69,18 +68,13 @@ def plot_umap(adata):
|
|
69 |
|
70 |
return img
|
71 |
|
72 |
-
|
73 |
def toggle_file_input(default_dataset):
|
74 |
if default_dataset != "None":
|
75 |
return gr.update(interactive=False) # Disable the file input if a default dataset is selected
|
76 |
else:
|
77 |
return gr.update(interactive=True) # Enable the file input if no default dataset is selected
|
78 |
|
79 |
-
|
80 |
-
def main(input_file_path, species, default_dataset):
|
81 |
-
|
82 |
-
BASE_PATH = '/home/user/app/UCE/'
|
83 |
-
|
84 |
# clone and cd into UCE repo
|
85 |
os.system('git clone https://github.com/minwoosun/UCE.git')
|
86 |
os.chdir(BASE_PATH)
|
@@ -92,6 +86,23 @@ def main(input_file_path, species, default_dataset):
|
|
92 |
default_dataset_1_path = hf_hub_download(repo_id="minwoosun/uce-misc", filename="100_pbmcs_proc_subset.h5ad")
|
93 |
default_dataset_2_path = hf_hub_download(repo_id="minwoosun/uce-misc", filename="1k_pbmcs_proc_subset.h5ad")
|
94 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
# If the user selects a default dataset, use that instead of the uploaded file
|
96 |
if default_dataset == "PBMC 100 cells":
|
97 |
input_file_path = default_dataset_1_path
|
@@ -105,10 +116,6 @@ def main(input_file_path, species, default_dataset):
|
|
105 |
from accelerate import Accelerator
|
106 |
|
107 |
model_loc = 'minwoosun/uce-100m'
|
108 |
-
|
109 |
-
print(input_file_path)
|
110 |
-
print(BASE_PATH)
|
111 |
-
print(model_loc)
|
112 |
|
113 |
# Construct the command
|
114 |
command = [
|
@@ -156,6 +163,9 @@ def main(input_file_path, species, default_dataset):
|
|
156 |
|
157 |
if __name__ == "__main__":
|
158 |
|
|
|
|
|
|
|
159 |
with gr.Blocks() as demo:
|
160 |
gr.Markdown(
|
161 |
'''
|
@@ -218,32 +228,27 @@ if __name__ == "__main__":
|
|
218 |
image_output = gr.Image(type="numpy", label="UMAP_of_UCE_Embeddings")
|
219 |
file_output = gr.File(label="Download embeddings")
|
220 |
pred_output = gr.File(label="Download predictions")
|
221 |
-
|
222 |
-
print(image_output)
|
223 |
-
print(file_output)
|
224 |
-
print(pred_output)
|
225 |
|
226 |
# Add the components and link to the function
|
227 |
run_button.click(
|
228 |
fn=main,
|
229 |
-
inputs=[file_input, species_input, default_dataset_input],
|
230 |
outputs=[image_output, file_output, pred_output]
|
231 |
)
|
232 |
|
|
|
|
|
|
|
|
|
233 |
|
234 |
-
#
|
235 |
-
examples = [
|
236 |
-
[None, "human", "PBMC 100 cells"],
|
237 |
-
[None, "human", "PBMC 1000 cells"]
|
238 |
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
cache_examples=True
|
247 |
-
)
|
248 |
|
249 |
demo.launch()
|
|
|
35 |
|
36 |
return y_pred
|
37 |
|
|
|
38 |
def plot_umap(adata):
|
39 |
|
40 |
labels = pd.Categorical(adata.obs["cell_type"])
|
|
|
68 |
|
69 |
return img
|
70 |
|
|
|
71 |
def toggle_file_input(default_dataset):
|
72 |
if default_dataset != "None":
|
73 |
return gr.update(interactive=False) # Disable the file input if a default dataset is selected
|
74 |
else:
|
75 |
return gr.update(interactive=True) # Enable the file input if no default dataset is selected
|
76 |
|
77 |
+
def download_files(base_path):
|
|
|
|
|
|
|
|
|
78 |
# clone and cd into UCE repo
|
79 |
os.system('git clone https://github.com/minwoosun/UCE.git')
|
80 |
os.chdir(BASE_PATH)
|
|
|
86 |
default_dataset_1_path = hf_hub_download(repo_id="minwoosun/uce-misc", filename="100_pbmcs_proc_subset.h5ad")
|
87 |
default_dataset_2_path = hf_hub_download(repo_id="minwoosun/uce-misc", filename="1k_pbmcs_proc_subset.h5ad")
|
88 |
|
89 |
+
return default_dataset_1_path, default_dataset_2_path
|
90 |
+
|
91 |
+
def main(input_file_path, species, default_dataset, default_dataset_1_path, default_dataset_2_path):
|
92 |
+
|
93 |
+
BASE_PATH = '/home/user/app/UCE/'
|
94 |
+
|
95 |
+
# # clone and cd into UCE repo
|
96 |
+
# os.system('git clone https://github.com/minwoosun/UCE.git')
|
97 |
+
# os.chdir(BASE_PATH)
|
98 |
+
|
99 |
+
# # Add the directory to the Python path
|
100 |
+
# sys.path.append(BASE_PATH)
|
101 |
+
|
102 |
+
# # Set default dataset path
|
103 |
+
# default_dataset_1_path = hf_hub_download(repo_id="minwoosun/uce-misc", filename="100_pbmcs_proc_subset.h5ad")
|
104 |
+
# default_dataset_2_path = hf_hub_download(repo_id="minwoosun/uce-misc", filename="1k_pbmcs_proc_subset.h5ad")
|
105 |
+
|
106 |
# If the user selects a default dataset, use that instead of the uploaded file
|
107 |
if default_dataset == "PBMC 100 cells":
|
108 |
input_file_path = default_dataset_1_path
|
|
|
116 |
from accelerate import Accelerator
|
117 |
|
118 |
model_loc = 'minwoosun/uce-100m'
|
|
|
|
|
|
|
|
|
119 |
|
120 |
# Construct the command
|
121 |
command = [
|
|
|
163 |
|
164 |
if __name__ == "__main__":
|
165 |
|
166 |
+
BASE_PATH = '/home/user/app/UCE/'
|
167 |
+
default_dataset_1_path, default_dataset_2_path = download_files(BASE_PATH)
|
168 |
+
|
169 |
with gr.Blocks() as demo:
|
170 |
gr.Markdown(
|
171 |
'''
|
|
|
228 |
image_output = gr.Image(type="numpy", label="UMAP_of_UCE_Embeddings")
|
229 |
file_output = gr.File(label="Download embeddings")
|
230 |
pred_output = gr.File(label="Download predictions")
|
|
|
|
|
|
|
|
|
231 |
|
232 |
# Add the components and link to the function
|
233 |
run_button.click(
|
234 |
fn=main,
|
235 |
+
inputs=[file_input, species_input, default_dataset_input, default_dataset_1_path, default_dataset_2_path],
|
236 |
outputs=[image_output, file_output, pred_output]
|
237 |
)
|
238 |
|
239 |
+
# # Examples section
|
240 |
+
# examples = [
|
241 |
+
# ["", "human", "PBMC 100 cells"],
|
242 |
+
# ["", "human", "PBMC 1000 cells"]
|
243 |
|
244 |
+
# ]
|
|
|
|
|
|
|
245 |
|
246 |
+
# gr.Examples(
|
247 |
+
# fn=main,
|
248 |
+
# examples=examples,
|
249 |
+
# inputs=[file_input, species_input, default_dataset_input],
|
250 |
+
# outputs=[image_output, file_output, pred_output],
|
251 |
+
# cache_examples=True
|
252 |
+
# )
|
|
|
|
|
253 |
|
254 |
demo.launch()
|