DDingcheol commited on
Commit
755d925
β€’
1 Parent(s): aa9b219

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -4
app.py CHANGED
@@ -12,6 +12,7 @@ import tempfile # μž„μ‹œ νŒŒμΌμ„ μƒμ„±ν•˜κΈ° μœ„ν•œ λΌμ΄λΈŒλŸ¬λ¦¬μž…λ‹ˆλ‹€.
12
  import os
13
  from huggingface_hub import hf_hub_download # Hugging Face Hubμ—μ„œ λͺ¨λΈμ„ λ‹€μš΄λ‘œλ“œν•˜κΈ° μœ„ν•œ ν•¨μˆ˜μž…λ‹ˆλ‹€.
14
 
 
15
  # PDF λ¬Έμ„œλ‘œλΆ€ν„° ν…μŠ€νŠΈλ₯Ό μΆ”μΆœν•˜λŠ” ν•¨μˆ˜μž…λ‹ˆλ‹€.
16
  def get_pdf_text(pdf_docs):
17
  temp_dir = tempfile.TemporaryDirectory() # μž„μ‹œ 디렉토리λ₯Ό μƒμ„±ν•©λ‹ˆλ‹€.
@@ -27,12 +28,12 @@ def get_pdf_text(pdf_docs):
27
  def get_text_file(docs):
28
  text_list = []
29
  for doc in docs:
30
- # 파일 객체λ₯Ό μ²˜λ¦¬ν•©λ‹ˆλ‹€.
31
- if hasattr(doc, 'read'): # 파일 객체에 'read' λ©”μ„œλ“œκ°€ μžˆλŠ”μ§€ ν™•μΈν•©λ‹ˆλ‹€.
32
  text = doc.read().decode("utf-8") # νŒŒμΌμ„ 읽고 UTF-8둜 λ””μ½”λ”©ν•˜μ—¬ λ¬Έμžμ—΄λ‘œ λ³€ν™˜ν•©λ‹ˆλ‹€.
 
33
  else:
34
- text = str(doc) # 파일 객체가 μ•„λ‹Œ 경우 λ¬Έμžμ—΄λ‘œ λ³€ν™˜ν•©λ‹ˆλ‹€.
35
- text_list.append(text)
36
  return text_list
37
 
38
 
 
12
  import os
13
  from huggingface_hub import hf_hub_download # Hugging Face Hubμ—μ„œ λͺ¨λΈμ„ λ‹€μš΄λ‘œλ“œν•˜κΈ° μœ„ν•œ ν•¨μˆ˜μž…λ‹ˆλ‹€.
14
 
15
+
16
  # PDF λ¬Έμ„œλ‘œλΆ€ν„° ν…μŠ€νŠΈλ₯Ό μΆ”μΆœν•˜λŠ” ν•¨μˆ˜μž…λ‹ˆλ‹€.
17
  def get_pdf_text(pdf_docs):
18
  temp_dir = tempfile.TemporaryDirectory() # μž„μ‹œ 디렉토리λ₯Ό μƒμ„±ν•©λ‹ˆλ‹€.
 
28
  def get_text_file(docs):
29
  text_list = []
30
  for doc in docs:
31
+ if hasattr(doc, 'read') and callable(getattr(doc, 'read')):
32
+ # 파일 객체인지 ν™•μΈν•˜κ³  'read' λ©”μ„œλ“œκ°€ μžˆλŠ”μ§€ κ²€μ‚¬ν•©λ‹ˆλ‹€.
33
  text = doc.read().decode("utf-8") # νŒŒμΌμ„ 읽고 UTF-8둜 λ””μ½”λ”©ν•˜μ—¬ λ¬Έμžμ—΄λ‘œ λ³€ν™˜ν•©λ‹ˆλ‹€.
34
+ text_list.append(text)
35
  else:
36
+ text_list.append(str(doc)) # 파일 객체가 μ•„λ‹Œ 경우 λ¬Έμžμ—΄λ‘œ λ³€ν™˜ν•˜μ—¬ μΆ”κ°€ν•©λ‹ˆλ‹€.
 
37
  return text_list
38
 
39