Thback commited on
Commit
c484610
ยท
1 Parent(s): b029abd

Update app.py

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