DDingcheol commited on
Commit
3fecf20
ยท
1 Parent(s): 6974986

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -22
app.py CHANGED
@@ -25,38 +25,19 @@ def get_pdf_text(pdf_docs):
25
 
26
  # ๊ณผ์ œ
27
  # ์•„๋ž˜ ํ…์ŠคํŠธ ์ถ”์ถœ ํ•จ์ˆ˜๋ฅผ ์ž‘์„ฑ
28
- '''
29
  def get_text_file(docs):
30
  text_list = []
31
  try:
32
  for file in docs:
33
  try:
34
- if file.type == 'text/plain':
35
- # ํŒŒ์ผ์ด .txt์ธ ๊ฒฝ์šฐ
36
- text = file.getvalue().decode("utf-8") # ํŒŒ์ผ ๋‚ด์šฉ์„ utf-8 ํ˜•์‹์œผ๋กœ ๋””์ฝ”๋”ฉํ•˜์—ฌ ํ…์ŠคํŠธ๋กœ ๋ณ€ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
37
  text_list.append(text)
38
- except IndexError as ie:
39
- print(f"IndexError occurred while processing a text file: {ie}")
40
- continue # IndexError๊ฐ€ ๋ฐœ์ƒํ–ˆ์„ ๊ฒฝ์šฐ ์ฒ˜๋ฆฌ๋ฅผ ๊ฑด๋„ˆ๋œ๋‹ˆ๋‹ค.
41
  except Exception as e:
42
  print(f"An error occurred while extracting text: {e}")
43
- continue # ๋‹ค๋ฅธ ์˜ˆ์™ธ๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด ์ฒ˜๋ฆฌ๋ฅผ ๊ฑด๋„ˆ๋œ๋‹ˆ๋‹ค.
44
  except Exception as ex:
45
  print(f"An error occurred while processing files: {ex}")
46
-
47
- return text_list
48
- '''
49
- def get_text_file(docs):
50
- text_list = []
51
- try:
52
- text = docs.getvalue().decode("utf-8") # ํŒŒ์ผ ๋‚ด์šฉ์„ utf-8 ํ˜•์‹์œผ๋กœ ๋””์ฝ”๋”ฉํ•˜์—ฌ ํ…์ŠคํŠธ๋กœ ๋ณ€ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
53
- text_list.append(text)
54
- except UnicodeDecodeError as decode_error:
55
- print(f"UnicodeDecodeError occurred while decoding text: {decode_error}")
56
- # ํŒŒ์ผ์„ ๋‹ค๋ฅธ ๋ฐฉ์‹์œผ๋กœ ๋””์ฝ”๋”ฉํ•˜๊ฑฐ๋‚˜ ๊ฑด๋„ˆ๋›ฐ๋„๋ก ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
57
- except Exception as e:
58
- print(f"An error occurred while extracting text: {e}")
59
-
60
  return text_list
61
 
62
  def get_csv_file(docs):
 
25
 
26
  # ๊ณผ์ œ
27
  # ์•„๋ž˜ ํ…์ŠคํŠธ ์ถ”์ถœ ํ•จ์ˆ˜๋ฅผ ์ž‘์„ฑ
 
28
  def get_text_file(docs):
29
  text_list = []
30
  try:
31
  for file in docs:
32
  try:
33
+ if isinstance(file, bytes):
34
+ text = file.decode("utf-8") # ํŒŒ์ผ ๋‚ด์šฉ์„ utf-8 ํ˜•์‹์œผ๋กœ ๋””์ฝ”๋”ฉํ•˜์—ฌ ํ…์ŠคํŠธ๋กœ ๋ณ€ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
 
35
  text_list.append(text)
 
 
 
36
  except Exception as e:
37
  print(f"An error occurred while extracting text: {e}")
38
+ continue
39
  except Exception as ex:
40
  print(f"An error occurred while processing files: {ex}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  return text_list
42
 
43
  def get_csv_file(docs):