hyonee commited on
Commit
da8b199
1 Parent(s): 1d93e3a
Files changed (1) hide show
  1. app.py +10 -6
app.py CHANGED
@@ -39,21 +39,25 @@ def get_text_file(text_docs):
39
  temp_dir.cleanup()
40
  return text_content
41
 
 
42
  def get_csv_file(csv_docs):
43
  temp_dir = tempfile.TemporaryDirectory()
44
- temp_filepath = os.path.join(temp_dir.name, "temp_file.csv")
45
-
46
- with open(temp_filepath, "wb") as f:
47
- f.write(csv_docs.getvalue())
48
 
49
- csv_loader = CSVLoader(temp_filepath)
50
  try:
 
 
 
 
51
  csv_content = csv_loader.load()
 
52
  except Exception as e:
53
  print(f"Error loading CSV file: {e}")
54
  csv_content = None
55
 
56
- temp_dir.cleanup()
 
 
57
  return csv_content
58
 
59
  def get_json_file(json_docs):
 
39
  temp_dir.cleanup()
40
  return text_content
41
 
42
+
43
  def get_csv_file(csv_docs):
44
  temp_dir = tempfile.TemporaryDirectory()
45
+ temp_filepath = os.path.join(temp_dir.name, csv_docs.name)
 
 
 
46
 
 
47
  try:
48
+ with open(temp_filepath, "wb") as f:
49
+ f.write(csv_docs.getvalue())
50
+
51
+ csv_loader = CSVLoader(temp_filepath)
52
  csv_content = csv_loader.load()
53
+
54
  except Exception as e:
55
  print(f"Error loading CSV file: {e}")
56
  csv_content = None
57
 
58
+ finally:
59
+ temp_dir.cleanup()
60
+
61
  return csv_content
62
 
63
  def get_json_file(json_docs):