Update app.py
Browse files
app.py
CHANGED
@@ -25,22 +25,22 @@ def get_pdf_text(pdf_docs):
|
|
25 |
# ๊ณผ์
|
26 |
# ์๋ ํ
์คํธ ์ถ์ถ ํจ์๋ฅผ ์์ฑ
|
27 |
def get_text_file(docs):
|
28 |
-
temp_dir = tempfile.TemporaryDirectory()
|
29 |
-
temp_filepath = os.path.join(temp_dir.name,
|
30 |
-
with open(temp_filepath, "wb") as f:
|
31 |
-
f.write(
|
32 |
-
text_loader = TextLoader(temp_filepath)
|
33 |
-
text_doc = text_loader.load()
|
34 |
-
return text_doc
|
35 |
-
|
36 |
def get_csv_file(docs):
|
37 |
-
temp_dir = tempfile.TemporaryDirectory()
|
38 |
-
temp_filepath = os.path.join(temp_dir.name,
|
39 |
-
with open(temp_filepath, "wb") as f:
|
40 |
-
|
41 |
-
csv_loader = CSVLoader(temp_filepath)
|
42 |
-
csv_doc = csv_loader.load()
|
43 |
-
return csv_doc
|
44 |
|
45 |
def get_json_file(docs):
|
46 |
temp_dir = tempfile.TemporaryDirectory() # ์์ ๋๋ ํ ๋ฆฌ๋ฅผ ์์ฑํฉ๋๋ค.
|
@@ -49,8 +49,7 @@ def get_json_file(docs):
|
|
49 |
f.write(docs.getvalue()) # JSON ๋ฌธ์์ ๋ด์ฉ์ ์์ ํ์ผ์ ์๋๋ค.
|
50 |
json_loader = JSONLoader(temp_filepath, jq_schema='.messages[].content', text_content=False) # JSONLoader๋ฅผ ์ฌ์ฉํด JSON๋ฅผ ๋ก๋ํฉ๋๋ค.
|
51 |
json_doc = json_loader.load() # ํ
์คํธ๋ฅผ ์ถ์ถํฉ๋๋ค.
|
52 |
-
|
53 |
-
return json_doc # ์ถ์ถํ ํ
์คํธ๋ฅผ ๋ฐํํฉ๋๋ค
|
54 |
|
55 |
# ๋ฌธ์๋ค์ ์ฒ๋ฆฌํ์ฌ ํ
์คํธ ์ฒญํฌ๋ก ๋๋๋ ํจ์์
๋๋ค.
|
56 |
def get_text_chunks(documents):
|
|
|
25 |
# ๊ณผ์
|
26 |
# ์๋ ํ
์คํธ ์ถ์ถ ํจ์๋ฅผ ์์ฑ
|
27 |
def get_text_file(docs):
|
28 |
+
temp_dir = tempfile.TemporaryDirectory() # ์์ ๋๋ ํ ๋ฆฌ๋ฅผ ์์ฑํฉ๋๋ค.
|
29 |
+
temp_filepath = os.path.join(temp_dir.name, "temp_file.txt") # ์์ ํ์ผ ๊ฒฝ๋ก๋ฅผ ์์ฑํฉ๋๋ค.
|
30 |
+
with open(temp_filepath, "wb") as f:
|
31 |
+
f.write(docs.getvalue()) # text ๋ฌธ์์ ๋ด์ฉ์ ์์ ํ์ผ์ ์๋๋ค.
|
32 |
+
text_loader = TextLoader(temp_filepath) # TextLoader๋ฅผ ์ฌ์ฉํด text๋ฅผ ๋ก๋ํฉ๋๋ค.
|
33 |
+
text_doc = text_loader.load() # ํ
์คํธ๋ฅผ ์ถ์ถํฉ๋๋ค.
|
34 |
+
return text_doc # ์ถ์ถํ ํ
์คํธ๋ฅผ ๋ฐํํฉ๋๋ค.
|
35 |
+
|
36 |
def get_csv_file(docs):
|
37 |
+
temp_dir = tempfile.TemporaryDirectory() # ์์ ๋๋ ํ ๋ฆฌ๋ฅผ ์์ฑํฉ๋๋ค.
|
38 |
+
temp_filepath = os.path.join(temp_dir.name, "temp_file.csv") # ์์ ํ์ผ ๊ฒฝ๋ก๋ฅผ ์์ฑํฉ๋๋ค.
|
39 |
+
with open(temp_filepath, "wb") as f:
|
40 |
+
f.write(docs.getvalue()) # CSV ๋ฌธ์์ ๋ด์ฉ์ ์์ ํ์ผ์ ์๋๋ค.
|
41 |
+
csv_loader = CSVLoader(temp_filepath) # CSVLoader๋ฅผ ์ฌ์ฉํด CSV๋ฅผ ๋ก๋ํฉ๋๋ค.
|
42 |
+
csv_doc = csv_loader.load() # ํ
์คํธ๋ฅผ ์ถ์ถํฉ๋๋ค.
|
43 |
+
return csv_doc # ์ถ์ถํ ํ
์คํธ๋ฅผ ๋ฐํํฉ๋๋ค.
|
44 |
|
45 |
def get_json_file(docs):
|
46 |
temp_dir = tempfile.TemporaryDirectory() # ์์ ๋๋ ํ ๋ฆฌ๋ฅผ ์์ฑํฉ๋๋ค.
|
|
|
49 |
f.write(docs.getvalue()) # JSON ๋ฌธ์์ ๋ด์ฉ์ ์์ ํ์ผ์ ์๋๋ค.
|
50 |
json_loader = JSONLoader(temp_filepath, jq_schema='.messages[].content', text_content=False) # JSONLoader๋ฅผ ์ฌ์ฉํด JSON๋ฅผ ๋ก๋ํฉ๋๋ค.
|
51 |
json_doc = json_loader.load() # ํ
์คํธ๋ฅผ ์ถ์ถํฉ๋๋ค.
|
52 |
+
return json_doc # ์ถ์ถํ ํ
์คํธ๋ฅผ ๋ฐํํฉ๋๋ค.
|
|
|
53 |
|
54 |
# ๋ฌธ์๋ค์ ์ฒ๋ฆฌํ์ฌ ํ
์คํธ ์ฒญํฌ๋ก ๋๋๋ ํจ์์
๋๋ค.
|
55 |
def get_text_chunks(documents):
|