Update app.py
Browse files
app.py
CHANGED
@@ -26,13 +26,9 @@ def get_pdf_text(pdf_docs):
|
|
26 |
# ์๋ ํ
์คํธ ์ถ์ถ ํจ์๋ฅผ ์์ฑ
|
27 |
|
28 |
def get_text_file(text_docs):
|
29 |
-
|
30 |
-
|
31 |
-
|
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 |
-
|
|
|
|
|
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 |
|