Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
CHANGED
|
@@ -12,6 +12,7 @@ def show_cwe_sev(input_code):
|
|
| 12 |
sev_score = int(sev_pred["batch_sev_score"][0])
|
| 13 |
sev_class = sev_pred["batch_sev_class"][0]
|
| 14 |
|
|
|
|
| 15 |
if "CWE-" in cwe_pred:
|
| 16 |
id_ = cwe_pred.split("CWE-")[-1]
|
| 17 |
link = f"https://cwe.mitre.org/data/definitions/{id_}.html"
|
|
@@ -63,23 +64,23 @@ if __name__ == "__main__":
|
|
| 63 |
line_pred = out["batch_statement_pred"][0]
|
| 64 |
line_confidence = out["batch_statement_pred_prob"][0]
|
| 65 |
output = None
|
| 66 |
-
|
| 67 |
-
st.snow()
|
| 68 |
-
print_code = input_code.split("\n")[:MAX_NUM_STATEMENTS]
|
| 69 |
-
st.markdown("### Scanning Results:")
|
| 70 |
if func_pred == 0:
|
|
|
|
| 71 |
st.markdown("<span style='color:green'>" + "**No vulnerabilities detected**"+ "</span>", unsafe_allow_html=True)
|
| 72 |
st.markdown("### Non-Vulnerable Function:")
|
| 73 |
else:
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
|
|
|
| 82 |
st.code(input_code, language="cpp", line_numbers=True)
|
|
|
|
| 83 |
|
| 84 |
elif behavior == "Analyze my own":
|
| 85 |
# user input of project title
|
|
@@ -100,17 +101,19 @@ if __name__ == "__main__":
|
|
| 100 |
# inference complete
|
| 101 |
st.snow()
|
| 102 |
print_code = input_code.split("\n")[:MAX_NUM_STATEMENTS]
|
| 103 |
-
st.markdown("### Scanning Results:")
|
| 104 |
if func_pred == 0:
|
|
|
|
| 105 |
st.write("<span style='color:green'>" + "No vulnerabilities detected"+ "</span>", unsafe_allow_html=True)
|
| 106 |
st.markdown("### Non-Vulnerable Function:")
|
| 107 |
else:
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
|
|
|
|
|
|
|
|
| 12 |
sev_score = int(sev_pred["batch_sev_score"][0])
|
| 13 |
sev_class = sev_pred["batch_sev_class"][0]
|
| 14 |
|
| 15 |
+
st.markdown("### Scanning Results:")
|
| 16 |
if "CWE-" in cwe_pred:
|
| 17 |
id_ = cwe_pred.split("CWE-")[-1]
|
| 18 |
link = f"https://cwe.mitre.org/data/definitions/{id_}.html"
|
|
|
|
| 64 |
line_pred = out["batch_statement_pred"][0]
|
| 65 |
line_confidence = out["batch_statement_pred_prob"][0]
|
| 66 |
output = None
|
| 67 |
+
print_code = input_code.split("\n")[:MAX_NUM_STATEMENTS]
|
|
|
|
|
|
|
|
|
|
| 68 |
if func_pred == 0:
|
| 69 |
+
st.markdown("### Scanning Results:")
|
| 70 |
st.markdown("<span style='color:green'>" + "**No vulnerabilities detected**"+ "</span>", unsafe_allow_html=True)
|
| 71 |
st.markdown("### Non-Vulnerable Function:")
|
| 72 |
else:
|
| 73 |
+
with st.spinner("Identifying vulnerability types and severity..."):
|
| 74 |
+
show_cwe_sev(input_code)
|
| 75 |
+
for i in range(len(print_code)):
|
| 76 |
+
c = print_code[i]
|
| 77 |
+
vul = line_pred[i]
|
| 78 |
+
if vul == 1:
|
| 79 |
+
st.markdown(f"<span style='color:red'> Vulnerable Line **{i+1}** </span>", unsafe_allow_html=True)
|
| 80 |
+
st.code(c)
|
| 81 |
+
st.markdown("### Vulnerable Function:")
|
| 82 |
st.code(input_code, language="cpp", line_numbers=True)
|
| 83 |
+
st.snow()
|
| 84 |
|
| 85 |
elif behavior == "Analyze my own":
|
| 86 |
# user input of project title
|
|
|
|
| 101 |
# inference complete
|
| 102 |
st.snow()
|
| 103 |
print_code = input_code.split("\n")[:MAX_NUM_STATEMENTS]
|
|
|
|
| 104 |
if func_pred == 0:
|
| 105 |
+
st.markdown("### Scanning Results:")
|
| 106 |
st.write("<span style='color:green'>" + "No vulnerabilities detected"+ "</span>", unsafe_allow_html=True)
|
| 107 |
st.markdown("### Non-Vulnerable Function:")
|
| 108 |
else:
|
| 109 |
+
with st.spinner("Identifying vulnerability types and severity..."):
|
| 110 |
+
show_cwe_sev(input_code)
|
| 111 |
+
for i in range(len(print_code)):
|
| 112 |
+
c = print_code[i]
|
| 113 |
+
vul = line_pred[i]
|
| 114 |
+
if vul == 1:
|
| 115 |
+
st.write(f"<span style='color:red'> Vulnerable Line {i+1} </span>", unsafe_allow_html=True)
|
| 116 |
+
st.code(c)
|
| 117 |
+
st.markdown("### Vulnerable Function:")
|
| 118 |
+
st.code(input_code, language="cpp", line_numbers=True)
|
| 119 |
+
st.snow()
|