lgq12697 commited on
Commit
3570cf1
1 Parent(s): 5f47520

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +68 -0
app.py ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ import subprocess
4
+ from transformers import AutoModelForSequenceClassification,AutoTokenizer
5
+
6
+ model_names = ['plant-dnabert','plant-nucleotide-transformer','plant-dnagpt',
7
+ 'plant-dnagemma','dnabert2','nucleotide-transformer-v2-100m','agront-1b']
8
+ tokenizer_type = "6mer"
9
+ model_names = [x + '-' + tokenizer_type if x.startswith("plant") else x for x in model_names]
10
+
11
+ def inference(seq,model,task):
12
+ if not seq:
13
+ gr.Warning("No sequence provided, use the default sequence.")
14
+ seq = placeholder
15
+ # Load model and tokenizer
16
+ model_name = f'zhangtaolab/{model}-{task}'
17
+ model = AutoModelForSequenceClassification.from_pretrained(model_name,ignore_mismatched_sizes=True)
18
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
19
+
20
+ # Inference
21
+ inputs = tokenizer(seq, return_tensors='pt', padding=True, truncation=True, max_length=1024)
22
+ outputs = model(**inputs)
23
+ result = outputs.logits.item()
24
+ return result
25
+
26
+ placeholder = 'TACTCTAATCGTATCAGCTGCACTTGCGTACAGGCTACCGGCGTCCTCAGCCACGTAAGAAAAGGCCCAATAAAGGCCCAACTACAACCAGCGGATATATATACTGGAGCCTGGCGAGATCACCCTAACCCCTCACACTCCCATCCAGCCGCCACCAGGTGCAGAGTGTT'
27
+ css = """
28
+ .gradio-container {
29
+ max-width: 900px;
30
+ margin: auto;
31
+ padding: 20px;
32
+ }
33
+ .btn-primary {
34
+ background-color: #8e44ad;
35
+ border-color: #8e44ad;
36
+ }
37
+ """
38
+ # 创建 Gradio 接口
39
+
40
+ with gr.Blocks(css=css) as demo:
41
+ gr.HTML(
42
+ """
43
+ <h1 style="text-align: center;">Promoter strength in leaf predicted by plant LLMs</h1>
44
+ """
45
+ )
46
+ with gr.Row():
47
+ with gr.Column(scale=1):
48
+ drop1 = gr.Dropdown(choices=['promoter_strength_leaf'],
49
+ label="Selected Task",
50
+ interactive=False,
51
+ value="promoter_strength_leaf")
52
+ with gr.Column(scale=1):
53
+ drop2 = gr.Dropdown(choices=model_names,
54
+ label="Select Model",
55
+ interactive=True,
56
+ value=model_names[0])
57
+ with gr.Row():
58
+ with gr.Column(scale=1):
59
+ input_box = gr.Textbox(placeholder=placeholder, label="Enter promoter Sequence", lines=4)
60
+ with gr.Column(scale=1):
61
+ output_box = gr.Textbox(label="Output", lines=4)
62
+ with gr.Row():
63
+ submit_button = gr.Button("Submit", variant="primary")
64
+ clear_button = gr.Button("Clear")
65
+ submit_button.click(inference, inputs=[input_box,drop2,drop1], outputs=output_box)
66
+ clear_button.click(lambda: ("", ""), inputs=None, outputs=[input_box, output_box])
67
+ # 启动 Gradio 接口
68
+ demo.launch()