import gradio as gr from pdf_loader import load_pdf_from_url from vector_store import create_vector_store from rag_pipeline import rag_answer vector_store = None def ingest_pdfs(pdf_links): global vector_store all_text = "" links = [l for l in pdf_links.split("\n") if l.strip()] try: for link in links: all_text += load_pdf_from_url(link) vector_store = create_vector_store(all_text) return "✅ Knowledge base created successfully for you!" except Exception as e: return f"❌ Error while ingesting PDFs:\n{str(e)}" def ask_question(question): if vector_store is None: return "⚠️ Please ingest documents first." return rag_answer(vector_store, question) with gr.Blocks(theme=gr.themes.Soft()) as demo: gr.Markdown( """ # 📚 RAG App using Groq + FAISS **Upload your knowledge via PDF links and chat with it** """ ) with gr.Row(): pdf_input = gr.Textbox( label="Google Drive PDF Links (one per line)", lines=5, placeholder="https://drive.google.com/uc?id=..." ) ingest_btn = gr.Button("📥 Build Knowledge Base") status = gr.Textbox(label="Status") ingest_btn.click( ingest_pdfs, inputs=pdf_input, outputs=status ) gr.Markdown("## 💬 Ask Questions") question = gr.Textbox( label="Your Question", placeholder="Ask something from the documents..." ) answer = gr.Textbox(label="Answer", lines=6) question.submit( ask_question, inputs=question, outputs=answer ) demo.launch()