Spaces:
Runtime error
Runtime error
File size: 3,401 Bytes
030f984 | 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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | """
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()
|