Thback commited on
Commit
66beb96
โ€ข
1 Parent(s): 49723e8

Update app.py

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