Spaces:
Sleeping
Sleeping
Delete app.py
Browse files1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495"""QueryVault - Gradio Web InterfaceRun this file to launch the QA bot in your browser.
Usage: python app.py"""
import gradio as grfrom dotenv import load_dotenvfrom src.qabot import process_pdf_and_query
# Load environment variables from .env fileload_dotenv()
# ---------------------------------------------------------------------------# Gradio Interface# ---------------------------------------------------------------------------
def answer_question(pdf_file, question: str) -> str: """ Wrapper called by Gradio on each user interaction.
Args: pdf_file: Gradio file object (has a .name attribute with the temp path). question: User's question string.
Returns: Answer string to display in the output box. """ if pdf_file is None: return "β οΈ Please upload a PDF document before asking a question."
file_path = pdf_file.name # Gradio stores uploaded files at a temp path return process_pdf_and_query(file_path, question)
# ---------------------------------------------------------------------------# UI Layout# ---------------------------------------------------------------------------
with gr.Blocks( title="QueryVault β PDF QA Bot") as demo:
gr.Markdown( """ # π QueryVault β PDF Question Answering Bot Upload a PDF document, ask any question about its content, and get an intelligent answer powered by **Groq API (Llama-3.3 70B)** and **LangChain RAG**. """ )
with gr.Row(): with gr.Column(scale=1): pdf_input = gr.File( label="π Upload PDF", file_types=[".pdf"], type="filepath", ) question_input = gr.Textbox( label="β Your Question", placeholder="e.g. What are the main findings of this document?", lines=3, ) submit_btn = gr.Button("π Get Answer", variant="primary")
with gr.Column(scale=1): answer_output = gr.Textbox( label="π‘ Answer", lines=12, interactive=False, )
submit_btn.click( fn=answer_question, inputs=[pdf_input, question_input], outputs=answer_output, )
gr.Markdown( """ --- **How it works:** 1. Your PDF is parsed and split into chunks. 2. Each chunk is converted to a semantic embedding via HuggingFace Local Embeddings (`all-MiniLM-L6-v2`). 3. The most relevant chunks are retrieved using ChromaDB. 4. Llama-3.3 70B reads the context and generates a precise answer. """ )
if __name__ == "__main__": demo.launch(share=True, theme=gr.themes.Soft())app.pyDeleted-95