ak3ra commited on
Commit
c55ca9a
·
1 Parent(s): 0ee04a5

fixed pdf issue

Browse files
Files changed (3) hide show
  1. app.py +16 -10
  2. study_files_backup.json +0 -13
  3. utils/db.py +2 -2
app.py CHANGED
@@ -7,7 +7,7 @@ import io
7
  import json
8
  import logging
9
  import os
10
- from typing import Any, List, Tuple
11
 
12
  import gradio as gr
13
  import openai
@@ -83,7 +83,7 @@ def get_rag_pipeline(study_name: str) -> RAGPipeline:
83
  return rag_cache[study_name]
84
 
85
 
86
- def get_study_info(study_name: str | list) -> str:
87
  """Retrieve information about the specified study."""
88
  if isinstance(study_name, list):
89
  study_name = study_name[0] if study_name else None
@@ -546,19 +546,25 @@ def create_gr_interface() -> gr.Blocks:
546
  return "Please select PDF files", None
547
 
548
  try:
549
- result = process_pdf_uploads(files, name)
 
 
550
  collection_id = f"pdf_{slugify(name)}"
551
- return result, collection_id
 
 
 
 
 
 
 
 
 
 
552
  except Exception as e:
553
  logger.error(f"Error in handle_pdf_upload: {str(e)}")
554
  return f"Error: {str(e)}", None
555
 
556
- upload_btn.click(
557
- handle_pdf_upload,
558
- inputs=[pdf_files, collection_name],
559
- outputs=[pdf_status, current_collection],
560
- )
561
-
562
  def add_message(history, message):
563
  """Add user message to chat history."""
564
  if not message.strip():
 
7
  import json
8
  import logging
9
  import os
10
+ from typing import Any, List, Tuple, Union
11
 
12
  import gradio as gr
13
  import openai
 
83
  return rag_cache[study_name]
84
 
85
 
86
+ def get_study_info(study_name: Union[str, list]) -> str:
87
  """Retrieve information about the specified study."""
88
  if isinstance(study_name, list):
89
  study_name = study_name[0] if study_name else None
 
546
  return "Please select PDF files", None
547
 
548
  try:
549
+ processor = PDFProcessor()
550
+ # Process PDFs
551
+ output_path = processor.process_pdfs(files, name)
552
  collection_id = f"pdf_{slugify(name)}"
553
+
554
+ # Add to study files JSON
555
+ append_to_study_files("study_files.json", collection_id, output_path)
556
+
557
+ # Add to ChromaDB
558
+ add_study_files_to_chromadb("study_files.json", "study_files_collection")
559
+
560
+ # Add to SQLite database - this is the crucial missing step
561
+ add_study_files_to_db("study_files.json", "local") # Add library_id parameter
562
+
563
+ return f"Successfully processed PDFs into collection: {collection_id}", collection_id
564
  except Exception as e:
565
  logger.error(f"Error in handle_pdf_upload: {str(e)}")
566
  return f"Error: {str(e)}", None
567
 
 
 
 
 
 
 
568
  def add_message(history, message):
569
  """Add user message to chat history."""
570
  if not message.strip():
study_files_backup.json DELETED
@@ -1,13 +0,0 @@
1
- {
2
- "Vaccine coverage": "data/vaccine_coverage_zotero_items.json",
3
- "Ebola Virus": "data/ebola_virus_zotero_items.json",
4
- "GeneXpert": "data/gene_xpert_zotero_items.json",
5
- "Zotero Collection Pastan": "data/zotero-collection-pastan_zotero_items.json",
6
- "EBSCOhost": "data/ebscohost_zotero_items.json",
7
- "ref BMGF": "data/ref-bmgf_zotero_items.json",
8
- "scholar (29)": "data/scholar-29_zotero_items.json",
9
- "iom": "data/iom_zotero_items.json",
10
- "ExportedRis_file_1_of_1 (1)": "data/exportedris-file-1-of-1-1_zotero_items.json",
11
- "wb_1813-9450-6689": "data/wb-1813-9450-6689_zotero_items.json",
12
- "kayongo papers": "data/kayongo-papers_zotero_items.json"
13
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
utils/db.py CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:4fc6c599c827559f1eb0b001f4a132109b004ae3d12851ac2e2327492a323e44
3
- size 4968
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e165937f30a52640195e2a6ee5a71bcf980f0037e901658ebf813d794332ca6c
3
+ size 5045