HamidOmarov commited on
Commit
e2677cb
·
verified ·
1 Parent(s): 6f0292d

Upload 2 files

Browse files
Files changed (2) hide show
  1. app (1).py +26 -0
  2. requirements (1).txt +6 -0
app (1).py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app.py (repo root)
2
+ import gradio as gr
3
+ from day3.rag_system import RAGPipeline
4
+
5
+ # separate persistent dir for Spaces
6
+ rag = RAGPipeline(persist_dir="./chroma_db_space", collection_name="pdf_docs")
7
+
8
+ def chat_with_pdf(pdf_file, question):
9
+ if pdf_file is None or not question:
10
+ return "Please upload a PDF and enter a question."
11
+ # index uploaded PDF (idempotent for small demos)
12
+ rag.index_document(pdf_file.name, doc_id_prefix="upload")
13
+ out = rag.query(question, k=4)
14
+ return out["answer"]
15
+
16
+ demo = gr.Interface(
17
+ fn=chat_with_pdf,
18
+ inputs=[gr.File(label="Upload PDF", file_types=[".pdf"]),
19
+ gr.Textbox(label="Ask a question")],
20
+ outputs=gr.Textbox(label="Answer"),
21
+ title="PDF RAG (Chroma + Groq)",
22
+ description="Upload a PDF, ask a question. Uses Chroma for retrieval and Groq LLM for answering."
23
+ )
24
+
25
+ if __name__ == "__main__":
26
+ demo.launch()
requirements (1).txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ gradio
2
+ chromadb
3
+ sentence-transformers
4
+ langchain-groq
5
+ pypdf
6
+ python-dotenv