mitulagr2 commited on
Commit
453bbe9
1 Parent(s): 09eb2ef
Files changed (1) hide show
  1. app/main.py +5 -4
app/main.py CHANGED
@@ -37,19 +37,20 @@ def process_input(text: str):
37
  def upload(files: list[UploadFile]):
38
  session_assistant.clear()
39
  session_messages = []
 
40
 
41
  try:
42
- os.makedirs("~/wtp_be_files/")
43
  for file in files:
44
  try:
45
  file.file.seek(0)
46
- with Path("~/wtp_be_files/").open("wb") as destination:
47
  shutil.copyfileobj(file.file, destination)
48
  finally:
49
  file.file.close()
50
  finally:
51
- session_assistant.ingest("~/wtp_be_files/")
52
- shutil.rmtree("~/wtp_be_files/")
53
 
54
  return "Files inserted!"
55
 
 
37
  def upload(files: list[UploadFile]):
38
  session_assistant.clear()
39
  session_messages = []
40
+ files_dir = os.path.expanduser("~/wtp_be_files/")
41
 
42
  try:
43
+ os.makedirs(files_dir)
44
  for file in files:
45
  try:
46
  file.file.seek(0)
47
+ with Path(files_dir).open("wb") as destination:
48
  shutil.copyfileobj(file.file, destination)
49
  finally:
50
  file.file.close()
51
  finally:
52
+ session_assistant.ingest(files_dir)
53
+ shutil.rmtree(files_dir)
54
 
55
  return "Files inserted!"
56