elselse commited on
Commit
f8e978b
·
verified ·
1 Parent(s): 9a580ea

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -0
app.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ MODEL_NAME = "CIRCL/cwe-parent-patch-vulnerability-classification-roberta-base"
5
+
6
+ classifier = pipeline("text-classification", model=MODEL_NAME, return_all_scores=True)
7
+
8
+ def classify_cwe(text):
9
+ results = classifier(text)[0]
10
+ # Sort by confidence score descending
11
+ sorted_results = sorted(results, key=lambda x: x["score"], reverse=True)
12
+ return {res["label"]: round(res["score"], 4) for res in sorted_results[:5]}
13
+
14
+ interface = gr.Interface(
15
+ fn=classify_cwe,
16
+ inputs=gr.Textbox(lines=5, placeholder="Enter vulnerability commit message..."),
17
+ outputs=gr.Label(num_top_classes=5),
18
+ title="CWE Vulnerability Classifier",
19
+ description="Enter a vulnerability commit message to predict the most likely CWE parent family"
20
+ )
21
+
22
+ # Launch the Gradio app
23
+ interface.launch()