awacke1 commited on
Commit
9ec8a42
Β·
verified Β·
1 Parent(s): 346ca65

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +157 -88
app.py CHANGED
@@ -2,69 +2,36 @@ import streamlit as st
2
  import pandas as pd
3
  import subprocess
4
  import time
 
5
 
6
  # ---------------------------- Header and Introduction ----------------------------
7
 
8
- # Set the page configuration
9
- st.set_page_config(
10
- page_title="LLMs for Cyber Security",
11
- page_icon="πŸ”’",
12
- layout="wide",
13
- initial_sidebar_state="expanded",
14
- )
15
-
16
- # Title of the application
17
  st.title("πŸ”’ LLMs for Cyber Security: State-of-the-Art Surveys")
18
-
19
- # Introduction text with link to the paper
20
- st.markdown("""
21
- This app is based on the paper: [Large Language Models for Cyber Security](https://arxiv.org/pdf/2405.04760v3).
22
- It showcases LLMs in the cybersecurity landscape, summarizing key surveys and insights.
23
- """)
24
 
25
  # ---------------------------- Data Preparation ----------------------------
26
 
27
- # Create the data dictionary
28
  data = {
29
- "Reference": [
30
- "Motlagh et al.", "Divakaran et al.", "Yao et al.", "Yigit et al.",
31
- "Coelho et al.", "Novelli et al.", "LLM4Security"
32
- ],
33
  "Year": [2024, 2024, 2023, 2024, 2024, 2024, 2024],
34
- "Scope": [
35
- "Security application", "Security application", "Security application, Security of LLM",
36
- "Security application, Security of LLM", "Security application",
37
- "Security application", "Security application"
38
- ],
39
- "Dimensions": [
40
- "Task", "Task", "Model, Task", "Task", "Task, Domain specific technique",
41
- "Task, Model, Domain specific technique", "Model, Task, Domain specific technique, Data"
42
- ],
43
- "Time frame": [
44
- "2022-2023", "2020-2024", "2019-2024", "2020-2024",
45
- "2021-2023", "2020-2024", "2020-2024"
46
- ],
47
  "Papers": ["Not specified", "Not specified", 281, "Not specified", 19, "Not specified", 127]
48
  }
49
-
50
- # Convert the data dictionary into a pandas DataFrame
51
  df = pd.DataFrame(data)
52
 
53
  # ---------------------------- Display Data Table ----------------------------
54
 
55
  st.subheader("πŸ“Š Survey Overview Table")
56
-
57
- # Display the DataFrame as an interactive table
58
  st.dataframe(df, height=300)
59
-
60
- # Add some spacing
61
  st.markdown("---")
62
 
63
  # ---------------------------- Mermaid Diagram Visualization ----------------------------
64
 
65
  st.subheader("πŸ›‘οΈ Security Model Visualization with Mermaid")
66
 
67
- # Define the Mermaid code
68
  mermaid_code = '''
69
  graph TD;
70
  A[LLMs in Security] --> B[Security Application]
@@ -74,25 +41,155 @@ graph TD;
74
  E --> F[Data]
75
  '''
76
 
77
- # Display the Mermaid diagram using markdown
78
- st.markdown(f"""
79
- ```mermaid
80
- {mermaid_code}
81
- ```
82
- """)
 
 
 
 
 
 
 
 
 
 
83
 
84
- # Explanation of the diagram
85
  st.markdown("""
86
  Figure: The diagram illustrates how Large Language Models (LLMs) are applied in security, highlighting the flow from general applications to specific tasks, models, domain-specific techniques, and data considerations.
87
  """)
 
88
 
89
- # Add some spacing
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
  st.markdown("---")
91
 
92
  # ---------------------------- Scrollable Content for Additional Insights ----------------------------
93
- st.subheader("πŸ“ Additional Insights")
94
 
95
- # Custom CSS for scrollable content
96
  st.markdown("""
97
  <style>
98
  .scrollable-content {
@@ -102,10 +199,6 @@ st.markdown("""
102
  border: 1px solid #ccc;
103
  }
104
  </style>
