Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1567,6 +1567,10 @@ def fetch_google_flights(departure_id="JFK", arrival_id="BHM", outbound_date=cur
|
|
1567 |
# def insert_prompt(current_text, prompt):
|
1568 |
# return prompt[0] if prompt else current_text
|
1569 |
|
|
|
|
|
|
|
|
|
1570 |
|
1571 |
from langchain_core.documents import Document
|
1572 |
# Function to process PDF, extract text, split it into chunks, and upload to the vector DB
|
@@ -1587,6 +1591,17 @@ def process_pdf(pdf_file):
|
|
1587 |
chunk_id = vectorstore.add_documents([document])
|
1588 |
chunk_ids.append(chunk_id)
|
1589 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1590 |
return f"Uploaded {len(chunks)} chunks to the vector database."
|
1591 |
|
1592 |
|
@@ -1700,11 +1715,17 @@ with gr.Blocks(theme='gradio/soft') as demo:
|
|
1700 |
file_input = gr.File(label="Upload PDF", file_types=[".pdf"])
|
1701 |
# Button to trigger processing
|
1702 |
process_button = gr.Button("Process PDF and Upload")
|
|
|
|
|
|
|
|
|
|
|
1703 |
# Output textbox for results
|
1704 |
output_textbox = gr.Textbox(label="Result")
|
1705 |
|
1706 |
# Define button click action
|
1707 |
-
process_button.click(fn=process_pdf, inputs=file_input, outputs=output_textbox)
|
|
|
1708 |
|
1709 |
|
1710 |
|
|
|
1567 |
# def insert_prompt(current_text, prompt):
|
1568 |
# return prompt[0] if prompt else current_text
|
1569 |
|
1570 |
+
# Create a global list to store uploaded document records
|
1571 |
+
uploaded_documents = []
|
1572 |
+
from datetime import datetime
|
1573 |
+
|
1574 |
|
1575 |
from langchain_core.documents import Document
|
1576 |
# Function to process PDF, extract text, split it into chunks, and upload to the vector DB
|
|
|
1591 |
chunk_id = vectorstore.add_documents([document])
|
1592 |
chunk_ids.append(chunk_id)
|
1593 |
|
1594 |
+
# Update the upload history
|
1595 |
+
document_record = {
|
1596 |
+
"Document Name": pdf_file.name,
|
1597 |
+
"Upload Time": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
1598 |
+
"Chunks": len(chunks),
|
1599 |
+
"Pinecone Index": index_name
|
1600 |
+
}
|
1601 |
+
|
1602 |
+
# Add the record to the global list
|
1603 |
+
uploaded_documents.append(document_record)
|
1604 |
+
|
1605 |
return f"Uploaded {len(chunks)} chunks to the vector database."
|
1606 |
|
1607 |
|
|
|
1715 |
file_input = gr.File(label="Upload PDF", file_types=[".pdf"])
|
1716 |
# Button to trigger processing
|
1717 |
process_button = gr.Button("Process PDF and Upload")
|
1718 |
+
|
1719 |
+
# Dataframe to display uploaded document records
|
1720 |
+
document_table = gr.Dataframe(headers=["Document Name", "Upload Time", "Chunks", "Pinecone Index"], interactive=False)
|
1721 |
+
|
1722 |
+
|
1723 |
# Output textbox for results
|
1724 |
output_textbox = gr.Textbox(label="Result")
|
1725 |
|
1726 |
# Define button click action
|
1727 |
+
# process_button.click(fn=process_pdf, inputs=file_input, outputs=output_textbox)
|
1728 |
+
process_button.click(fn=process_pdf, inputs=[file_input, gr.State(uploaded_documents)], outputs=[document_table, output_textbox])
|
1729 |
|
1730 |
|
1731 |
|