Upload app.py
Browse files
app.py
CHANGED
|
@@ -14,10 +14,15 @@ import streamlit as st
|
|
| 14 |
from pathlib import Path
|
| 15 |
from typing import Dict, Any, Optional
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
from src.full_pipeline.simple_pipeline import analyze_log_file
|
| 18 |
|
| 19 |
from dotenv import load_dotenv
|
| 20 |
from huggingface_hub import login as huggingface_login
|
|
|
|
| 21 |
|
| 22 |
load_dotenv()
|
| 23 |
|
|
@@ -109,11 +114,33 @@ def run_analysis(
|
|
| 109 |
return {"success": False, "error": str(e)}
|
| 110 |
|
| 111 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
def main():
|
| 113 |
"""Main Streamlit app."""
|
| 114 |
|
| 115 |
-
|
| 116 |
-
|
| 117 |
|
| 118 |
st.set_page_config(
|
| 119 |
page_title="Cybersecurity Agent Pipeline", page_icon="🛡️", layout="wide"
|
|
|
|
| 14 |
from pathlib import Path
|
| 15 |
from typing import Dict, Any, Optional
|
| 16 |
|
| 17 |
+
# Add project root to path for agent imports
|
| 18 |
+
project_root = Path(__file__).parent
|
| 19 |
+
sys.path.insert(0, str(project_root))
|
| 20 |
+
|
| 21 |
from src.full_pipeline.simple_pipeline import analyze_log_file
|
| 22 |
|
| 23 |
from dotenv import load_dotenv
|
| 24 |
from huggingface_hub import login as huggingface_login
|
| 25 |
+
from huggingface_hub.utils import HfHubHTTPError
|
| 26 |
|
| 27 |
load_dotenv()
|
| 28 |
|
|
|
|
| 114 |
return {"success": False, "error": str(e)}
|
| 115 |
|
| 116 |
|
| 117 |
+
@st.cache_resource
|
| 118 |
+
def initialize_hf_login():
|
| 119 |
+
"""Initialize Hugging Face login only once."""
|
| 120 |
+
hf_token = os.getenv("HF_TOKEN")
|
| 121 |
+
if hf_token:
|
| 122 |
+
try:
|
| 123 |
+
# Check if already logged in by trying to get user info
|
| 124 |
+
from huggingface_hub import whoami
|
| 125 |
+
|
| 126 |
+
whoami()
|
| 127 |
+
return True
|
| 128 |
+
except (HfHubHTTPError, Exception):
|
| 129 |
+
# Not logged in, try to login
|
| 130 |
+
try:
|
| 131 |
+
huggingface_login(token=hf_token)
|
| 132 |
+
return True
|
| 133 |
+
except Exception as e:
|
| 134 |
+
st.warning(f"Failed to login to Hugging Face: {e}")
|
| 135 |
+
return False
|
| 136 |
+
return False
|
| 137 |
+
|
| 138 |
+
|
| 139 |
def main():
|
| 140 |
"""Main Streamlit app."""
|
| 141 |
|
| 142 |
+
# Initialize HF login (cached)
|
| 143 |
+
initialize_hf_login()
|
| 144 |
|
| 145 |
st.set_page_config(
|
| 146 |
page_title="Cybersecurity Agent Pipeline", page_icon="🛡️", layout="wide"
|