Spaces:
Runtime error
Runtime error
Download main.py from StudyOcean/Study-Ocean-AI_Mentor: direct link, hf CLI and curl.
- Browser
- Download file 3.4 kB
-
https://huggingface.co/spaces/StudyOcean/Study-Ocean-AI_Mentor/resolve/main/main.py
- Command line
-
hf download hf://spaces/StudyOcean/Study-Ocean-AI_Mentor/main.py
-
curl -L -o main.py https://huggingface.co/spaces/StudyOcean/Study-Ocean-AI_Mentor/resolve/main/main.py
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() | |