hyonee commited on
Commit
8781a2d
โ€ข
1 Parent(s): 03d0f67
Files changed (1) hide show
  1. app.py +7 -9
app.py CHANGED
@@ -36,7 +36,6 @@ def get_text_file(text_docs):
36
  f.write(text_docs.getvalue())
37
  text_loader = TextLoader(temp_filepath)
38
  text_content = text_loader.load()
39
- temp_dir.cleanup()
40
  return text_content
41
 
42
 
@@ -51,14 +50,13 @@ def get_csv_file(csv_docs):
51
 
52
 
53
  def get_json_file(json_docs):
54
- with tempfile.TemporaryDirectory() as temp_dir:
55
- temp_filepath = os.path.join(temp_dir, "temp_file.json")
56
- with open(temp_filepath, "wb") as f:
57
- f.write(json_docs.getvalue())
58
- json_loader = JSONLoader(temp_filepath)
59
- json_content = json_loader.load()
60
-
61
- return json_content
62
 
63
 
64
  # ๋ฌธ์„œ๋“ค์„ ์ฒ˜๋ฆฌํ•˜์—ฌ ํ…์ŠคํŠธ ์ฒญํฌ๋กœ ๋‚˜๋ˆ„๋Š” ํ•จ์ˆ˜์ž…๋‹ˆ๋‹ค.
 
36
  f.write(text_docs.getvalue())
37
  text_loader = TextLoader(temp_filepath)
38
  text_content = text_loader.load()
 
39
  return text_content
40
 
41
 
 
50
 
51
 
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()) # PDF ๋ฌธ์„œ์˜ ๋‚ด์šฉ์„ ์ž„์‹œ ํŒŒ์ผ์— ์”๋‹ˆ๋‹ค.
57
+ json_loader = JSONLoader(temp_filepath) # PyPDFLoader๋ฅผ ์‚ฌ์šฉํ•ด PDF๋ฅผ ๋กœ๋“œํ•ฉ๋‹ˆ๋‹ค.
58
+ json_doc = json_loader.load() # ํ…์ŠคํŠธ๋ฅผ ์ถ”์ถœํ•ฉ๋‹ˆ๋‹ค.
59
+ return json_doc # ์ถ”์ถœํ•œ ํ…์ŠคํŠธ๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
 
60
 
61
 
62
  # ๋ฌธ์„œ๋“ค์„ ์ฒ˜๋ฆฌํ•˜์—ฌ ํ…์ŠคํŠธ ์ฒญํฌ๋กœ ๋‚˜๋ˆ„๋Š” ํ•จ์ˆ˜์ž…๋‹ˆ๋‹ค.