Spaces:
Sleeping
Sleeping
kms
commited on
Commit
ยท
6dab898
1
Parent(s):
8b8361a
update app
Browse files
app.py
CHANGED
@@ -25,18 +25,38 @@ def get_pdf_text(pdf_docs):
|
|
25 |
pdf_doc = pdf_loader.load() # ํ
์คํธ๋ฅผ ์ถ์ถํฉ๋๋ค.
|
26 |
return pdf_doc # ์ถ์ถํ ํ
์คํธ๋ฅผ ๋ฐํํฉ๋๋ค.
|
27 |
|
28 |
-
#
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
|
42 |
# ๋ฌธ์๋ค์ ์ฒ๋ฆฌํ์ฌ ํ
์คํธ ์ฒญํฌ๋ก ๋๋๋ ํจ์์
๋๋ค.
|
|
|
25 |
pdf_doc = pdf_loader.load() # ํ
์คํธ๋ฅผ ์ถ์ถํฉ๋๋ค.
|
26 |
return pdf_doc # ์ถ์ถํ ํ
์คํธ๋ฅผ ๋ฐํํฉ๋๋ค.
|
27 |
|
28 |
+
# ํ
์คํธ ํ์ผ๋ก๋ถํฐ ํ
์คํธ ์ถ์ถ ํจ์๋ฅผ ์์ฑ
|
29 |
+
def get_text_file(text_docs):
|
30 |
+
temp_dir = tempfile.TemporaryDirectory()
|
31 |
+
temp_filepath = os.path.join(temp_dir.name, text_docs.name)
|
32 |
+
with open(temp_filepath, "wb") as f:
|
33 |
+
f.write(text_docs.getvalue())
|
34 |
+
text_loader = TextLoader(temp_filepath)
|
35 |
+
text_docs = text_loader.load()
|
36 |
+
return text_docs
|
37 |
+
|
38 |
+
# csv ํ์ผ๋ก๋ถํฐ ํ
์คํธ๋ฅผ ์ถ์ถํ๋ ํจ์์
๋๋ค.
|
39 |
+
def get_csv_file(csv_docs):
|
40 |
+
temp_dir = tempfile.TemporaryDirectory()
|
41 |
+
temp_filepath = os.path.join(temp_dir.name, csv_docs.name)
|
42 |
+
with open(temp_filepath, "wb") as f:
|
43 |
+
f.write(csv_docs.getvalue())
|
44 |
+
csv_loader = CSVLoader(temp_filepath)
|
45 |
+
csv_docs = csv_loader.load()
|
46 |
+
text = ""
|
47 |
+
for row in csv_docs:
|
48 |
+
text += "".join(row) + ""
|
49 |
+
return text
|
50 |
+
|
51 |
+
# json ํ์ผ๋ก๋ถํฐ ํ
์คํธ๋ฅผ ์ถ์ถํ๋ ํจ์์
๋๋ค.
|
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())
|
57 |
+
json_loader = JSONLoader(temp_filepath, jq_schema='.messages[].content', text_content=True)
|
58 |
+
json_docs = json_loader.load()
|
59 |
+
return json_docs
|
60 |
|
61 |
|
62 |
# ๋ฌธ์๋ค์ ์ฒ๋ฆฌํ์ฌ ํ
์คํธ ์ฒญํฌ๋ก ๋๋๋ ํจ์์
๋๋ค.
|