Update app.py
Browse files
app.py
CHANGED
@@ -26,27 +26,27 @@ def get_pdf_text(pdf_docs):
|
|
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) # 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,
|
39 |
with open(temp_filepath, "wb") as f:
|
40 |
-
f.write(
|
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() # ์์ ๋๋ ํ ๋ฆฌ๋ฅผ ์์ฑํฉ๋๋ค.
|
47 |
-
temp_filepath = os.path.join(temp_dir.name,
|
48 |
with open(temp_filepath, "wb") as f:
|
49 |
-
f.write(
|
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 # ์ถ์ถํ ํ
์คํธ๋ฅผ ๋ฐํํฉ๋๋ค.
|
|
|
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(text_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(csv_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() # ์์ ๋๋ ํ ๋ฆฌ๋ฅผ ์์ฑํฉ๋๋ค.
|
47 |
+
temp_filepath = os.path.join(temp_dir.name, temp_file.json) # ์์ ํ์ผ ๊ฒฝ๋ก๋ฅผ ์์ฑํฉ๋๋ค.
|
48 |
with open(temp_filepath, "wb") as f:
|
49 |
+
f.write(json_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 # ์ถ์ถํ ํ
์คํธ๋ฅผ ๋ฐํํฉ๋๋ค.
|