# GenAI Program g8 - PDF / IPC document chatbot (PyMuPDF)
!pip install pymupdf

import fitz

def extract(file):
    text = ""
    with fitz.open(file) as pdf:
        for page in pdf:
            text += page.get_text()
    return text

def search(query, ipc):
    query = query.lower()
    results = [line for line in ipc.split("\n") if query in line.lower()]
    return results if results else ["No relevant section found."]

def chatbot():
    print("Loading IPC document...")
    ipc = extract("IPC.pdf")
    print("Chatbot ready! Type 'exit' to quit.\n")
    while True:
        query = input("Ask a question about the IPC: ")
        if query.lower() == "exit":
            print("Goodbye!")
            break
        print("\n".join(search(query, ipc)))
        print("-" * 50)

chatbot()
