Spaces:
Sleeping
Sleeping
epowell101
commited on
Commit
·
7e4120a
1
Parent(s):
c484c91
several imporvements
Browse files
app.py
CHANGED
|
@@ -10,9 +10,16 @@ required_columns = [
|
|
| 10 |
'Avg forward segment size', 'Avg backward segment size'
|
| 11 |
]
|
| 12 |
|
|
|
|
|
|
|
|
|
|
| 13 |
# Streamlit UI
|
| 14 |
st.title("NetFlow Log Comparison Tool")
|
| 15 |
-
st.write("Compare your NetFlow logs against Sigma rules or MITRE ATT&CK patterns using RAG.")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
# Instructions for data upload
|
| 18 |
st.markdown("""
|
|
@@ -22,9 +29,17 @@ st.markdown("""
|
|
| 22 |
- You can upload **up to 5 rows** for analysis.
|
| 23 |
""")
|
| 24 |
|
| 25 |
-
# Display required schema for users
|
| 26 |
st.write("### Required NetFlow Schema:")
|
| 27 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
# Step 1: File Upload
|
| 30 |
uploaded_file = st.file_uploader("Upload your NetFlow log sequence CSV file", type="csv")
|
|
@@ -34,7 +49,12 @@ hugging_face_api_token = st.text_input("Enter your Hugging Face API Token", type
|
|
| 34 |
if not hugging_face_api_token:
|
| 35 |
st.warning("Please provide a Hugging Face API Token to proceed.")
|
| 36 |
|
| 37 |
-
# Step 3:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
if uploaded_file and hugging_face_api_token:
|
| 39 |
# Read and display the file using CSV module
|
| 40 |
csv_file = StringIO(uploaded_file.getvalue().decode("utf-8"))
|
|
@@ -54,8 +74,7 @@ if uploaded_file and hugging_face_api_token:
|
|
| 54 |
# Prepare data for Hugging Face API call
|
| 55 |
input_texts = [f"{row}" for row in csv_data] # Convert each row to a string for comparison
|
| 56 |
|
| 57 |
-
#
|
| 58 |
-
HUGGING_FACE_API_URL = "https://api-inference.huggingface.co/models/sentence-transformers/all-distilroberta-v1"
|
| 59 |
headers = {"Authorization": f"Bearer {hugging_face_api_token}"}
|
| 60 |
|
| 61 |
try:
|
|
@@ -66,7 +85,14 @@ if uploaded_file and hugging_face_api_token:
|
|
| 66 |
# Display the results
|
| 67 |
st.write("### Comparison Results")
|
| 68 |
comparison_results = response.json()
|
| 69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
except requests.exceptions.RequestException as e:
|
| 72 |
st.error(f"Error calling Hugging Face API: {str(e)}")
|
|
@@ -84,7 +110,7 @@ st.write("We value your feedback. [Fill out our survey](https://docs.google.com/
|
|
| 84 |
# Footer
|
| 85 |
st.markdown("---")
|
| 86 |
st.write("This free site is maintained by DeepTempo.")
|
| 87 |
-
# st.image("Final_DeepTempo_logo.png", width=300) # Adjust the path and width as needed 'Final DeepTempo logo.png
|
| 88 |
st.write("[Visit DeepTempo.ai](https://deeptempo.ai)")
|
| 89 |
st.write("[Check out the underlying code on GitHub](https://github.com/deepsecoss)")
|
| 90 |
|
|
|
|
| 10 |
'Avg forward segment size', 'Avg backward segment size'
|
| 11 |
]
|
| 12 |
|
| 13 |
+
# Hugging Face API Settings
|
| 14 |
+
HUGGING_FACE_API_URL = "https://api-inference.huggingface.co/models/sentence-transformers/all-distilroberta-v1"
|
| 15 |
+
|
| 16 |
# Streamlit UI
|
| 17 |
st.title("NetFlow Log Comparison Tool")
|
| 18 |
+
st.write("Compare your NetFlow logs against Sigma rules or MITRE ATT&CK patterns using Retrieval-Augmented Generation (RAG).")
|
| 19 |
+
|
| 20 |
+
# Display the embedding model being used
|
| 21 |
+
st.write("### Embedding Model in Use")
|
| 22 |
+
st.write("The model used for embedding is: **All-DistilRoBERTa-V1**")
|
| 23 |
|
| 24 |
# Instructions for data upload
|
| 25 |
st.markdown("""
|
|
|
|
| 29 |
- You can upload **up to 5 rows** for analysis.
|
| 30 |
""")
|
| 31 |
|
| 32 |
+
# Display required schema for users with bullet points
|
| 33 |
st.write("### Required NetFlow Schema:")
|
| 34 |
+
st.markdown("""
|
| 35 |
+
- **Flow duration**
|
| 36 |
+
- **Source port**
|
| 37 |
+
- **Destination port**
|
| 38 |
+
- **Total forward packets**
|
| 39 |
+
- **Total backward packets**
|
| 40 |
+
- **Avg forward segment size**
|
| 41 |
+
- **Avg backward segment size**
|
| 42 |
+
""")
|
| 43 |
|
| 44 |
# Step 1: File Upload
|
| 45 |
uploaded_file = st.file_uploader("Upload your NetFlow log sequence CSV file", type="csv")
|
|
|
|
| 49 |
if not hugging_face_api_token:
|
| 50 |
st.warning("Please provide a Hugging Face API Token to proceed.")
|
| 51 |
|
| 52 |
+
# Step 3: Model and Comparison Options
|
| 53 |
+
st.write("### Model and Comparison Options")
|
| 54 |
+
llm_choice = st.selectbox("Select LLM", ["All-DistilRoBERTa-V1"]) # Add other models as necessary
|
| 55 |
+
comparison_choice = st.selectbox("Select Comparison Type", ["Mitre", "Sigma"])
|
| 56 |
+
|
| 57 |
+
# Step 4: Run Comparison if File Uploaded and Token Provided
|
| 58 |
if uploaded_file and hugging_face_api_token:
|
| 59 |
# Read and display the file using CSV module
|
| 60 |
csv_file = StringIO(uploaded_file.getvalue().decode("utf-8"))
|
|
|
|
| 74 |
# Prepare data for Hugging Face API call
|
| 75 |
input_texts = [f"{row}" for row in csv_data] # Convert each row to a string for comparison
|
| 76 |
|
| 77 |
+
# Call Hugging Face API
|
|
|
|
| 78 |
headers = {"Authorization": f"Bearer {hugging_face_api_token}"}
|
| 79 |
|
| 80 |
try:
|
|
|
|
| 85 |
# Display the results
|
| 86 |
st.write("### Comparison Results")
|
| 87 |
comparison_results = response.json()
|
| 88 |
+
|
| 89 |
+
# Sort and extract top 3 results for display
|
| 90 |
+
top_results = sorted(comparison_results, key=lambda x: x['score'], reverse=True)[:3]
|
| 91 |
+
|
| 92 |
+
# Display the top 3 results
|
| 93 |
+
for idx, result in enumerate(top_results):
|
| 94 |
+
st.write(f"**{idx + 1}.** Matched Sequence: `{result['sequence']}`")
|
| 95 |
+
st.write(f" - **Cosine Similarity Score**: {result['score']:.4f}")
|
| 96 |
|
| 97 |
except requests.exceptions.RequestException as e:
|
| 98 |
st.error(f"Error calling Hugging Face API: {str(e)}")
|
|
|
|
| 110 |
# Footer
|
| 111 |
st.markdown("---")
|
| 112 |
st.write("This free site is maintained by DeepTempo.")
|
| 113 |
+
# st.image("Final_DeepTempo_logo.png", width=300) # Adjust the path and width as needed 'Final DeepTempo logo.png'
|
| 114 |
st.write("[Visit DeepTempo.ai](https://deeptempo.ai)")
|
| 115 |
st.write("[Check out the underlying code on GitHub](https://github.com/deepsecoss)")
|
| 116 |
|