Spaces:
Build error
Build error
Commit ·
3ebaabb
1
Parent(s): f1730df
added app
Browse files
app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from utils.pdf_parser import extract_text_from_pdf
|
| 4 |
+
from utils.rag_chain import RAGChatbot
|
| 5 |
+
|
| 6 |
+
chatbot = RAGChatbot()
|
| 7 |
+
|
| 8 |
+
def process_query(pdf, query, history):
|
| 9 |
+
if pdf is not None:
|
| 10 |
+
text = extract_text_from_pdf(pdf.name)
|
| 11 |
+
chatbot.load_document(text)
|
| 12 |
+
answer = chatbot.query(query)
|
| 13 |
+
history.append((query, answer))
|
| 14 |
+
return history, ""
|
| 15 |
+
|
| 16 |
+
with gr.Blocks() as demo:
|
| 17 |
+
gr.Markdown("# 🧠 RAG‑based PDF Reader with Contextual Memory")
|
| 18 |
+
pdf_file = gr.File(label="Upload PDF", file_types=[".pdf"])
|
| 19 |
+
chatbot_ui = gr.Chatbot()
|
| 20 |
+
user_input = gr.Textbox(label="Your Question")
|
| 21 |
+
ask_button = gr.Button("Ask")
|
| 22 |
+
|
| 23 |
+
ask_button.click(process_query, [pdf_file, user_input, chatbot_ui], [chatbot_ui, user_input])
|
| 24 |
+
|
| 25 |
+
if __name__ == "__main__":
|
| 26 |
+
demo.launch()
|