taewon99 commited on
Commit
98a0661
β€’
1 Parent(s): 38c660f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -8
app.py CHANGED
@@ -41,14 +41,19 @@ def get_text_file(docs):
41
  return text_doc # μΆ”μΆœν•œ ν…μŠ€νŠΈλ₯Ό λ°˜ν™˜ν•©λ‹ˆλ‹€.
42
 
43
 
44
- def get_csv_file(docs):
45
- temp_dir = tempfile.TemporaryDirectory() # μž„μ‹œ 디렉토리λ₯Ό μƒμ„±ν•©λ‹ˆλ‹€.
46
- temp_filepath = os.path.join(temp_dir.name, docs.name) # μž„μ‹œ 파일 경둜λ₯Ό μƒμ„±ν•©λ‹ˆλ‹€.
47
- with open(temp_filepath, "wb") as f: # μž„μ‹œ νŒŒμΌμ„ λ°”μ΄λ„ˆλ¦¬ μ“°κΈ° λͺ¨λ“œλ‘œ μ—½λ‹ˆλ‹€.
48
- f.write(docs.getvalue()) # CSV 파일의 λ‚΄μš©μ„ μž„μ‹œ νŒŒμΌμ— μ”λ‹ˆλ‹€.
49
- csv_loader = CSVLoader(temp_filepath) # CSVLoaderλ₯Ό μ‚¬μš©ν•΄ CSVλ₯Ό λ‘œλ“œν•©λ‹ˆλ‹€.
50
- csv_doc = csv_loader.load() # ν…μŠ€νŠΈλ₯Ό μΆ”μΆœν•©λ‹ˆλ‹€.
51
- return csv_doc # μΆ”μΆœν•œ ν…μŠ€νŠΈλ₯Ό λ°˜ν™˜ν•©λ‹ˆλ‹€.
 
 
 
 
 
52
 
53
 
54
  def get_json_file(docs):
 
41
  return text_doc # μΆ”μΆœν•œ ν…μŠ€νŠΈλ₯Ό λ°˜ν™˜ν•©λ‹ˆλ‹€.
42
 
43
 
44
+ def get_csv_text(csv_file):
45
+ # μž„μ‹œ νŒŒμΌμ„ μƒμ„±ν•˜κ³ , μ—…λ‘œλ“œλœ CSV 파일의 λ‚΄μš©μ„ μ”λ‹ˆλ‹€.
46
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".csv") as temp_file:
47
+ temp_file.write(csv_file.read())
48
+ temp_file_path = temp_file.name # μž„μ‹œ 파일 경둜λ₯Ό μ €μž₯ν•©λ‹ˆλ‹€.
49
+
50
+ # CSV νŒŒμΌμ„ μ—΄κ³  λ‚΄μš©μ„ μ½μŠ΅λ‹ˆλ‹€.
51
+ with open(temp_file_path, mode='r', encoding='utf-8') as file:
52
+ csv_reader = csv.reader(file)
53
+ csv_text = "\n".join([", ".join(row) for row in csv_reader]) # 각 행을 λ¬Έμžμ—΄λ‘œ λ³€ν™˜ν•©λ‹ˆλ‹€.
54
+
55
+ os.remove(temp_file_path) # μž„μ‹œ νŒŒμΌμ„ μ‚­μ œν•©λ‹ˆλ‹€.
56
+ return csv_text # CSV 파일의 ν…μŠ€νŠΈλ₯Ό λ°˜ν™˜ν•©λ‹ˆλ‹€.
57
 
58
 
59
  def get_json_file(docs):