Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -16,9 +16,7 @@ embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/all-mpnet-b
|
|
16 |
vector_store = None
|
17 |
retriever = None
|
18 |
|
19 |
-
|
20 |
def extract_text_from_pdf(filepath):
|
21 |
-
# Use unstructured to read text from the PDF
|
22 |
loader = UnstructuredLoader([filepath])
|
23 |
pages = []
|
24 |
for doc in loader.lazy_load():
|
@@ -26,7 +24,6 @@ def extract_text_from_pdf(filepath):
|
|
26 |
return "\n".join([page.text for page in pages])
|
27 |
|
28 |
def extract_tables_from_pdf(filepath):
|
29 |
-
# Use camelot to read tables from the PDF
|
30 |
tables = camelot.read_pdf(filepath, pages='1-end')
|
31 |
return [table.df.to_string(index=False) for table in tables]
|
32 |
|
@@ -71,7 +68,9 @@ def upload_file(filepath):
|
|
71 |
# Update documents in the vector store
|
72 |
update_documents(text)
|
73 |
|
74 |
-
return [gr.UploadButton(visible=False),
|
|
|
|
|
75 |
|
76 |
# Gradio interface setup
|
77 |
demo = gr.Blocks()
|
@@ -81,7 +80,11 @@ with demo:
|
|
81 |
u = gr.UploadButton("Upload a file", file_count="single")
|
82 |
d = gr.DownloadButton("Download the file", visible=False)
|
83 |
|
84 |
-
|
|
|
|
|
|
|
|
|
85 |
|
86 |
with gr.Row():
|
87 |
chat = gr.ChatInterface(
|
|
|
16 |
vector_store = None
|
17 |
retriever = None
|
18 |
|
|
|
19 |
def extract_text_from_pdf(filepath):
|
|
|
20 |
loader = UnstructuredLoader([filepath])
|
21 |
pages = []
|
22 |
for doc in loader.lazy_load():
|
|
|
24 |
return "\n".join([page.text for page in pages])
|
25 |
|
26 |
def extract_tables_from_pdf(filepath):
|
|
|
27 |
tables = camelot.read_pdf(filepath, pages='1-end')
|
28 |
return [table.df.to_string(index=False) for table in tables]
|
29 |
|
|
|
68 |
# Update documents in the vector store
|
69 |
update_documents(text)
|
70 |
|
71 |
+
return [gr.UploadButton(visible=False),
|
72 |
+
gr.DownloadButton(label=f"Download {Path(filepath).name}", value=filepath, visible=True),
|
73 |
+
f"{len(tables)} tables extracted."] # Change to a Textbox below
|
74 |
|
75 |
# Gradio interface setup
|
76 |
demo = gr.Blocks()
|
|
|
80 |
u = gr.UploadButton("Upload a file", file_count="single")
|
81 |
d = gr.DownloadButton("Download the file", visible=False)
|
82 |
|
83 |
+
# Create a Textbox for the status message
|
84 |
+
status_output = gr.Textbox(label="Status", visible=True)
|
85 |
+
|
86 |
+
# Use the proper output components in the upload method
|
87 |
+
u.upload(upload_file, u, [u, d, status_output])
|
88 |
|
89 |
with gr.Row():
|
90 |
chat = gr.ChatInterface(
|