han-byeol commited on
Commit
08400f8
ยท
1 Parent(s): 42e8d6e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -9
app.py CHANGED
@@ -30,11 +30,11 @@ def get_pdf_text(pdf_docs):
30
  # txt ๋ฌธ์„œ๋กœ๋ถ€ํ„ฐ ํ…์ŠคํŠธ๋ฅผ ์ถ”์ถœํ•˜๋Š” ํ•จ์ˆ˜
31
  def get_text_file(docs):
32
  text_data = ""
33
- if docs and hasattr(docs, '__iter__'): # docs๊ฐ€ None์ด ์•„๋‹ˆ๊ณ  iterableํ•œ์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.
34
- for doc in docs:
35
- if doc.type == 'text/plain':
36
- text = doc.getvalue().decode("utf-8")
37
- text_data += text if text else "" # ํŒŒ์ผ์ด ๋น„์–ด์žˆ์ง€ ์•Š์€ ๊ฒฝ์šฐ๋งŒ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.
38
  return text_data
39
 
40
 
@@ -43,8 +43,9 @@ def get_csv_file(docs):
43
  csv_data = ""
44
  for doc in docs:
45
  if doc.type == 'text/csv':
46
- csv_data += doc.getvalue().decode("utf-8")
47
- # CSV ํŒŒ์ผ์ด๋ฉด ํ•ด๋‹น ๋ฐ์ดํ„ฐ๋ฅผ csv_data์— ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.
 
48
  return csv_data
49
 
50
 
@@ -53,10 +54,12 @@ def get_json_file(docs):
53
  json_data = ""
54
  for doc in docs:
55
  if doc.type == 'application/json':
56
- json_data += doc.getvalue().decode("utf-8")
57
- # JSON ํŒŒ์ผ์ด๋ฉด ํ•ด๋‹น ๋ฐ์ดํ„ฐ๋ฅผ json_data์— ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.
 
58
  return json_data
59
 
 
60
 
61
  # ๋ฌธ์„œ๋“ค์„ ์ฒ˜๋ฆฌํ•˜์—ฌ ํ…์ŠคํŠธ ์ฒญํฌ๋กœ ๋‚˜๋ˆ„๋Š” ํ•จ์ˆ˜์ž…๋‹ˆ๋‹ค.
62
  def get_text_chunks(documents):
 
30
  # txt ๋ฌธ์„œ๋กœ๋ถ€ํ„ฐ ํ…์ŠคํŠธ๋ฅผ ์ถ”์ถœํ•˜๋Š” ํ•จ์ˆ˜
31
  def get_text_file(docs):
32
  text_data = ""
33
+ for doc in docs:
34
+ if doc.type == 'text/plain':
35
+ text_loader = TextLoader(doc)
36
+ text_doc = text_loader.load()
37
+ text_data += text_doc if text_doc else "" # ํ…์ŠคํŠธ๊ฐ€ ๋น„์–ด์žˆ์ง€ ์•Š์€ ๊ฒฝ์šฐ๋งŒ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.
38
  return text_data
39
 
40
 
 
43
  csv_data = ""
44
  for doc in docs:
45
  if doc.type == 'text/csv':
46
+ csv_loader = CSVLoader(doc)
47
+ csv_doc = csv_loader.load()
48
+ csv_data += csv_doc if csv_doc else "" # CSV ๋ฐ์ดํ„ฐ๊ฐ€ ๋น„์–ด์žˆ์ง€ ์•Š์€ ๊ฒฝ์šฐ๋งŒ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.
49
  return csv_data
50
 
51
 
 
54
  json_data = ""
55
  for doc in docs:
56
  if doc.type == 'application/json':
57
+ json_loader = JSONLoader(doc)
58
+ json_doc = json_loader.load()
59
+ json_data += json_doc if json_doc else "" # JSON ๋ฐ์ดํ„ฐ๊ฐ€ ๋น„์–ด์žˆ์ง€ ์•Š์€ ๊ฒฝ์šฐ๋งŒ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.
60
  return json_data
61
 
62
+
63
 
64
  # ๋ฌธ์„œ๋“ค์„ ์ฒ˜๋ฆฌํ•˜์—ฌ ํ…์ŠคํŠธ ์ฒญํฌ๋กœ ๋‚˜๋ˆ„๋Š” ํ•จ์ˆ˜์ž…๋‹ˆ๋‹ค.
65
  def get_text_chunks(documents):