Thback commited on
Commit
d372ba9
Β·
1 Parent(s): 1e79c34

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -2
app.py CHANGED
@@ -25,11 +25,28 @@ def get_pdf_text(pdf_docs):
25
  # 과제
26
  # μ•„λž˜ ν…μŠ€νŠΈ μΆ”μΆœ ν•¨μˆ˜λ₯Ό μž‘μ„±
27
 
28
- def get_text_file(text_docs): # text λ¬Έμ„œμ˜ λ‚΄μš©μ„ λ°”λ‘œ μΆ”μΆœν•©λ‹ˆλ‹€.
29
- text_content = text_docs.getvalue().decode('utf-8')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  return [text_content] # μΆ”μΆœν•œ ν…μŠ€νŠΈλ₯Ό λ¦¬μŠ€νŠΈμ— λ‹΄μ•„ λ°˜ν™˜ν•©λ‹ˆλ‹€.
31
 
32
 
 
33
  def get_csv_file(csv_docs):
34
  temp_dir = tempfile.TemporaryDirectory() # μž„μ‹œ 디렉토리λ₯Ό μƒμ„±ν•©λ‹ˆλ‹€.
35
  temp_filepath = os.path.join(temp_dir.name, "temp_file.csv") # μž„μ‹œ 파일 경둜λ₯Ό μƒμ„±ν•©λ‹ˆλ‹€.
 
25
  # 과제
26
  # μ•„λž˜ ν…μŠ€νŠΈ μΆ”μΆœ ν•¨μˆ˜λ₯Ό μž‘μ„±
27
 
28
+ def get_text_file(text_docs):
29
+ # μž„μ‹œ 디렉토리λ₯Ό μƒμ„±ν•©λ‹ˆλ‹€.
30
+ temp_dir = tempfile.TemporaryDirectory()
31
+
32
+ # μž„μ‹œ 파일 경둜λ₯Ό μƒμ„±ν•©λ‹ˆλ‹€.
33
+ temp_filepath = os.path.join(temp_dir.name, "temp_file.txt")
34
+
35
+ # ν…μŠ€νŠΈ λ¬Έμ„œμ˜ λ‚΄μš©μ„ μž„μ‹œ νŒŒμΌμ— μ”λ‹ˆλ‹€.
36
+ with open(temp_filepath, "w", encoding="utf-8") as f:
37
+ f.write(text_docs.getvalue())
38
+
39
+ # μž„μ‹œ νŒŒμΌμ—μ„œ ν…μŠ€νŠΈλ₯Ό μ½μ–΄μ˜΅λ‹ˆλ‹€.
40
+ with open(temp_filepath, "r", encoding="utf-8") as f:
41
+ text_content = f.read()
42
+
43
+ # μž„μ‹œ 디렉토리λ₯Ό μžλ™μœΌλ‘œ μ •λ¦¬ν•©λ‹ˆλ‹€.
44
+ temp_dir.cleanup()
45
+
46
  return [text_content] # μΆ”μΆœν•œ ν…μŠ€νŠΈλ₯Ό λ¦¬μŠ€νŠΈμ— λ‹΄μ•„ λ°˜ν™˜ν•©λ‹ˆλ‹€.
47
 
48
 
49
+
50
  def get_csv_file(csv_docs):
51
  temp_dir = tempfile.TemporaryDirectory() # μž„μ‹œ 디렉토리λ₯Ό μƒμ„±ν•©λ‹ˆλ‹€.
52
  temp_filepath = os.path.join(temp_dir.name, "temp_file.csv") # μž„μ‹œ 파일 경둜λ₯Ό μƒμ„±ν•©λ‹ˆλ‹€.