LaplaceWitch commited on
Commit
30c60ed
ยท
1 Parent(s): 4dce0ce

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -11
app.py CHANGED
@@ -27,33 +27,36 @@ def get_pdf_text(pdf_docs):
27
 
28
  # ๊ณผ์ œ
29
  # ์•„๋ž˜ ํ…์ŠคํŠธ ์ถ”์ถœ ํ•จ์ˆ˜๋ฅผ ์ž‘์„ฑ
30
-
31
- def get_text_file(docs):
32
  temp_dir = tempfile.TemporaryDirectory()
33
  temp_filepath = os.path.join(temp_dir.name, text_docs.name)
34
  with open(temp_filepath, "wb") as f:
35
  f.write(text_docs.getvalue())
36
  text_loader = TextLoader(temp_filepath)
37
- text_doc = text_loader.load()
38
- return text_doc
39
 
40
- def get_csv_file(docs):
 
41
  temp_dir = tempfile.TemporaryDirectory()
42
  temp_filepath = os.path.join(temp_dir.name, csv_docs.name)
43
  with open(temp_filepath, "wb") as f:
44
  f.write(csv_docs.getvalue())
45
  csv_loader = CSVLoader(temp_filepath)
46
- csv_doc = csv_loader.load()
47
- return csv_doc
48
 
49
- def get_json_file(docs):
 
50
  temp_dir = tempfile.TemporaryDirectory()
51
  temp_filepath = os.path.join(temp_dir.name, json_docs.name)
52
  with open(temp_filepath, "wb") as f:
53
  f.write(json_docs.getvalue())
54
- json_loader = JSONLoader(temp_filepath, jq_schema=None)
55
- users_text = json_loader.load()
56
- return users_text
 
57
 
58
 
59
  # ๋ฌธ์„œ๋“ค์„ ์ฒ˜๋ฆฌํ•˜์—ฌ ํ…์ŠคํŠธ ์ฒญํฌ๋กœ ๋‚˜๋ˆ„๋Š” ํ•จ์ˆ˜์ž…๋‹ˆ๋‹ค.
 
27
 
28
  # ๊ณผ์ œ
29
  # ์•„๋ž˜ ํ…์ŠคํŠธ ์ถ”์ถœ ํ•จ์ˆ˜๋ฅผ ์ž‘์„ฑ
30
+ # ํ…์ŠคํŠธ ํŒŒ์ผ๋กœ๋ถ€ํ„ฐ ํ…์ŠคํŠธ ์ถ”์ถœ ํ•จ์ˆ˜๋ฅผ ์ž‘์„ฑ
31
+ def get_text_file(text_docs):
32
  temp_dir = tempfile.TemporaryDirectory()
33
  temp_filepath = os.path.join(temp_dir.name, text_docs.name)
34
  with open(temp_filepath, "wb") as f:
35
  f.write(text_docs.getvalue())
36
  text_loader = TextLoader(temp_filepath)
37
+ text_docs = text_loader.load()
38
+ return text_docs
39
 
40
+ # csv ํŒŒ์ผ๋กœ๋ถ€ํ„ฐ ํ…์ŠคํŠธ๋ฅผ ์ถ”์ถœํ•˜๋Š” ํ•จ์ˆ˜์ž…๋‹ˆ๋‹ค.
41
+ def get_csv_file(csv_docs):
42
  temp_dir = tempfile.TemporaryDirectory()
43
  temp_filepath = os.path.join(temp_dir.name, csv_docs.name)
44
  with open(temp_filepath, "wb") as f:
45
  f.write(csv_docs.getvalue())
46
  csv_loader = CSVLoader(temp_filepath)
47
+ csv_docs = csv_loader.load()
48
+ return csv_docs
49
 
50
+ # json ํŒŒ์ผ๋กœ๋ถ€ํ„ฐ ํ…์ŠคํŠธ๋ฅผ ์ถ”์ถœํ•˜๋Š” ํ•จ์ˆ˜์ž…๋‹ˆ๋‹ค.
51
+ def get_json_file(json_docs):
52
  temp_dir = tempfile.TemporaryDirectory()
53
  temp_filepath = os.path.join(temp_dir.name, json_docs.name)
54
  with open(temp_filepath, "wb") as f:
55
  f.write(json_docs.getvalue())
56
+ json_loader = JSONLoader(temp_filepath, jq_schema='.messages[].content', text_content=True)
57
+ json_docs = json_loader.load()
58
+ return json_docs
59
+
60
 
61
 
62
  # ๋ฌธ์„œ๋“ค์„ ์ฒ˜๋ฆฌํ•˜์—ฌ ํ…์ŠคํŠธ ์ฒญํฌ๋กœ ๋‚˜๋ˆ„๋Š” ํ•จ์ˆ˜์ž…๋‹ˆ๋‹ค.