msmaje commited on
Commit
8b9abe3
Β·
verified Β·
1 Parent(s): 8442587

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -8
app.py CHANGED
@@ -294,7 +294,7 @@ def extract_zip_to_pdfs(zip_file):
294
  os.makedirs(PDF_FOLDER_PATH, exist_ok=True)
295
 
296
  # Extract ZIP file
297
- with zipfile.ZipFile(zip_file.name, 'r') as zip_ref:
298
  # Extract only PDF files
299
  pdf_files = [f for f in zip_ref.namelist() if f.lower().endswith('.pdf')]
300
 
@@ -344,10 +344,10 @@ def process_pdfs(pdf_files, chunk_size, chunk_overlap):
344
  temp_dir = tempfile.mkdtemp()
345
 
346
  # Save uploaded files to temp directory
347
- for pdf_file in pdf_files:
348
- if pdf_file is not None:
349
- temp_path = os.path.join(temp_dir, os.path.basename(pdf_file.name))
350
- shutil.copy2(pdf_file.name, temp_path)
351
 
352
  # Load documents
353
  loader = PyPDFDirectoryLoader(temp_dir)
@@ -959,14 +959,16 @@ def create_interface():
959
 
960
  with gr.Accordion("πŸ“¦ Upload ZIP Archive", open=False):
961
  gr.Markdown("### Option 2: Upload ZIP Archive")
962
- zip_file_input = gr.File(label="Upload ZIP File", type="file", file_count="single", file_types=[".zip"])
 
963
  extract_zip_btn = gr.Button("πŸ“€ Extract ZIP Archive", variant="primary")
964
  zip_status_output = gr.Textbox(label="ZIP Extraction Status", interactive=False)
965
 
966
  with gr.Accordion("πŸ“„ Upload PDF Files", open=False):
967
  gr.Markdown("### Option 3: Direct PDF upload")
968
  gr.Markdown("Upload PDF files directly for processing.")
969
- pdf_file_input = gr.File(label="Upload PDF Files", type="file", file_count="multiple", file_types=[".pdf"])
 
970
 
971
  with gr.Accordion("βš™οΈ Processing Parameters", open=False):
972
  chunk_size_slider = gr.Slider(
@@ -1031,4 +1033,3 @@ if __name__ == "__main__":
1031
  # It's better to explicitly set share=False for local development
1032
  # and only set it to True if you intend to share publicly (which creates a public link)
1033
  demo.launch(show_api=False, inline=False)
1034
-
 
294
  os.makedirs(PDF_FOLDER_PATH, exist_ok=True)
295
 
296
  # Extract ZIP file
297
+ with zipfile.ZipFile(zip_file, 'r') as zip_ref: # zip_file is now a filepath string
298
  # Extract only PDF files
299
  pdf_files = [f for f in zip_ref.namelist() if f.lower().endswith('.pdf')]
300
 
 
344
  temp_dir = tempfile.mkdtemp()
345
 
346
  # Save uploaded files to temp directory
347
+ for pdf_file_path in pdf_files: # pdf_files is now a list of filepaths
348
+ if pdf_file_path is not None:
349
+ temp_path = os.path.join(temp_dir, os.path.basename(pdf_file_path)) # Use pdf_file_path directly
350
+ shutil.copy2(pdf_file_path, temp_path)
351
 
352
  # Load documents
353
  loader = PyPDFDirectoryLoader(temp_dir)
 
959
 
960
  with gr.Accordion("πŸ“¦ Upload ZIP Archive", open=False):
961
  gr.Markdown("### Option 2: Upload ZIP Archive")
962
+ # Changed type from "file" to "filepath"
963
+ zip_file_input = gr.File(label="Upload ZIP File", type="filepath", file_count="single", file_types=[".zip"])
964
  extract_zip_btn = gr.Button("πŸ“€ Extract ZIP Archive", variant="primary")
965
  zip_status_output = gr.Textbox(label="ZIP Extraction Status", interactive=False)
966
 
967
  with gr.Accordion("πŸ“„ Upload PDF Files", open=False):
968
  gr.Markdown("### Option 3: Direct PDF upload")
969
  gr.Markdown("Upload PDF files directly for processing.")
970
+ # Changed type from "file" to "filepath"
971
+ pdf_file_input = gr.File(label="Upload PDF Files", type="filepath", file_count="multiple", file_types=[".pdf"])
972
 
973
  with gr.Accordion("βš™οΈ Processing Parameters", open=False):
974
  chunk_size_slider = gr.Slider(
 
1033
  # It's better to explicitly set share=False for local development
1034
  # and only set it to True if you intend to share publicly (which creates a public link)
1035
  demo.launch(show_api=False, inline=False)