Spaces:
Sleeping
Sleeping
Download cli.py from veltrixcode/businesslawrag: direct link, hf CLI and curl.
- Browser
- Download file 1.75 kB
-
https://huggingface.co/spaces/veltrixcode/businesslawrag/resolve/main/cli.py
- Command line
-
hf download hf://spaces/veltrixcode/businesslawrag/cli.py
-
curl -L -o cli.py https://huggingface.co/spaces/veltrixcode/businesslawrag/resolve/main/cli.py
1.75 kB
| #!/usr/bin/env python3 | |
| import os | |
| import sys | |
| from dotenv import load_dotenv | |
| from src.retriever import HybridLegalRetriever | |
| from src.rag_engine import LegalRAGEngine | |
| load_dotenv() | |
| def main(): | |
| print("⚖️ Initializing ICAI Business Laws Deep RAG System...") | |
| retriever = HybridLegalRetriever(persist_dir="data/index") | |
| engine = LegalRAGEngine(retriever) | |
| print("\n✅ System Ready! Ask any complex question from the book.") | |
| print("Type 'exit' or 'quit' to stop.\n") | |
| provider = os.getenv("RAG_PROVIDER", "gemini" if os.getenv("GEMINI_API_KEY") else ("openai" if os.getenv("OPENAI_API_KEY") else "mock")) | |
| while True: | |
| try: | |
| query = input("❓ Enter your legal question: ").strip() | |
| if not query: | |
| continue | |
| if query.lower() in ["exit", "quit", "q"]: | |
| print("Goodbye!") | |
| break | |
| print("\n🔍 Retrieving exact book sections and reasoning...\n") | |
| result = engine.answer_query( | |
| query=query, | |
| top_k=5, | |
| provider=provider | |
| ) | |
| print("==================== ANSWER ====================") | |
| print(result["answer"]) | |
| print("\n================ EXACT SOURCES =================") | |
| for i, src in enumerate(result["retrieved_chunks"], 1): | |
| print(f"[{i}] {src['title']} ({src['chapter']}) — Page {src['page_number']} | Score: {src['retrieval_score']}") | |
| print("================================================\n") | |
| except (KeyboardInterrupt, EOFError): | |
| print("\nExiting.") | |
| break | |
| if __name__ == "__main__": | |
| main() | |