Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -99,47 +99,7 @@ rag_chain = (
|
|
| 99 |
| StrOutputParser()
|
| 100 |
)
|
| 101 |
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
# Use existing components for PDF processing and RAG
|
| 107 |
-
loader = DoclingPDFLoader(file_path=pdf_path)
|
| 108 |
-
text_splitter = RecursiveCharacterTextSplitter(
|
| 109 |
-
chunk_size=1000,
|
| 110 |
-
chunk_overlap=200,
|
| 111 |
-
)
|
| 112 |
-
|
| 113 |
-
docs = loader.load()
|
| 114 |
-
splits = text_splitter.split_documents(docs)
|
| 115 |
-
|
| 116 |
-
# Use the existing vectorstore
|
| 117 |
-
vectorstore = Milvus.from_documents(
|
| 118 |
-
splits,
|
| 119 |
-
embeddings,
|
| 120 |
-
connection_args={"uri": MILVUS_URI},
|
| 121 |
-
index_params={
|
| 122 |
-
"index_type": "IVF_FLAT",
|
| 123 |
-
"metric_type": "L2",
|
| 124 |
-
"params": {"nlist": 128}
|
| 125 |
-
},
|
| 126 |
-
drop_old=True,
|
| 127 |
-
)
|
| 128 |
-
|
| 129 |
-
# Use the existing RAG chain
|
| 130 |
-
response = rag_chain.invoke(query)
|
| 131 |
-
return response
|
| 132 |
-
|
| 133 |
-
if __name__ == "__main__":
|
| 134 |
-
# Initialize Gradio interface
|
| 135 |
-
def ask_question(question: str) -> str:
|
| 136 |
-
return main("vol1.pdf", question)
|
| 137 |
-
|
| 138 |
-
iface = gr.Interface(
|
| 139 |
-
fn=ask_question,
|
| 140 |
-
inputs="text",
|
| 141 |
-
outputs="text",
|
| 142 |
-
title="PDF Question Answering",
|
| 143 |
-
description="Ask questions about the PDF content"
|
| 144 |
-
)
|
| 145 |
-
iface.launch()
|
|
|
|
| 99 |
| StrOutputParser()
|
| 100 |
)
|
| 101 |
|
| 102 |
+
rag_chain.invoke("can you explain the subject matter to a primary school student?")
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|