simecek commited on
Commit
60de227
1 Parent(s): 8468756

initial commit

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
2
+ from scipy.special import softmax
3
+ import gradio as gr
4
+
5
+ tokenizer = AutoTokenizer.from_pretrained("armheb/DNA_bert_6")
6
+ model2 = AutoModelForSequenceClassification.from_pretrained("simecek/promoters_demo")
7
+
8
+ def kmers(s, k=6):
9
+ return [s[i:i + k] for i in range(0, len(s)-k+1)]
10
+
11
+ def tokenization(x):
12
+ return tokenizer(" ".join(kmers(x["seq"])), return_tensors="pt")
13
+
14
+ categories = ["not-promoter", "promoter"]
15
+
16
+ def is_promoter(DNAseq):
17
+ input = tokenization({"seq": DNAseq})
18
+ logits = model2(**input)['logits'].detach().numpy()
19
+ probs = softmax(logits, axis=1)[0]
20
+ probs = map(float, probs)
21
+
22
+ return dict(zip(categories, probs))
23
+
24
+ text = gr.inputs.Textbox(placeholder="Input DNA sequence", lines=5)
25
+ label = gr.outputs.Label(label = "Is it a promoter?")
26
+
27
+ intf = gr.Interface(fn=is_promoter, inputs=text, outputs=label)
28
+
29
+ intf.launch()