Dopler47 commited on
Commit
5e3bca6
·
1 Parent(s): 364348a

error fix

Browse files
Files changed (2) hide show
  1. src/utils/constants.py +1 -1
  2. src/utils/utils.py +12 -1
src/utils/constants.py CHANGED
@@ -1,2 +1,2 @@
1
- TEMP_FOLDER = "/home/ubuntu/temps/"
2
  EMBEDDING_MODEL_NAME = "BAAI/bge-small-en"
 
1
+ TEMP_FOLDER = "./data/"
2
  EMBEDDING_MODEL_NAME = "BAAI/bge-small-en"
src/utils/utils.py CHANGED
@@ -1,9 +1,18 @@
1
  import os
2
  import shutil
 
3
 
4
  from src.utils.constants import TEMP_FOLDER
5
 
6
 
 
 
 
 
 
 
 
 
7
  def extract_corpus(fileobj):
8
  """
9
  Reads a file object and returns its contents as a list of strings.
@@ -21,10 +30,12 @@ def extract_corpus(fileobj):
21
  lines : List of str
22
  The contents of the file as a list of strings.
23
  """
24
- path = TEMP_FOLDER + os.path.basename(fileobj)
25
  shutil.copyfile(fileobj.name, path)
26
 
27
  with open(path, "r") as f:
28
  lines = f.readlines()
29
 
 
 
30
  return lines
 
1
  import os
2
  import shutil
3
+ from datetime import datetime
4
 
5
  from src.utils.constants import TEMP_FOLDER
6
 
7
 
8
+ def get_timestamp():
9
+ """
10
+ Return the current timestamp as a string in the format
11
+ "%Y%m%d_%H%M%S".
12
+ """
13
+ return datetime.now().strftime("%Y%m%d_%H%M%S")
14
+
15
+
16
  def extract_corpus(fileobj):
17
  """
18
  Reads a file object and returns its contents as a list of strings.
 
30
  lines : List of str
31
  The contents of the file as a list of strings.
32
  """
33
+ path = TEMP_FOLDER + get_timestamp() + os.path.basename(fileobj)
34
  shutil.copyfile(fileobj.name, path)
35
 
36
  with open(path, "r") as f:
37
  lines = f.readlines()
38
 
39
+ os.remove(path)
40
+
41
  return lines