acpotts commited on
Commit
074696e
·
1 Parent(s): 5314488

Update process_text_file() function

Browse files
Files changed (1) hide show
  1. app.py +14 -3
app.py CHANGED
@@ -59,9 +59,20 @@ def process_text_file(file: AskFileResponse):
59
  with open(temp_file_path, "wb") as f:
60
  f.write(file.content)
61
 
62
- text_loader = TextFileLoader(temp_file_path)
63
- documents = text_loader.load_documents()
64
- texts = text_splitter.split_texts(documents)
 
 
 
 
 
 
 
 
 
 
 
65
  return texts
66
 
67
 
 
59
  with open(temp_file_path, "wb") as f:
60
  f.write(file.content)
61
 
62
+ if file.type == 'text/plain':
63
+ text_loader = TextFileLoader(temp_file_path)
64
+ documents = text_loader.load_documents()
65
+ texts = text_splitter.split_texts(documents)
66
+ elif file.type == 'application/pdf':
67
+ import pymupdf
68
+ doc = pymupdf.open(temp_file_path)
69
+ texts = ""
70
+ for page_num in range(len(doc)):
71
+ page = doc.load_page(page_num)
72
+ texts += page.get_text()
73
+ else:
74
+ raise ValueError("Provide a .txt or .pdf file")
75
+
76
  return texts
77
 
78