Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,33 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
|
| 7 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForMaskedLM
|
| 3 |
+
import torch
|
| 4 |
|
| 5 |
+
# 加载模型和分词器
|
| 6 |
+
model_name = "InstaDeepAI/agro-nucleotide-transformer-1b"
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 8 |
+
model = AutoModelForMaskedLM.from_pretrained(model_name)
|
| 9 |
+
|
| 10 |
+
# 推理函数
|
| 11 |
+
def predict(sequence):
|
| 12 |
+
# 编码
|
| 13 |
+
tokens = tokenizer(sequence, return_tensors="pt", padding=True)
|
| 14 |
+
with torch.no_grad():
|
| 15 |
+
output = model(**tokens)
|
| 16 |
+
|
| 17 |
+
# 提取 logits(每个 token 的预测概率)
|
| 18 |
+
logits = output.logits[0]
|
| 19 |
+
predicted_token_ids = torch.argmax(logits, dim=-1)
|
| 20 |
+
predicted_sequence = tokenizer.decode(predicted_token_ids)
|
| 21 |
+
|
| 22 |
+
return predicted_sequence
|
| 23 |
+
|
| 24 |
+
# Gradio 网页界面
|
| 25 |
+
demo = gr.Interface(
|
| 26 |
+
fn=predict,
|
| 27 |
+
inputs=gr.Textbox(lines=2, placeholder="输入DNA序列,例如:ATATACGGCCGNC"),
|
| 28 |
+
outputs="text",
|
| 29 |
+
title="AgroNT 植物DNA语言模型",
|
| 30 |
+
description="使用 AgroNT 模型(1B参数)对DNA序列进行语言建模预测"
|
| 31 |
+
)
|
| 32 |
|
|
|
|
| 33 |
demo.launch()
|