Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,15 @@
|
|
1 |
import gradio as gr
|
2 |
import json
|
3 |
from transformers import pipeline
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
# Load Hugging Face model (text classification)
|
6 |
classifier = pipeline(
|
@@ -8,6 +17,11 @@ classifier = pipeline(
|
|
8 |
model="CIRCL/cwe-parent-vulnerability-classification-roberta-base",
|
9 |
return_all_scores=True
|
10 |
)
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
# Load child-to-parent mapping
|
13 |
with open("child_to_parent_mapping.json", "r") as f:
|
@@ -41,8 +55,6 @@ demo = gr.Interface(
|
|
41 |
["Fixed buffer overflow in input parsing"],
|
42 |
["SQL injection possible in login flow"],
|
43 |
["Improved input validation to prevent XSS"],
|
44 |
-
["Added try/catch to avoid null pointer crash"],
|
45 |
-
["Patched race condition in thread lock logic"]
|
46 |
]
|
47 |
)
|
48 |
|
|
|
1 |
import gradio as gr
|
2 |
import json
|
3 |
from transformers import pipeline
|
4 |
+
import torch
|
5 |
+
import random
|
6 |
+
import numpy as np
|
7 |
+
|
8 |
+
torch.manual_seed(42)
|
9 |
+
random.seed(42)
|
10 |
+
np.random.seed(42)
|
11 |
+
|
12 |
+
torch.use_deterministic_algorithms(True)
|
13 |
|
14 |
# Load Hugging Face model (text classification)
|
15 |
classifier = pipeline(
|
|
|
17 |
model="CIRCL/cwe-parent-vulnerability-classification-roberta-base",
|
18 |
return_all_scores=True
|
19 |
)
|
20 |
+
classifier.model.eval()
|
21 |
+
|
22 |
+
threshold = 0.2
|
23 |
+
filtered_results = [item for item in sorted_results if item["score"] >= threshold]
|
24 |
+
|
25 |
|
26 |
# Load child-to-parent mapping
|
27 |
with open("child_to_parent_mapping.json", "r") as f:
|
|
|
55 |
["Fixed buffer overflow in input parsing"],
|
56 |
["SQL injection possible in login flow"],
|
57 |
["Improved input validation to prevent XSS"],
|
|
|
|
|
58 |
]
|
59 |
)
|
60 |
|