File size: 952 Bytes
cff57aa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
26
27
28
import gradio as gr
from transformers import pipeline

# Load your model from Hugging Face
model_name = "CIRCL/vulnerability-severity-classification-roberta-base"
classifier = pipeline("text-classification", model=model_name, return_all_scores=True)

# Define severity labels
severity_labels = ["Low", "Medium", "High", "Critical"]

def classify_text(text):
    results = classifier(text)[0]  # Extract the first (and only) result
    scores = {severity_labels[i]: round(r["score"], 4) for i, r in enumerate(results)}
    return scores

# Create the Gradio interface
interface = gr.Interface(
    fn=classify_text,
    inputs=gr.Textbox(lines=5, placeholder="Enter vulnerability description..."),
    outputs=gr.Label(num_top_classes=4),  # Display all scores
    title="Vulnerability Severity Classification",
    description="Enter a vulnerability description, and the model will classify its severity level."
)

# Launch the app
interface.launch()