ss900371tw commited on
Commit
83c57cc
·
verified ·
1 Parent(s): 07423f9

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +10 -12
src/streamlit_app.py CHANGED
@@ -34,6 +34,16 @@ st.set_page_config(page_title="Cybersecurity AI Assistant (Hugging Face RAG & Ba
34
  st.title("🛡️ Meta-Llama-3-8B-Instruct with FAISS RAG & Batch Analysis (Inference Client)")
35
  st.markdown("已啟用:**IndexFlatIP** + **L2 正規化** + **Hugging Face Inference Client (API)**。上傳 JSON 執行批量分析,上傳其他檔案作為 RAG 參考庫。")
36
 
 
 
 
 
 
 
 
 
 
 
37
  # 設定模型 ID (替換為您指定的模型)
38
  MODEL_ID = "ZySec-AI/SecurityLLM"
39
  WINDOW_SIZE = 8
@@ -289,16 +299,7 @@ Based on the provided LOG SEQUENCE and REFERENCE CONTEXT, you must analyze the *
289
  # 如果模型呼叫失敗,回傳詳細錯誤訊息
290
  return f"Hugging Face Model Error: {str(e)}", context_text
291
 
292
- # === 檔案處理和主執行邏輯 (保持結構,替換 LLM 呼叫) ===
293
- # 初始化 Session State (保持不變)
294
- if 'execute_batch_analysis' not in st.session_state:
295
- st.session_state.execute_batch_analysis = False
296
- if 'batch_results' not in st.session_state:
297
- st.session_state.batch_results = None
298
 
299
- # --- 1. 處理 RAG 知識庫檔案 (rag_uploaded_file) --- (保持不變)
300
- if 'rag_current_file_key' not in st.session_state:
301
- st.session_state.rag_current_file_key = None
302
 
303
  if rag_uploaded_file:
304
  file_key = f"vs_{rag_uploaded_file.name}_{rag_uploaded_file.size}"
@@ -319,9 +320,6 @@ elif 'vector_store' in st.session_state:
319
  del st.session_state.rag_current_file_key
320
  st.info("RAG 檔案已移除,已清除相關知識庫。")
321
 
322
- # --- 2. 處理 JSON 批量分析檔案 (json_uploaded_file) --- (保持不變)
323
- if 'json_current_file_key' not in st.session_state:
324
- st.session_state.json_current_file_key = None
325
 
326
  if json_uploaded_file:
327
  json_file_key = f"json_{json_uploaded_file.name}_{json_uploaded_file.size}"
 
34
  st.title("🛡️ Meta-Llama-3-8B-Instruct with FAISS RAG & Batch Analysis (Inference Client)")
35
  st.markdown("已啟用:**IndexFlatIP** + **L2 正規化** + **Hugging Face Inference Client (API)**。上傳 JSON 執行批量分析,上傳其他檔案作為 RAG 參考庫。")
36
 
37
+
38
+ if 'execute_batch_analysis' not in st.session_state:
39
+ st.session_state.execute_batch_analysis = False
40
+ if 'batch_results' not in st.session_state:
41
+ st.session_state.batch_results = None
42
+ if 'rag_current_file_key' not in st.session_state:
43
+ st.session_state.rag_current_file_key = None
44
+ if 'json_current_file_key' not in st.session_state:
45
+ st.session_state.json_current_file_key = None
46
+
47
  # 設定模型 ID (替換為您指定的模型)
48
  MODEL_ID = "ZySec-AI/SecurityLLM"
49
  WINDOW_SIZE = 8
 
299
  # 如果模型呼叫失敗,回傳詳細錯誤訊息
300
  return f"Hugging Face Model Error: {str(e)}", context_text
301
 
 
 
 
 
 
 
302
 
 
 
 
303
 
304
  if rag_uploaded_file:
305
  file_key = f"vs_{rag_uploaded_file.name}_{rag_uploaded_file.size}"
 
320
  del st.session_state.rag_current_file_key
321
  st.info("RAG 檔案已移除,已清除相關知識庫。")
322
 
 
 
 
323
 
324
  if json_uploaded_file:
325
  json_file_key = f"json_{json_uploaded_file.name}_{json_uploaded_file.size}"