kms commited on
Commit
6dab898
โ€ข
1 Parent(s): 8b8361a

update app

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