Muzammil6376 commited on
Commit
3341c6c
Β·
verified Β·
1 Parent(s): 7fdd092

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -7
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(pdf_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(pdf_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
- pdf_in = gr.File(
117
- label="Upload PDF",
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