lgq12697 commited on
Commit
272d619
1 Parent(s): 2776743

Create app.py

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