105
- """, unsafe_allow_html=True)
106
-
107
- # Scrollable content with insights
108
- st.markdown("""
109
  <div class="scrollable-content">
110
  <h4>Survey Highlights:</h4>
111
  <ul>
@@ -125,40 +218,26 @@ st.markdown("""
125
  </ol>
126
  </div>
127
  """, unsafe_allow_html=True)
128
-
129
- # Add some spacing
130
  st.markdown("---")
131
 
132
  # ---------------------------- Security Audit Section ----------------------------
133
- st.subheader("πŸ” Run Python Dependency Security Audit")
134
 
135
- # Explanation of the security audit
136
- st.markdown("""
137
- Keeping your project's dependencies secure is crucial. Use the button below to run a security audit on the Python packages used in this environment.
138
- """)
139
 
140
- # Button to trigger the security audit
141
  if st.button('Run pip-audit for Security Check'):
142
  with st.spinner('Running security audit...'):
143
- # Simulate a delay for the audit process
144
  time.sleep(2)
145
- # Run the pip-audit command
146
  result = subprocess.run(['pip-audit'], capture_output=True, text=True)
147
- # Display the audit results
148
  st.code(result.stdout)
149
  st.success('Security audit completed!')
150
 
151
- # Note about pip-audit
152
- st.markdown("""
153
- Note: The pip-audit tool checks your Python environment for packages with known vulnerabilities, referencing public CVE databases.
154
- """)
155
-
156
- # Add some spacing
157
  st.markdown("---")
158
 
159
  # ---------------------------- AI Pair Programming Recommendations ----------------------------
160
- st.subheader("πŸ€– AI Pair Programming: Security Recommendations")
161
 
 
162
  st.markdown("""
163
  Leveraging AI in pair programming can enhance code security and quality. Here are some recommendations:
164
 
@@ -168,13 +247,11 @@ Leveraging AI in pair programming can enhance code security and quality. Here ar
168
  4. **Code Review Assistance**: AI can assist in code reviews by highlighting potential security issues and non-compliance with best practices.
169
  5. **Secure Coding Practices**: AI can provide real-time suggestions for secure coding patterns and discourage the use of insecure functions.
170
  """)
171
-
172
- # Add some spacing
173
  st.markdown("---")
174
 
175
  # ---------------------------- Azure Deployment Information ----------------------------
176
- st.subheader("☁️ Azure Deployment Information")
177
 
 
178
  st.markdown("""
179
  While this demo does not include operational deployment, here's how you can deploy this application using Azure services:
180
 
@@ -196,14 +273,11 @@ While this demo does not include operational deployment, here's how you can depl
196
  - Multi-model database service
197
  - Low latency and high availability
198
  """)
199
-
200
- # Add some spacing
201
  st.markdown("---")
202
 
203
  # ---------------------------- Footer and Additional Resources ----------------------------
204
- st.subheader("πŸ“š Additional Resources")
205
 
