originws-app / main.py
Maurizio Dipierro
working gradio
38b9656
raw
history blame
1.49 kB
import argparse
import logging
from document_handler import load_documents_from_disk, load_documents_from_sitemap, save_documents_to_disk
from vectorstore_handler import load_or_create_vectorstore, get_embeddings
from query_executor import execute_query
# Configure logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s', handlers=[
logging.FileHandler("query_executor.log"),
logging.StreamHandler()
])
def main(query):
# Path to save the documents
sitemap_url = "https://www.originws.it/page-sitemap.xml"
docs_file_path = 'sitemap_docs.pkl'
# Try to load documents from disk
docs = load_documents_from_disk(docs_file_path)
if docs is None:
logging.info("Documents not found on disk, loading from sitemap...")
# Load documents using SitemapLoader
docs = load_documents_from_sitemap(sitemap_url)
save_documents_to_disk(docs, docs_file_path)
logging.info("Documents saved to disk.")
else:
logging.info("Documents loaded from disk.")
# Get embeddings and load/create the vectorstore
embeddings = get_embeddings()
vectorstore = load_or_create_vectorstore(docs, embeddings)
# Now that the vectorstore is ready, let's query it
question = query
logging.info(f"Executing query: {question}")
response = execute_query(question, vectorstore)
# Log the response
logging.info(f"Query response: {response}")
return response