Spaces:
Paused
Paused
Commit
·
c4d60f8
1
Parent(s):
a79df8e
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,13 @@ from transformers import AutoTokenizer, EsmModel
|
|
3 |
import torch
|
4 |
import json
|
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
# selecing and loading a model
|
7 |
model_name = st.selectbox(
|
8 |
'Choose a model',
|
@@ -12,36 +19,38 @@ st.write('You selected model:', model_name)
|
|
12 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
13 |
model = EsmModel.from_pretrained(model_name)
|
14 |
|
15 |
-
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
st.write(
|
22 |
-
st.write('Last hidden states:')
|
23 |
-
st.write(last_hidden_states)
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
}
|
29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
st.download_button(
|
32 |
-
label="Download JSON file",
|
33 |
-
data=json_data,
|
34 |
-
file_name="esm-2 last hidden states.json",
|
35 |
-
mime='application/json'
|
36 |
)
|
37 |
|
38 |
|
39 |
if st.button('Get embedding'):
|
40 |
-
|
41 |
|
42 |
st.write('Also, Dania is not gay')
|
43 |
-
#uploading AA sequences file
|
44 |
-
uploaded_file = st.file_uploader("Choose a JSON file", type='json')
|
45 |
-
if uploaded_file is not None:
|
46 |
-
data = json.load(uploaded_file)
|
47 |
-
st.write(data)
|
|
|
3 |
import torch
|
4 |
import json
|
5 |
|
6 |
+
def embed(aa_seq, tokenizer, model):
|
7 |
+
inputs = tokenizer(aa_seq, return_tensors="pt")
|
8 |
+
outputs = model(**inputs)
|
9 |
+
last_hidden_states = outputs.last_hidden_state.to_list()
|
10 |
+
|
11 |
+
return last_hidden_states
|
12 |
+
|
13 |
# selecing and loading a model
|
14 |
model_name = st.selectbox(
|
15 |
'Choose a model',
|
|
|
19 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
20 |
model = EsmModel.from_pretrained(model_name)
|
21 |
|
22 |
+
#aa_seq_input = st.text_input('Type AA sequance here')
|
23 |
|
24 |
+
#uploading AA sequences file
|
25 |
+
uploaded_file = st.file_uploader("Upload JSON with AA sequences", type='json')
|
26 |
+
if uploaded_file is not None:
|
27 |
+
data = json.load(uploaded_file)
|
28 |
+
st.write(data)
|
|
|
|
|
29 |
|
30 |
+
def embed_upload_file(upload_dict_dania):
|
31 |
+
# upload_dict_dania = {
|
32 |
+
# 'uid1': ['aa', 'aan']
|
33 |
+
# }
|
34 |
+
# output = {
|
35 |
+
# 'uid1': {'aa':[[[0.1298, ....]]], 'aan':[[[0.1298, ....]]]}
|
36 |
+
# }
|
37 |
+
|
38 |
+
for uid, seqs in upload_json_dania.items():
|
39 |
+
output[uid] = {}
|
40 |
+
for seq in seqs:
|
41 |
+
output[uid][seq] = embed(seq)
|
42 |
+
|
43 |
+
json_data = json.dumps(output)
|
44 |
|
45 |
st.download_button(
|
46 |
+
label = "Download JSON file",
|
47 |
+
data = json_data,
|
48 |
+
file_name = "esm-2 last hidden states.json",
|
49 |
+
mime = 'application/json'
|
50 |
)
|
51 |
|
52 |
|
53 |
if st.button('Get embedding'):
|
54 |
+
embed_upload_file(data)
|
55 |
|
56 |
st.write('Also, Dania is not gay')
|
|
|
|
|
|
|
|
|
|