Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -64,12 +64,14 @@ def extract_image_caption(path: str) -> str:
|
|
64 |
return vision_client.image_to_text(img)
|
65 |
|
66 |
|
67 |
-
def process_pdf(
|
68 |
"""Ingest a local PDF file, extract text & images, chunk, embed, and index."""
|
69 |
global vector_store, qa_chain
|
70 |
|
71 |
# Move the uploaded PDF into our PDFs folder
|
72 |
-
src = Path(
|
|
|
|
|
73 |
dest = PDF_DIR / src.name
|
74 |
src.rename(dest)
|
75 |
|
@@ -113,11 +115,8 @@ with gr.Blocks() as demo:
|
|
113 |
gr.Markdown("## ππ· Multimodal RAG β Hugging Face Spaces")
|
114 |
|
115 |
with gr.Row():
|
116 |
-
|
117 |
-
|
118 |
-
file_types=["pdf"],
|
119 |
-
type="filepath"
|
120 |
-
)
|
121 |
btn_proc = gr.Button("Process PDF")
|
122 |
status = gr.Textbox(label="Status")
|
123 |
|
|
|
64 |
return vision_client.image_to_text(img)
|
65 |
|
66 |
|
67 |
+
def process_pdf(local_path: str) -> str:
|
68 |
"""Ingest a local PDF file, extract text & images, chunk, embed, and index."""
|
69 |
global vector_store, qa_chain
|
70 |
|
71 |
# Move the uploaded PDF into our PDFs folder
|
72 |
+
src = Path(local_path)
|
73 |
+
if src.suffix.lower() != ".pdf":
|
74 |
+
return "β Error: Uploaded file is not a PDF."
|
75 |
dest = PDF_DIR / src.name
|
76 |
src.rename(dest)
|
77 |
|
|
|
115 |
gr.Markdown("## ππ· Multimodal RAG β Hugging Face Spaces")
|
116 |
|
117 |
with gr.Row():
|
118 |
+
# just accept any local file; we check for .pdf in process_pdf()
|
119 |
+
pdf_in = gr.File(label="Upload PDF", type="filepath")
|
|
|
|
|
|
|
120 |
btn_proc = gr.Button("Process PDF")
|
121 |
status = gr.Textbox(label="Status")
|
122 |
|