File size: 738 Bytes
b3617c5
 
e2677cb
 
b3617c5
 
e2677cb
b3617c5
 
 
 
 
 
 
 
 
 
 
e2677cb
 
b3617c5
 
 
 
 
 
 
e2677cb
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import sys
import os
import gradio as gr

# day3 qovluğunu sys.path-ə əlavə et
sys.path.append(os.path.join(os.path.dirname(__file__), "day3"))

from rag_system import RAGPipeline

rag = RAGPipeline()

def ask_pdf(pdf_file, question):
    if pdf_file:
        info = rag.index_document(pdf_file.name)
    else:
        info = {"chunks_indexed": 0, "best_strategy": None}
    out = rag.query(question)
    return f"**Answer:** {out['answer']}\n\n_Used chunks: {out['used_chunks']}_"

demo = gr.Interface(
    fn=ask_pdf,
    inputs=[
        gr.File(label="Upload PDF", file_types=[".pdf"]),
        gr.Textbox(label="Question")
    ],
    outputs="markdown",
    title="PDF RAG System"
)

if __name__ == "__main__":
    demo.launch()