import os
import sys

# Ensure preprocess.py is in the same directory
sys.path.append(os.path.dirname(__file__))

# Import preprocess function
from preprocess import preprocess

# Check if precomputed files exist and run preprocessing if needed
if not (os.path.exists("chunks.pkl") and os.path.exists("index.faiss")):
    print("Precomputed files missing. Running preprocess.py...")
    preprocess()
else:
    print("Precomputed files found. Skipping preprocessing.")

# Import and run app.py
print("Starting app.py...")
from app import demo
demo.launch()