Morinash commited on
Commit
6180296
·
verified ·
1 Parent(s): 07ad00d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -4
app.py CHANGED
@@ -61,10 +61,14 @@ def ingest_sources(files, urls):
61
  metadata = []
62
  for f in files:
63
  name = f.name
64
- tmp = tempfile.NamedTemporaryFile(delete=False)
65
- tmp.write(f.read())
66
- tmp.flush()
67
- tmp.close()
 
 
 
 
68
  if name.lower().endswith(".pdf"):
69
  text = extract_text_from_pdf(tmp.name)
70
  elif name.lower().endswith(".docx"):
 
61
  metadata = []
62
  for f in files:
63
  name = f.name
64
+ tmp = tempfile.NamedTemporaryFile(delete=False)
65
+ # handle both NamedString and normal file
66
+ if hasattr(f, "read"):
67
+ tmp.write(f.read())
68
+ else:
69
+ tmp.write(f.encode("utf-8"))
70
+ tmp.flush()
71
+ tmp.close()
72
  if name.lower().endswith(".pdf"):
73
  text = extract_text_from_pdf(tmp.name)
74
  elif name.lower().endswith(".docx"):