| import gradio as gr |
| from transformers import pipeline |
|
|
| |
| model_name = "CIRCL/vulnerability-severity-classification-chinese-macbert-base" |
| classifier = pipeline("text-classification", model=model_name, return_all_scores=True) |
|
|
| |
| severity_labels = ["Low 低", "Medium 中", "High 高"] |
|
|
| def classify_text(text): |
| results = classifier(text)[0] |
| scores = {severity_labels[i]: round(r["score"], 4) for i, r in enumerate(results)} |
| return scores |
|
|
| |
| interface = gr.Interface( |
| fn=classify_text, |
| inputs=gr.Textbox(lines=5, placeholder="Enter vulnerability description..."), |
| outputs=gr.Label(num_top_classes=4), |
| title="Vulnerability Severity Classification", |
| description="Enter a vulnerability description, and the model will classify its severity level." |
| ) |
|
|
| |
| interface.launch() |
|
|