DDingcheol commited on
Commit
a531e8e
ยท
1 Parent(s): b7e362e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -9
app.py CHANGED
@@ -27,15 +27,21 @@ def get_pdf_text(pdf_docs):
27
  # ์•„๋ž˜ ํ…์ŠคํŠธ ์ถ”์ถœ ํ•จ์ˆ˜๋ฅผ ์ž‘์„ฑ
28
  def get_text_file(docs):
29
  text_list = []
30
- for file in docs:
31
- try:
32
- if file.type == 'text/plain':
33
- # ํŒŒ์ผ์ด .txt์ธ ๊ฒฝ์šฐ
34
- text = file.getvalue().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
 
40
  return text_list
41
 
 
27
  # ์•„๋ž˜ ํ…์ŠคํŠธ ์ถ”์ถœ ํ•จ์ˆ˜๋ฅผ ์ž‘์„ฑ
28
  def get_text_file(docs):
29
  text_list = []
30
+ try:
31
+ for file in docs:
32
+ try:
33
+ if file.type == 'text/plain':
34
+ # ํŒŒ์ผ์ด .txt์ธ ๊ฒฝ์šฐ
35
+ text = file.getvalue().decode("utf-8") # ํŒŒ์ผ ๋‚ด์šฉ์„ utf-8 ํ˜•์‹์œผ๋กœ ๋””์ฝ”๋”ฉํ•˜์—ฌ ํ…์ŠคํŠธ๋กœ ๋ณ€ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
36
+ text_list.append(text)
37
+ except IndexError as ie:
38
+ print(f"IndexError occurred while processing a text file: {ie}")
39
+ continue # IndexError๊ฐ€ ๋ฐœ์ƒํ–ˆ์„ ๊ฒฝ์šฐ ์ฒ˜๋ฆฌ๋ฅผ ๊ฑด๋„ˆ๋œ๋‹ˆ๋‹ค.
40
+ except Exception as e:
41
+ print(f"An error occurred while extracting text: {e}")
42
+ continue # ๋‹ค๋ฅธ ์˜ˆ์™ธ๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด ์ฒ˜๋ฆฌ๋ฅผ ๊ฑด๋„ˆ๋œ๋‹ˆ๋‹ค.
43
+ except Exception as ex:
44
+ print(f"An error occurred while processing files: {ex}")
45
 
46
  return text_list
47