Umair Khan
commited on
Commit
·
8cb988a
1
Parent(s):
6b43a2d
put installation and imports at beginning of app
Browse files
app.py
CHANGED
|
@@ -1,14 +1,22 @@
|
|
| 1 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import gc
|
| 3 |
-
import spaces
|
| 4 |
import tempfile
|
|
|
|
| 5 |
import gradio as gr
|
| 6 |
import anndata as ad
|
| 7 |
import pandas as pd
|
| 8 |
import numpy as np
|
| 9 |
import scanpy as sc
|
| 10 |
from pathlib import Path
|
|
|
|
| 11 |
from omegaconf import OmegaConf as om
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
# hardcoded configuration
|
| 14 |
EMB_KEY = "X_tx1-70m"
|
|
@@ -56,21 +64,8 @@ def _save_outputs(adata, emb):
|
|
| 56 |
return str(parquet_path), str(out_h5ad)
|
| 57 |
|
| 58 |
# compute embeddings
|
| 59 |
-
@spaces.GPU
|
| 60 |
def _embed(adata_bytes, layer_name, feature_col, batch_size):
|
| 61 |
|
| 62 |
-
# install package
|
| 63 |
-
import os
|
| 64 |
-
# os.system("pip install --no-build-isolation flash-attn")
|
| 65 |
-
os.system("pip install --no-deps ./mosaicfm-0.1.2-py3-none-any.whl")
|
| 66 |
-
|
| 67 |
-
# imports inside GPU scope
|
| 68 |
-
import torch
|
| 69 |
-
from composer import Trainer
|
| 70 |
-
from mosaicfm.model.model import ComposerSCGPTModel
|
| 71 |
-
from mosaicfm.data import CountDataset, DataCollator
|
| 72 |
-
from mosaicfm.tokenizer import GeneVocab
|
| 73 |
-
|
| 74 |
# retrieve AnnData from bytes
|
| 75 |
with tempfile.TemporaryDirectory() as td:
|
| 76 |
fpath = Path(td) / "input.h5ad"
|
|
|
|
| 1 |
+
# install custom package
|
| 2 |
+
import os
|
| 3 |
+
os.system("pip install --no-deps ./mosaicfm-0.1.2-py3-none-any.whl")
|
| 4 |
+
|
| 5 |
+
# imports
|
| 6 |
import gc
|
|
|
|
| 7 |
import tempfile
|
| 8 |
+
import torch
|
| 9 |
import gradio as gr
|
| 10 |
import anndata as ad
|
| 11 |
import pandas as pd
|
| 12 |
import numpy as np
|
| 13 |
import scanpy as sc
|
| 14 |
from pathlib import Path
|
| 15 |
+
from composer import Trainer
|
| 16 |
from omegaconf import OmegaConf as om
|
| 17 |
+
from mosaicfm.model.model import ComposerSCGPTModel
|
| 18 |
+
from mosaicfm.data import CountDataset, DataCollator
|
| 19 |
+
from mosaicfm.tokenizer import GeneVocab
|
| 20 |
|
| 21 |
# hardcoded configuration
|
| 22 |
EMB_KEY = "X_tx1-70m"
|
|
|
|
| 64 |
return str(parquet_path), str(out_h5ad)
|
| 65 |
|
| 66 |
# compute embeddings
|
|
|
|
| 67 |
def _embed(adata_bytes, layer_name, feature_col, batch_size):
|
| 68 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
# retrieve AnnData from bytes
|
| 70 |
with tempfile.TemporaryDirectory() as td:
|
| 71 |
fpath = Path(td) / "input.h5ad"
|