| import streamlit as st |
| import pandas as pd |
| import subprocess |
| import time |
| import random |
| import streamlit.components.v1 as components |
|
|
| |
|
|
| def generate_ner_data(): |
| |
| data_person = [{"text": f"Person example {i}", "entities": [{"entity": "Person", "value": f"Person {i}"}]} for i in range(1, 21)] |
| data_organization = [{"text": f"Organization example {i}", "entities": [{"entity": "Organization", "value": f"Organization {i}"}]} for i in range(1, 21)] |
| data_location = [{"text": f"Location example {i}", "entities": [{"entity": "Location", "value": f"Location {i}"}]} for i in range(1, 21)] |
| data_date = [{"text": f"Date example {i}", "entities": [{"entity": "Date", "value": f"Date {i}"}]} for i in range(1, 21)] |
| data_product = [{"text": f"Product example {i}", "entities": [{"entity": "Product", "value": f"Product {i}"}]} for i in range(1, 21)] |
| |
| |
| ner_data = { |
| "Person": data_person, |
| "Organization": data_organization, |
| "Location": data_location, |
| "Date": data_date, |
| "Product": data_product |
| } |
| |
| return ner_data |
|
|
| |
|
|
| def ner_demo(): |
| st.header("π€ LLM NER Model Demo π΅οΈββοΈ") |
| |
| |
| ner_data = generate_ner_data() |
|
|
| |
| entity_type = random.choice(list(ner_data.keys())) |
| st.subheader(f"Here comes the {entity_type} entity recognition, ready to show its magic! π©β¨") |
|
|
| |
| example = random.choice(ner_data[entity_type]) |
| st.write(f"Analyzing: *{example['text']}*") |
| |
| |
| for entity in example["entities"]: |
| st.success(f"π Found a {entity['entity']}: **{entity['value']}**") |
| |
| |
| st.write("There once was an AI so bright, π") |
| st.write("It could spot any name in sight, ποΈ") |
| st.write("With a click or a tap, it put on its cap, π©") |
| st.write("And found entities day or night! π") |
|
|
| |
|
|
| st.set_page_config(page_title="LLMs for Cyber Security", page_icon="π", layout="wide", initial_sidebar_state="expanded") |
| st.title("ππ LLMs for Cyber Security: State-of-the-Art Surveysππ") |
| 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.") |
| st.markdown('ππ https://arxiv.org/abs/2405.04760v3') |
| st.markdown("---") |
|
|
| |
|
|
| if st.button('π§ͺ Run NER Model Demo'): |
| ner_demo() |
| else: |
| st.write("Click the button above to start the AI NER magic! π©β¨") |
|
|
| |
|
|
| data = { |
| "Reference": ["Motlagh et al.", "Divakaran et al.", "Yao et al.", "Yigit et al.", "Coelho et al.", "Novelli et al.", "LLM4Security"], |
| "Year": [2024, 2024, 2023, 2024, 2024, 2024, 2024], |
| "Scope": ["Security application", "Security application", "Security application, Security of LLM", "Security application, Security of LLM", "Security application", "Security application", "Security application"], |
| "Dimensions": ["Task", "Task", "Model, Task", "Task", "Task, Domain specific technique", "Task, Model, Domain specific technique", "Model, Task, Domain specific technique, Data"], |
| "Time frame": ["2022-2023", "2020-2024", "2019-2024", "2020-2024", "2021-2023", "2020-2024", "2020-2024"], |
| "Papers": ["Not specified", "Not specified", 281, "Not specified", 19, "Not specified", 127] |
| } |
| df = pd.DataFrame(data) |
|
|
| |
|
|
| st.subheader("π Survey Overview Table") |
| st.dataframe(df, height=300) |
| st.markdown("---") |
|
|
| |
|
|
| st.subheader("π‘οΈ Security Model Visualization with Mermaid") |
|
|
| mermaid_code = ''' |
| graph TD; |
| A[LLMs in Security] --> B[Security Application] |
| B --> C[Task] |
| B --> D[Model] |
| D --> E[Domain-Specific Techniques] |
| E --> F[Data] |
| ''' |
|
|
| |
| mermaid_html = f""" |
| <html> |
| <body> |
| <pre class="mermaid"> |
| {mermaid_code} |
| </pre> |
| <script src="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"></script> |
| <script> |
| mermaid.initialize({{ startOnLoad: true }}); |
| </script> |
| </body> |
| </html> |
| """ |
|
|
| components.html(mermaid_html, height=300) |
|
|
| st.markdown(""" |
| 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. |
| """) |
| st.markdown("---") |
|
|
| |
|
|
| st.subheader("π Interactive Chart Example") |
|
|
| |
| chart_data = [ |
| {"year": 2020, "papers": 50}, |
| {"year": 2021, "papers": 80}, |
| {"year": 2022, "papers": 120}, |
| {"year": 2023, "papers": 200}, |
| {"year": 2024, "papers": 250}, |
| ] |
|
|
| |
| chart_html = f""" |
| <html> |
| <head> |
| <script src="https://cdn.jsdelivr.net/npm/chart.js"></script> |
| </head> |
| <body> |
| <canvas id="myChart" width="400" height="200"></canvas> |
| <script> |
| var ctx = document.getElementById('myChart').getContext('2d'); |
| var myChart = new Chart(ctx, {{ |
| type: 'line', |
| data: {{ |
| labels: {[d['year'] for d in chart_data]}, |
| datasets: [{{ |
| label: 'Number of Papers', |
| data: {[d['papers'] for d in chart_data]}, |
| borderColor: 'rgb(75, 192, 192)', |
| tension: 0.1 |
| }}] |
| }}, |
| options: {{ |
| responsive: true, |
| scales: {{ |
| y: {{ |
| beginAtZero: true |
| }} |
| }} |
| }} |
| }}); |
| </script> |
| </body> |
| </html> |
| """ |
|
|
| components.html(chart_html, height=300) |
| st.markdown("This interactive chart shows the growth in the number of papers on LLMs in cybersecurity over the years.") |
| st.markdown("---") |
|
|
| |
|
|
| st.subheader("π Additional Resources") |
| st.markdown(""" |
| - [Official Streamlit Documentation](https://docs.streamlit.io/) |
| - [pip-audit GitHub Repository](https://github.com/pypa/pip-audit) |
| - [Mermaid Live Editor](https://mermaid.live/) - Design and preview Mermaid diagrams. |
| - [Azure Container Apps Documentation](https://docs.microsoft.com/en-us/azure/container-apps/) |
| - [Cybersecurity Best Practices by CISA](https://www.cisa.gov/cybersecurity-best-practices) |
| """) |
| st.markdown("---") |
|
|
| |
|
|
| st.sidebar.title("Navigation") |
| st.sidebar.markdown(""" |
| - [Introduction](#llms-for-cyber-security-state-of-the-art-surveys) |
| - [Survey Overview Table](#survey-overview-table) |
| - [Security Model Visualization](#security-model-visualization-with-mermaid) |
| - [Interactive Chart](#interactive-chart-example) |
| - [Additional Resources](#additional-resources) |
| """, unsafe_allow_html=True) |
|
|
| st.sidebar.title("About") |
| st.sidebar.info(""" |
| 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. |
| """) |
|
|
| |
|
|
| |
|
|
| |
| |
| |
|
|