Thback commited on
Commit
7945cb2
โ€ข
1 Parent(s): c484610

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -16
app.py CHANGED
@@ -25,22 +25,35 @@ def get_pdf_text(pdf_docs):
25
  # ๊ณผ์ œ
26
  # ์•„๋ž˜ ํ…์ŠคํŠธ ์ถ”์ถœ ํ•จ์ˆ˜๋ฅผ ์ž‘์„ฑ
27
 
28
- def get_text_file(docs):
29
- # Assuming the document is a text file
30
- text = docs.getvalue().decode('utf-8')
31
- return [text]
32
-
33
- def get_csv_file(docs):
34
- # Assuming the document is a CSV file
35
- csv_loader = CSVLoader(docs)
36
- csv_doc = csv_loader.load()
37
- return csv_doc
38
-
39
- def get_json_file(docs):
40
- # Assuming the document is a JSON file
41
- json_loader = JSONLoader(docs)
42
- json_doc = json_loader.load()
43
- return json_doc
 
 
 
 
 
 
 
 
 
 
 
 
 
44
 
45
 
46
 
 
25
  # ๊ณผ์ œ
26
  # ์•„๋ž˜ ํ…์ŠคํŠธ ์ถ”์ถœ ํ•จ์ˆ˜๋ฅผ ์ž‘์„ฑ
27
 
28
+ # ์•„๋ž˜ ์ฝ”๋“œ๋Š” get_text_file, get_csv_file, get_json_file ํ•จ์ˆ˜ ๋‚ด์šฉ๋งŒ ๋ณ€๊ฒฝ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.
29
+
30
+ def get_text_file(text_docs):
31
+ temp_dir = tempfile.TemporaryDirectory() # ์ž„์‹œ ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.
32
+ temp_filepath = os.path.join(temp_dir.name, text_doce.name) # ์ž„์‹œ ํŒŒ์ผ ๊ฒฝ๋กœ๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.
33
+ with open(temp_filepath, "wb") as f:
34
+ f.write(text_docs.getvalue()) # text ๋ฌธ์„œ์˜ ๋‚ด์šฉ์„ ์ž„์‹œ ํŒŒ์ผ์— ์”๋‹ˆ๋‹ค.
35
+ text_loader = TextLoader(temp_filepath) # TextLoader๋ฅผ ์‚ฌ์šฉํ•ด text๋ฅผ ๋กœ๋“œํ•ฉ๋‹ˆ๋‹ค.
36
+ text_doc = text_loader.load() # ํ…์ŠคํŠธ๋ฅผ ์ถ”์ถœํ•ฉ๋‹ˆ๋‹ค.
37
+ return text_doc # ์ถ”์ถœํ•œ ํ…์ŠคํŠธ๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
38
+
39
+ def get_csv_file(csv_docs):
40
+ temp_dir = tempfile.TemporaryDirectory() # ์ž„์‹œ ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.
41
+ temp_filepath = os.path.join(temp_dir.name, csv_doce.name) # ์ž„์‹œ ํŒŒ์ผ ๊ฒฝ๋กœ๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.
42
+ with open(temp_filepath, "wb") as f:
43
+ f.write(csv_docs.getvalue()) # CSV ๋ฌธ์„œ์˜ ๋‚ด์šฉ์„ ์ž„์‹œ ํŒŒ์ผ์— ์”๋‹ˆ๋‹ค.
44
+ csv_loader = CSVLoader(temp_filepath) # CSVLoader๋ฅผ ์‚ฌ์šฉํ•ด CSV๋ฅผ ๋กœ๋“œํ•ฉ๋‹ˆ๋‹ค.
45
+ csv_doc = csv_loader.load() # ํ…์ŠคํŠธ๋ฅผ ์ถ”์ถœํ•ฉ๋‹ˆ๋‹ค.
46
+ return csv_doc # ์ถ”์ถœํ•œ ํ…์ŠคํŠธ๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
47
+
48
+ def get_json_file(json_docs):
49
+ temp_dir = tempfile.TemporaryDirectory() # ์ž„์‹œ ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.
50
+ temp_filepath = os.path.join(temp_dir.name, json_doce.name) # ์ž„์‹œ ํŒŒ์ผ ๊ฒฝ๋กœ๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.
51
+ with open(temp_filepath, "wb") as f:
52
+ f.write(json_docs.getvalue()) # JSON ๋ฌธ์„œ์˜ ๋‚ด์šฉ์„ ์ž„์‹œ ํŒŒ์ผ์— ์”๋‹ˆ๋‹ค.
53
+ json_loader = JSONLoader(temp_filepath, jq_schema='.messages[].content', text_content=False) # JSONLoader๋ฅผ ์‚ฌ์šฉํ•ด JSON๋ฅผ ๋กœ๋“œํ•ฉ๋‹ˆ๋‹ค.
54
+ json_doc = json_loader.load() # ํ…์ŠคํŠธ๋ฅผ ์ถ”์ถœํ•ฉ๋‹ˆ๋‹ค.
55
+ return json_doc # ์ถ”์ถœํ•œ ํ…์ŠคํŠธ๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
56
+
57
 
58
 
59