HamidOmarov commited on
Commit
85e68ad
·
verified ·
1 Parent(s): 1795915

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -17
app.py CHANGED
@@ -1,25 +1,30 @@
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__":
 
1
+ import sys
2
+ import os
3
  import gradio as gr
 
4
 
5
+ # day3 qovluğunu sys.path-ə əlavə et
6
+ sys.path.append(os.path.join(os.path.dirname(__file__), "day3"))
7
 
8
+ from rag_system import RAGPipeline
9
+
10
+ rag = RAGPipeline()
11
+
12
+ def ask_pdf(pdf_file, question):
13
+ if pdf_file:
14
+ info = rag.index_document(pdf_file.name)
15
+ else:
16
+ info = {"chunks_indexed": 0, "best_strategy": None}
17
+ out = rag.query(question)
18
+ return f"**Answer:** {out['answer']}\n\n_Used chunks: {out['used_chunks']}_"
19
 
20
  demo = gr.Interface(
21
+ fn=ask_pdf,
22
+ inputs=[
23
+ gr.File(label="Upload PDF", file_types=[".pdf"]),
24
+ gr.Textbox(label="Question")
25
+ ],
26
+ outputs="markdown",
27
+ title="PDF RAG System"
28
  )
29
 
30
  if __name__ == "__main__":