Update app.py
Browse files
app.py
CHANGED
|
@@ -6,8 +6,53 @@ import requests
|
|
| 6 |
import gradio as gr
|
| 7 |
from dotenv import load_dotenv
|
| 8 |
from datasets import load_dataset
|
| 9 |
-
|
| 10 |
-
from
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
from langchain_community.retrievers import BM25Retriever
|
| 12 |
|
| 13 |
# Load environment variables
|
|
@@ -624,6 +669,5 @@ if __name__ == "__main__":
|
|
| 624 |
print(" - search_cve_database: Search CVE knowledge base")
|
| 625 |
print(" - get_nvd_cve_details: Fetch detailed CVE info from NVD")
|
| 626 |
print(" - π search_and_fetch_cve_details: Smart combined RAG + NVD analysis")
|
| 627 |
-
print(" - simple_cve_search: Simple CVE search for multi-agent workflow")
|
| 628 |
|
| 629 |
demo.launch(mcp_server=True)
|
|
|
|
| 6 |
import gradio as gr
|
| 7 |
from dotenv import load_dotenv
|
| 8 |
from datasets import load_dataset
|
| 9 |
+
try:
|
| 10 |
+
from langchain_core.documents import Document
|
| 11 |
+
except ImportError:
|
| 12 |
+
try:
|
| 13 |
+
from langchain.docstore.document import Document
|
| 14 |
+
except ImportError:
|
| 15 |
+
try:
|
| 16 |
+
from langchain.schema import Document
|
| 17 |
+
except ImportError:
|
| 18 |
+
# Fallback: Create a simple Document class
|
| 19 |
+
class Document:
|
| 20 |
+
def __init__(self, page_content: str, metadata: dict = None):
|
| 21 |
+
self.page_content = page_content
|
| 22 |
+
self.metadata = metadata or {}
|
| 23 |
+
|
| 24 |
+
# Import RecursiveCharacterTextSplitter with fallback
|
| 25 |
+
RecursiveCharacterTextSplitter = None
|
| 26 |
+
|
| 27 |
+
try:
|
| 28 |
+
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
| 29 |
+
print("β
Using langchain.text_splitter.RecursiveCharacterTextSplitter")
|
| 30 |
+
except ImportError:
|
| 31 |
+
try:
|
| 32 |
+
from langchain_text_splitters import RecursiveCharacterTextSplitter
|
| 33 |
+
print("β
Using langchain_text_splitters.RecursiveCharacterTextSplitter")
|
| 34 |
+
except ImportError:
|
| 35 |
+
print("β οΈ Using fallback RecursiveCharacterTextSplitter")
|
| 36 |
+
# Fallback: Simple text splitter
|
| 37 |
+
class RecursiveCharacterTextSplitter:
|
| 38 |
+
def __init__(self, chunk_size=500, chunk_overlap=50, **kwargs):
|
| 39 |
+
self.chunk_size = chunk_size
|
| 40 |
+
self.chunk_overlap = chunk_overlap
|
| 41 |
+
print(f"π Initialized fallback text splitter with chunk_size={chunk_size}")
|
| 42 |
+
|
| 43 |
+
def split_documents(self, documents):
|
| 44 |
+
"""Simple document splitting fallback"""
|
| 45 |
+
print(f"π Splitting {len(documents)} documents using fallback method...")
|
| 46 |
+
result = []
|
| 47 |
+
for doc in documents:
|
| 48 |
+
text = doc.page_content
|
| 49 |
+
# Simple chunking
|
| 50 |
+
for i in range(0, len(text), self.chunk_size - self.chunk_overlap):
|
| 51 |
+
chunk = text[i:i + self.chunk_size]
|
| 52 |
+
if chunk.strip():
|
| 53 |
+
result.append(Document(page_content=chunk, metadata=doc.metadata))
|
| 54 |
+
print(f"β
Split into {len(result)} chunks")
|
| 55 |
+
return result
|
| 56 |
from langchain_community.retrievers import BM25Retriever
|
| 57 |
|
| 58 |
# Load environment variables
|
|
|
|
| 669 |
print(" - search_cve_database: Search CVE knowledge base")
|
| 670 |
print(" - get_nvd_cve_details: Fetch detailed CVE info from NVD")
|
| 671 |
print(" - π search_and_fetch_cve_details: Smart combined RAG + NVD analysis")
|
|
|
|
| 672 |
|
| 673 |
demo.launch(mcp_server=True)
|