206
- # List of additional resources and links
207
  st.markdown("""
208
  - [Official Streamlit Documentation](https://docs.streamlit.io/)
209
  - [pip-audit GitHub Repository](https://github.com/pypa/pip-audit)
@@ -212,21 +286,17 @@ st.markdown("""
212
  - [Cybersecurity Best Practices by CISA](https://www.cisa.gov/cybersecurity-best-practices)
213
  """)
214
 
215
- # Contact information or call to action
216
- st.markdown("""
217
- If you have any questions or would like to contribute to this project, please reach out or submit a pull request on GitHub.
218
- """)
219
-
220
- # Add some spacing
221
- st.markdown("---")
222
 
223
  # ---------------------------- Sidebar Content ----------------------------
224
- # Add content to the sidebar
225
  st.sidebar.title("Navigation")
226
  st.sidebar.markdown("""
227
  - [Introduction](#llms-for-cyber-security-state-of-the-art-surveys)
228
  - [Survey Overview Table](#survey-overview-table)
229
  - [Security Model Visualization](#security-model-visualization-with-mermaid)
 
 
230
  - [Additional Insights](#additional-insights)
231
  - [Security Audit](#run-python-dependency-security-audit)
232
  - [AI Recommendations](#ai-pair-programming-security-recommendations)
@@ -234,7 +304,6 @@ st.sidebar.markdown("""
234
  - [Additional Resources](#additional-resources)
235
  """, unsafe_allow_html=True)
236
 
237
- # Add an about section
238
  st.sidebar.title("About")
239
  st.sidebar.info("""
240
  This Streamlit app was developed to demonstrate the intersection of Large Language Models and Cybersecurity, highlighting recent surveys and providing tools and recommendations for secure coding practices.
 
2
  import pandas as pd
3
  import subprocess
4
  import time
5
+ import streamlit.components.v1 as components
6
 
7
  # ---------------------------- Header and Introduction ----------------------------
8
 
9
+ st.set_page_config(page_title="LLMs for Cyber Security", page_icon="πŸ”’", layout="wide", initial_sidebar_state="expanded")
 
 
 
 
 
 
 
 
10
  st.title("πŸ”’ LLMs for Cyber Security: State-of-the-Art Surveys")
11
+ st.markdown("This app is based on the paper: [Large Language Models for Cyber Security](https://arxiv.org/pdf/2405.04760v3). It showcases LLMs in the cybersecurity landscape, summarizing key surveys and insights.")
 
 
 
 
 
12
 
13
  # ---------------------------- Data Preparation ----------------------------
14
 
 
15
  data = {
16
+ "Reference": ["Motlagh et al.", "Divakaran et al.", "Yao et al.", "Yigit et al.", "Coelho et al.", "Novelli et al.", "LLM4Security"],
 
 
 
17
  "Year": [2024, 2024, 2023, 2024, 2024, 2024, 2024],
18
+ "Scope": ["Security application", "Security application", "Security application, Security of LLM", "Security application, Security of LLM", "Security application", "Security application", "Security application"],
19
+ "Dimensions": ["Task", "Task", "Model, Task", "Task", "Task, Domain specific technique", "Task, Model, Domain specific technique", "Model, Task, Domain specific technique, Data"],
20
+ "Time frame": ["2022-2023", "2020-2024", "2019-2024", "2020-2024", "2021-2023", "2020-2024", "2020-2024"],
 
 
 
 
 
 
 
 
 
 
21
  "Papers": ["Not specified", "Not specified", 281, "Not specified", 19, "Not specified", 127]
22
  }
 
 
23
  df = pd.DataFrame(data)
24
 
25
  # ---------------------------- Display Data Table ----------------------------
26
 
27
  st.subheader("πŸ“Š Survey Overview Table")
 
 
28
  st.dataframe(df, height=300)
 
 
29
  st.markdown("---")
30
 
31
  # ---------------------------- Mermaid Diagram Visualization ----------------------------
32
 
33
  st.subheader("πŸ›‘οΈ Security Model Visualization with Mermaid")
34
 
 
35
  mermaid_code = '''
36
  graph TD;
37
  A[LLMs in Security] --> B[Security Application]
 
41
  E --> F[Data]
42
  '''
43
 
44
+ # HTML component for Mermaid diagram
45
+ mermaid_html = f"""
46
+ <html>
47
+ <body>
48
+ <pre class="mermaid">
49
+ {mermaid_code}
50
+ </pre>
51
+ <script src="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"></script>
52
+ <script>
53
+ mermaid.initialize({{ startOnLoad: true }});
54
+ </script>
55
+ </body>
56
+ </html>
57
+ """
58
+
59
+ components.html(mermaid_html, height=300)
60
 
 
61
  st.markdown("""
62
  Figure: The diagram illustrates how Large Language Models (LLMs) are applied in security, highlighting the flow from general applications to specific tasks, models, domain-specific techniques, and data considerations.
63
  """)
64
+ st.markdown("---")
65
 
66
+ # ---------------------------- Interactive Chart Example ----------------------------
67
+
68
+ st.subheader("πŸ“ˆ Interactive Chart Example")
69
+
70
+ # Sample data for the chart
71
+ chart_data = [
72
+ {"year": 2020, "papers": 50},
73
+ {"year": 2021, "papers": 80},
74
+ {"year": 2022, "papers": 120},
75
+ {"year": 2023, "papers": 200},
76
+ {"year": 2024, "papers": 250},
77
+ ]
78
+
79
+ # HTML component for Chart.js
80
+ chart_html = f"""
81
+ <html>
82
+ <head>
83
+ <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
84
+ </head>
85
+ <body>
86
+ <canvas id="myChart" width="400" height="200"></canvas>
87
+ <script>
88
+ var ctx = document.getElementById('myChart').getContext('2d');
89
+ var myChart = new Chart(ctx, {{
90
+ type: 'line',
91
+ data: {{
92
+ labels: {[d['year'] for d in chart_data]},
93
+ datasets: [{{
94
+ label: 'Number of Papers',
95
+ data: {[d['papers'] for d in chart_data]},
96
+ borderColor: 'rgb(75, 192, 192)',
97
+ tension: 0.1
98
+ }}]
99
+ }},
100
+ options: {{
101
+ responsive: true,
102
+ scales: {{
103
+ y: {{
104
+ beginAtZero: true
105
+ }}
106
+ }}
107
+ }}
108
+ }});
109
+ </script>
110
+ </body>
111
+ </html>
112
+ """
113
+
114
+ components.html(chart_html, height=300)
115
+ st.markdown("This interactive chart shows the growth in the number of papers on LLMs in cybersecurity over the years.")
116
+ st.markdown("---")
117
+
118
+ # ---------------------------- Interactive D3.js Visualization ----------------------------
119
+
120
+ st.subheader("🌐 Interactive D3.js Visualization")
121
+
122
+ # Sample data for the D3 visualization
123
+ d3_data = [
124
+ {"name": "Task", "value": 30},
125
+ {"name": "Model", "value": 25},
126
+ {"name": "Domain-Specific", "value": 20},
127
+ {"name": "Data", "value": 15},
128
+ {"name": "Security of LLM", "value": 10},
129
+ ]
130
+
131
+ # HTML component for D3.js visualization
132
+ d3_html = f"""
133
+ <html>
134
+ <head>
135
+ <script src="https://d3js.org/d3.v7.min.js"></script>
136
+ <style>
137
+ .bar {{ fill: steelblue; }}
138
+ .bar:hover {{ fill: brown; }}
139
+ </style>
140
+ </head>
141
+ <body>
142
+ <div id="d3-chart"></div>
143
+ <script>
144
+ const data = {d3_data};
145
+ const margin = {{top: 20, right: 20, bottom: 30, left: 40}};
146
+ const width = 400 - margin.left - margin.right;
147
+ const height = 200 - margin.top - margin.bottom;
148
+
149
+ const svg = d3.select("#d3-chart")
150
+ .append("svg")
151
+ .attr("width", width + margin.left + margin.right)
152
+ .attr("height", height + margin.top + margin.bottom)
153
+ .append("g")
154
+ .attr("transform", `translate(${{margin.left}},${{margin.top}})`);
155
+
156
+ const x = d3.scaleBand()
157
+ .range([0, width])
158
+ .padding(0.1);
159
+
160
+ const y = d3.scaleLinear()
161
+ .range([height, 0]);
162
+
163
+ x.domain(data.map(d => d.name));
164
+ y.domain([0, d3.max(data, d => d.value)]);
165
+
166
+ svg.selectAll(".bar")
167
+ .data(data)
168
+ .enter().append("rect")
169
+ .attr("class", "bar")
170
+ .attr("x", d => x(d.name))
171
+ .attr("width", x.bandwidth())
172
+ .attr("y", d => y(d.value))
173
+ .attr("height", d => height - y(d.value));
174
+
175
+ svg.append("g")
176
+ .attr("transform", `translate(0,${{height}})`)
177
+ .call(d3.axisBottom(x));
178
+
179
+ svg.append("g")
180
+ .call(d3.axisLeft(y));
181
+ </script>
182
+ </body>
183
+ </html>
184
+ """
185
+
186
+ components.html(d3_html, height=300)
187
+ st.markdown("This D3.js visualization shows the distribution of different aspects in LLM cybersecurity research.")
188
  st.markdown("---")
189
 
190
  # ---------------------------- Scrollable Content for Additional Insights ----------------------------
 
191
 
192
+ st.subheader("πŸ“ Additional Insights")
193
  st.markdown("""
194
  <style>
195
  .scrollable-content {
 
199
  border: 1px solid #ccc;
200
  }
201
  </style>
 
 
 
 
202
  <div class="scrollable-content">
203
  <h4>Survey Highlights:</h4>
204
  <ul>
 
218
  </ol>
219
  </div>
220
  """, unsafe_allow_html=True)
 
 
221
  st.markdown("---")
222
 
223
  # ---------------------------- Security Audit Section ----------------------------
 
224
 
225
+ st.subheader("πŸ” Run Python Dependency Security Audit")
226
+ st.markdown("Keeping your project's dependencies secure is crucial. Use the button below to run a security audit on the Python packages used in this environment.")
 
 
227
 
 
228
  if st.button('Run pip-audit for Security Check'):
229
  with st.spinner('Running security audit...'):
 
230
  time.sleep(2)
 
231
  result = subprocess.run(['pip-audit'], capture_output=True, text=True)
 
232
  st.code(result.stdout)
233
  st.success('Security audit completed!')
234
 
235
+ st.markdown("Note: The pip-audit tool checks your Python environment for packages with known vulnerabilities, referencing public CVE databases.")
 
 
 
 
 
236
  st.markdown("---")
237
 
238
  # ---------------------------- AI Pair Programming Recommendations ----------------------------
 
239
 
240
+ st.subheader("πŸ€– AI Pair Programming: Security Recommendations")
241
  st.markdown("""
242
  Leveraging AI in pair programming can enhance code security and quality. Here are some recommendations:
243
 
 
247
  4. **Code Review Assistance**: AI can assist in code reviews by highlighting potential security issues and non-compliance with best practices.
248
  5. **Secure Coding Practices**: AI can provide real-time suggestions for secure coding patterns and discourage the use of insecure functions.
249
  """)
 
 
250
  st.markdown("---")
251
 
252
  # ---------------------------- Azure Deployment Information ----------------------------
 
253
 
254
+ st.subheader("☁️ Azure Deployment Information")
255
  st.markdown("""
256
  While this demo does not include operational deployment, here's how you can deploy this application using Azure services:
257
 
 
273
  - Multi-model database service
274
  - Low latency and high availability
275
  """)
 
 
276
  st.markdown("---")
277
 
278
  # ---------------------------- Footer and Additional Resources ----------------------------
 
279
 
280
+ st.subheader("πŸ“š Additional Resources")
281
  st.markdown("""
282
  - [Official Streamlit Documentation](https://docs.streamlit.io/)
283
  - [pip-audit GitHub Repository](https://github.com/pypa/pip-audit)
 
286
  - [Cybersecurity Best Practices by CISA](https://www.cisa.gov/cybersecurity-best-practices)
287
  """)
288
 
289
+ st.markdown("If you have any questions or would like to contribute to this project, please reach out or submit a pull request on GitHub.")
 
 
 
 
 
 
290
 
291
  # ---------------------------- Sidebar Content ----------------------------
292
+
293
  st.sidebar.title("Navigation")
294
  st.sidebar.markdown("""
295
  - [Introduction](#llms-for-cyber-security-state-of-the-art-surveys)
296
  - [Survey Overview Table](#survey-overview-table)
297
  - [Security Model Visualization](#security-model-visualization-with-mermaid)
298
+ - [Interactive Chart](#interactive-chart-example)
299
+ - [D3.js Visualization](#interactive-d3js-visualization)
300
  - [Additional Insights](#additional-insights)
301
  - [Security Audit](#run-python-dependency-security-audit)
302
  - [AI Recommendations](#ai-pair-programming-security-recommendations)
 
304
  - [Additional Resources](#additional-resources)
305
  """, unsafe_allow_html=True)
306
 
 
307
  st.sidebar.title("About")
308
  st.sidebar.info("""
309
  This Streamlit app was developed to demonstrate the intersection of Large Language Models and Cybersecurity, highlighting recent surveys and providing tools and recommendations for secure coding practices.