Spaces:
Sleeping
Sleeping
Download app.py from Padmini1/queryvault: direct link, hf CLI and curl.
- Browser
- Download file 2.97 kB
-
https://huggingface.co/spaces/Padmini1/queryvault/resolve/main/app.py
- Command line
-
hf download hf://spaces/Padmini1/queryvault/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Padmini1/queryvault/resolve/main/app.py
2.97 kB
| """ | |
| QueryVault - Gradio Web Interface | |
| Run this file to launch the QA bot in your browser. | |
| Usage: | |
| python app.py | |
| """ | |
| import gradio as gr | |
| from dotenv import load_dotenv | |
| from src.qabot import process_pdf_and_query | |
| # Load environment variables from .env file | |
| load_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." | |
| if isinstance(pdf_file, str): | |
| file_path = pdf_file | |
| elif isinstance(pdf_file, dict): | |
| file_path = pdf_file.get("path") or pdf_file.get("name") | |
| else: | |
| file_path = getattr(pdf_file, "name", str(pdf_file)) | |
| return process_pdf_and_query(file_path, question) | |
| # --------------------------------------------------------------------------- | |
| # UI Layout | |
| # --------------------------------------------------------------------------- | |
| with gr.Blocks( | |
| title="QueryVault β PDF QA Bot", | |
| theme=gr.themes.Soft() | |
| ) 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) | |