File size: 814 Bytes
938d8cb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
import gradio as gr
from transformers import AutoTokenizer, AutoModelForSequenceClassification
# 加载预训练的模型
tokenizer = AutoTokenizer.from_pretrained("microsoft/codebert-base")
model = AutoModelForSequenceClassification.from_pretrained("microsoft/codebert-base")
# 定义漏洞检测函数
def detect_vulnerability(code):
inputs = tokenizer(code, return_tensors="pt")
outputs = model(**inputs)
prediction = outputs.logits.argmax(-1).item()
return "Buffer Overflow Detected" if prediction == 1 else "No Vulnerability Detected"
# 创建 Gradio 界面
iface = gr.Interface(
fn=detect_vulnerability,
inputs="textbox",
outputs="text",
title="Buffer Overflow Detection",
description="输入代码片段以检测是否存在缓冲区溢出漏洞。"
)
iface.launch()
|