Spaces:
Sleeping
Sleeping
File size: 2,198 Bytes
2ed2129 821284f 2ed2129 821284f 2ed2129 821284f 2ed2129 821284f 2ed2129 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
import sys
import os
from pathlib import Path
import subprocess
import logging
project_root = Path(__file__).parent.parent.parent
if str(project_root) not in sys.path:
sys.path.append(str(project_root))
from course_search.search_system.data_pipeline import DataPipeline
from course_search.search_system.rag_system import RAGSystem
# Setup logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
def setup_paths():
"""Setup necessary paths and directories"""
project_root = Path(__file__).parent.parent.parent
if str(project_root) not in sys.path:
sys.path.append(str(project_root))
data_dir = project_root / 'data'
data_dir.mkdir(exist_ok=True)
return project_root, data_dir
def main():
try:
# Setup paths
project_root, data_dir = setup_paths()
# Create cache directory
cache_dir = data_dir / 'cache'
cache_dir.mkdir(exist_ok=True)
# Run data pipeline
logger.info("Running data pipeline...")
pipeline = DataPipeline()
df = pipeline.run_pipeline(
save_path=str(data_dir / 'courses.pkl'),
force_scrape=False # Set to True to force new scraping
)
# Initialize RAG system with caching
rag_system = RAGSystem()
rag_system.load_and_process_data(df, cache_dir=cache_dir)
# Run Gradio app
logger.info("Starting Gradio app...")
gradio_path = Path(__file__).parent / 'gradio_app.py'
if not gradio_path.exists():
raise FileNotFoundError(f"Gradio app not found at: {gradio_path}")
# Change to project root directory before running
os.chdir(str(project_root))
# Run Gradio with proper Python path
env = os.environ.copy()
env['PYTHONPATH'] = str(project_root)
subprocess.run(
['python', str(gradio_path)],
env=env,
check=True
)
except Exception as e:
logger.error(f"Error running application: {str(e)}")
raise
if __name__ == "__main__":
main() |