se0kcess commited on
Commit
8e40ce2
โ€ข
1 Parent(s): 950d69e
Files changed (1) hide show
  1. app.py +30 -16
app.py CHANGED
@@ -25,28 +25,42 @@ def get_pdf_text(pdf_docs):
25
  # ๊ณผ์ œ
26
  # ์•„๋ž˜ ํ…์ŠคํŠธ ์ถ”์ถœ ํ•จ์ˆ˜๋ฅผ ์ž‘์„ฑ
27
  def get_text_file(txt_docs):
28
- temp_dir = tempfile.TemporaryDirectory()
29
- temp_filepath = os.path.join(temp_dir.name, txt_docs.name)
30
 
31
  with open(temp_filepath, "w", encoding="utf-8") as f:
32
- f.write(txt_docs.getvalue())
33
-
34
- txt_loader = TextLoader(temp_filepath)
35
- txt_doc = txt_loader.load()
36
-
37
- return txt_doc
38
 
39
  # CSV ํŒŒ์ผ๋กœ๋ถ€ํ„ฐ ํ…์ŠคํŠธ๋ฅผ ์ถ”์ถœํ•˜๋Š” ํ•จ์ˆ˜
40
- def get_csv_file(docs):
41
- with open(docs, 'r', encoding='utf-8') as file:
42
- csv_text = file.read()
43
- return csv_text
 
 
 
 
 
 
 
44
 
45
  # JSON ํŒŒ์ผ๋กœ๋ถ€ํ„ฐ ํ…์ŠคํŠธ๋ฅผ ์ถ”์ถœํ•˜๋Š” ํ•จ์ˆ˜
46
- def get_json_file(docs):
47
- with open(docs, 'r', encoding='utf-8') as file:
48
- json_text = file.read()
49
- return json_text
 
 
 
 
 
 
 
50
 
51
  # ๋ฌธ์„œ๋“ค์„ ์ฒ˜๋ฆฌํ•˜์—ฌ ํ…์ŠคํŠธ ์ฒญํฌ๋กœ ๋‚˜๋ˆ„๋Š” ํ•จ์ˆ˜์ž…๋‹ˆ๋‹ค.
52
  def get_text_chunks(documents):
 
25
  # ๊ณผ์ œ
26
  # ์•„๋ž˜ ํ…์ŠคํŠธ ์ถ”์ถœ ํ•จ์ˆ˜๋ฅผ ์ž‘์„ฑ
27
  def get_text_file(txt_docs):
28
+ temp_dir = tempfile.TemporaryDirectory()
29
+ temp_filepath = os.path.join(temp_dir.name, txt_docs.name)
30
 
31
  with open(temp_filepath, "w", encoding="utf-8") as f:
32
+ f.write(txt_docs.getvalue())
33
+
34
+ text_loader = TextLoader(temp_filepath)
35
+ text_data = text_loader.load()
36
+
37
+ return text_data
38
 
39
  # CSV ํŒŒ์ผ๋กœ๋ถ€ํ„ฐ ํ…์ŠคํŠธ๋ฅผ ์ถ”์ถœํ•˜๋Š” ํ•จ์ˆ˜
40
+ def get_csv_file(csv_docs):
41
+ temp_dir = tempfile.TemporaryDirectory()
42
+ temp_filepath = os.path.join(temp_dir.name, csv_docs.name)
43
+
44
+ with open(temp_filepath, "w", encoding="utf-8") as f:
45
+ f.write(csv_docs.getvalue())
46
+
47
+ csv_loader = CSVLoader(temp_filepath)
48
+ csv_data = csv_loader.load()
49
+
50
+ return csv_data
51
 
52
  # JSON ํŒŒ์ผ๋กœ๋ถ€ํ„ฐ ํ…์ŠคํŠธ๋ฅผ ์ถ”์ถœํ•˜๋Š” ํ•จ์ˆ˜
53
+ def get_json_file(json_docs):
54
+ temp_dir = tempfile.TemporaryDirectory()
55
+ temp_filepath = os.path.join(temp_dir.name, json_docs.name)
56
+
57
+ with open(temp_filepath, "w", encoding="utf-8") as f:
58
+ f.write(json_docs.getvalue())
59
+
60
+ json_loader = JSONLoader(temp_filepath)
61
+ json_data = json_loader.load()
62
+
63
+ return json_data
64
 
65
  # ๋ฌธ์„œ๋“ค์„ ์ฒ˜๋ฆฌํ•˜์—ฌ ํ…์ŠคํŠธ ์ฒญํฌ๋กœ ๋‚˜๋ˆ„๋Š” ํ•จ์ˆ˜์ž…๋‹ˆ๋‹ค.
66
  def get_text_chunks(documents):