| import os |
| import sys |
| from pathlib import Path |
|
|
| |
| |
| |
| sys.path.insert(0, "src") |
|
|
| print("π Initializing IKS RAG System on HuggingFace Spaces...") |
|
|
| |
| print(f"Python Version: {sys.version}") |
| print(f"CWD: {os.getcwd()}") |
|
|
| |
| try: |
| from iks_rag.ui.gradio_app import create_interface |
| from iks_rag.rag_system import create_rag_system |
| print("β
Successfully imported iks_rag modules") |
| except ImportError as e: |
| print(f"β ERROR: Failed to import iks_rag modules: {e}") |
| print(f"Python path: {sys.path}") |
| |
| import gradio as gr |
| demo = gr.Interface(fn=lambda x: f"Import Error: {e}", inputs="text", outputs="text") |
| demo.launch() |
| sys.exit(1) |
|
|
| |
| api_key = os.environ.get("GOOGLE_API_KEY", "") |
| if not api_key: |
| print("β οΈ WARNING: GOOGLE_API_KEY not found in environment variables!") |
| print("Please set GOOGLE_API_KEY in the 'Settings > Secrets' section of your Space.") |
|
|
| |
| config_path = "configs/rag/default.yaml" |
| if not os.path.exists(config_path): |
| print(f"β ERROR: Config file not found at {config_path}") |
| else: |
| print(f"β
Found config at {config_path}") |
|
|
| try: |
| rag_system = create_rag_system(config_path) |
| print("β
RAG system initialized") |
| except Exception as e: |
| print(f"β ERROR initializing RAG system: {e}") |
| rag_system = None |
|
|
| |
| if rag_system: |
| docs_path = "data/documents" |
| if not os.path.exists(docs_path) or not os.listdir(docs_path): |
| print(f"β οΈ WARNING: No documents found in {docs_path}") |
| else: |
| print(f"π Loading documents from {docs_path}...") |
|
|
| try: |
| rag_system.load_documents() |
| stats = rag_system.get_stats() |
| print(f"β
Loaded {stats['documents_loaded']} document chunks into ChromaDB") |
| except Exception as e: |
| print(f"β ERROR loading documents: {str(e)}") |
|
|
| |
| print("π Launching Gradio Interface...") |
| if rag_system: |
| demo = create_interface(rag_system) |
| else: |
| import gradio as gr |
| demo = gr.Interface(fn=lambda x: "RAG System failed to initialize", inputs="text", outputs="text") |
|
|
| if __name__ == "__main__": |
| demo.launch() |
|
|