Mohit Raj
Sync from GitHub via hub-sync
030f984 verified
Raw History Blame Contribute Delete
3.4 kB
"""
Study Ocean RAG β€” Main Entry Point
Usage:
python main.py ingest # Ingest PDFs and build vector store
python main.py chat # Launch the Gradio web UI
python main.py ask # Ask a single question in the terminal
"""
import sys
def print_banner():
print("""
╔══════════════════════════════════════════════════════════╗
β•‘ πŸŽ“ Study Ocean AI Mentor β•‘
β•‘ RAG-based Student Doubt Solver β•‘
╠══════════════════════════════════════════════════════════╣
β•‘ β•‘
β•‘ Commands: β•‘
β•‘ python main.py ingest β€” Process PDFs & build index β•‘
β•‘ python main.py chat β€” Launch web chat interface β•‘
β•‘ python main.py ask β€” Ask a question in terminal β•‘
β•‘ β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•
""")
def run_ingest():
"""Run the PDF ingestion pipeline."""
from ingest import run_ingestion
run_ingestion()
def run_chat():
"""Launch the Gradio web interface."""
from app import app
print("\n🌐 Starting Study Ocean AI Mentor web interface...")
print(" Open http://localhost:7860 in your browser\n")
app.launch(
server_name="0.0.0.0",
server_port=7860,
share=False,
show_error=True,
)
def run_ask():
"""Interactive terminal Q&A mode."""
from rag_chain import get_chain, ask_question
print("\nπŸŽ“ Study Ocean AI Mentor β€” Terminal Mode")
print(" Type your question and press Enter.")
print(" Type 'quit' or 'exit' to stop.\n")
chain = get_chain()
while True:
try:
question = input("\nπŸ™‹ Your doubt: ").strip()
except (KeyboardInterrupt, EOFError):
print("\n\nπŸ‘‹ Goodbye! Keep studying! πŸ“š")
break
if question.lower() in ("quit", "exit", "q"):
print("\nπŸ‘‹ Goodbye! Keep studying! πŸ“š")
break
if not question:
print(" ⚠ Please type a question.")
continue
print("\nπŸ” Searching study material...\n")
result = ask_question(chain, question)
print("─" * 50)
print(f"\nπŸŽ“ Mentor's Answer:\n")
print(result["answer"])
if result["sources"]:
print(f"\nπŸ“– Sources:")
for i, src in enumerate(result["sources"], 1):
print(f" {i}. [{src['subject']}] {src['file']}")
print("\n" + "─" * 50)
def main():
if len(sys.argv) < 2:
print_banner()
sys.exit(0)
command = sys.argv[1].lower()
if command == "ingest":
run_ingest()
elif command == "chat":
run_chat()
elif command == "ask":
run_ask()
else:
print(f"❌ Unknown command: {command}")
print_banner()
sys.exit(1)
if __name__ == "__main__":
main()