Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
@@ -24,35 +24,34 @@ def get_pdf_text(pdf_docs):
|
|
24 |
|
25 |
# ๊ณผ์
|
26 |
# ์๋ ํ
์คํธ ์ถ์ถ ํจ์๋ฅผ ์์ฑ
|
27 |
-
|
28 |
def get_text_file(text_docs):
|
29 |
-
temp_dir = tempfile.TemporaryDirectory()
|
30 |
-
temp_filepath = os.path.join(temp_dir.name, text_docs.name)
|
31 |
-
with open(temp_filepath, "wb") as f:
|
32 |
-
f.write(text_docs.getvalue())
|
33 |
-
text_loader = TextLoader(temp_filepath)
|
34 |
-
text_doc = text_loader.load()
|
35 |
-
return text_doc
|
36 |
|
37 |
|
38 |
def get_csv_file(csv_docs):
|
39 |
-
temp_dir = tempfile.TemporaryDirectory()
|
40 |
-
temp_filepath = os.path.join(temp_dir.name, csv_docs.name)
|
41 |
-
with open(temp_filepath, "wb") as f:
|
42 |
-
f.write(csv_docs.getvalue())
|
43 |
-
csv_loader = CSVLoader(temp_filepath)
|
44 |
-
csv_doc = csv_loader.load()
|
45 |
-
return csv_doc
|
46 |
|
47 |
|
48 |
def get_json_file(json_docs):
|
49 |
-
temp_dir = tempfile.TemporaryDirectory()
|
50 |
-
temp_filepath = os.path.join(temp_dir.name, json_docs.name)
|
51 |
-
with open(temp_filepath, "wb") as f:
|
52 |
-
f.write(json_docs.getvalue())
|
53 |
-
json_loader = JSONLoader(temp_filepath)
|
54 |
-
json_doc = json_loader.load()
|
55 |
-
return json_doc
|
56 |
|
57 |
|
58 |
|
|
|
24 |
|
25 |
# ๊ณผ์
|
26 |
# ์๋ ํ
์คํธ ์ถ์ถ ํจ์๋ฅผ ์์ฑ
|
|
|
27 |
def get_text_file(text_docs):
|
28 |
+
temp_dir = tempfile.TemporaryDirectory() # ์์ ๋๋ ํ ๋ฆฌ๋ฅผ ์์ฑํฉ๋๋ค.
|
29 |
+
temp_filepath = os.path.join(temp_dir.name, text_docs.name) # ์์ ํ์ผ ๊ฒฝ๋ก๋ฅผ ์์ฑํฉ๋๋ค.
|
30 |
+
with open(temp_filepath, "wb") as f: # ์์ ํ์ผ์ ๋ฐ์ด๋๋ฆฌ ์ฐ๊ธฐ ๋ชจ๋๋ก ์ฝ๋๋ค.
|
31 |
+
f.write(text_docs.getvalue()) # PDF ๋ฌธ์์ ๋ด์ฉ์ ์์ ํ์ผ์ ์๋๋ค.
|
32 |
+
text_loader = TextLoader(temp_filepath) # PyPDFLoader๋ฅผ ์ฌ์ฉํด PDF๋ฅผ ๋ก๋ํฉ๋๋ค.
|
33 |
+
text_doc = text_loader.load() # ํ
์คํธ๋ฅผ ์ถ์ถํฉ๋๋ค.
|
34 |
+
return text_doc # ์ถ์ถํ ํ
์คํธ๋ฅผ ๋ฐํํฉ๋๋ค.
|
35 |
|
36 |
|
37 |
def get_csv_file(csv_docs):
|
38 |
+
temp_dir = tempfile.TemporaryDirectory() # ์์ ๋๋ ํ ๋ฆฌ๋ฅผ ์์ฑํฉ๋๋ค.
|
39 |
+
temp_filepath = os.path.join(temp_dir.name, csv_docs.name) # ์์ ํ์ผ ๊ฒฝ๋ก๋ฅผ ์์ฑํฉ๋๋ค.
|
40 |
+
with open(temp_filepath, "wb") as f: # ์์ ํ์ผ์ ๋ฐ์ด๋๋ฆฌ ์ฐ๊ธฐ ๋ชจ๋๋ก ์ฝ๋๋ค.
|
41 |
+
f.write(csv_docs.getvalue()) # PDF ๋ฌธ์์ ๋ด์ฉ์ ์์ ํ์ผ์ ์๋๋ค.
|
42 |
+
csv_loader = CSVLoader(temp_filepath) # PyPDFLoader๋ฅผ ์ฌ์ฉํด PDF๋ฅผ ๋ก๋ํฉ๋๋ค.
|
43 |
+
csv_doc = csv_loader.load() # ํ
์คํธ๋ฅผ ์ถ์ถํฉ๋๋ค.
|
44 |
+
return csv_doc # ์ถ์ถํ ํ
์คํธ๋ฅผ ๋ฐํํฉ๋๋ค.
|
45 |
|
46 |
|
47 |
def get_json_file(json_docs):
|
48 |
+
temp_dir = tempfile.TemporaryDirectory() # ์์ ๋๋ ํ ๋ฆฌ๋ฅผ ์์ฑํฉ๋๋ค.
|
49 |
+
temp_filepath = os.path.join(temp_dir.name, json_docs.name) # ์์ ํ์ผ ๊ฒฝ๋ก๋ฅผ ์์ฑํฉ๋๋ค.
|
50 |
+
with open(temp_filepath, "wb") as f: # ์์ ํ์ผ์ ๋ฐ์ด๋๋ฆฌ ์ฐ๊ธฐ ๋ชจ๋๋ก ์ฝ๋๋ค.
|
51 |
+
f.write(json_docs.getvalue()) # PDF ๋ฌธ์์ ๋ด์ฉ์ ์์ ํ์ผ์ ์๋๋ค.
|
52 |
+
json_loader = JSONLoader(temp_filepath) # PyPDFLoader๋ฅผ ์ฌ์ฉํด PDF๋ฅผ ๋ก๋ํฉ๋๋ค.
|
53 |
+
json_doc = json_loader.load() # ํ
์คํธ๋ฅผ ์ถ์ถํฉ๋๋ค.
|
54 |
+
return json_doc # ์ถ์ถํ ํ
์คํธ๋ฅผ ๋ฐํํฉ๋๋ค.
|
55 |
|
56 |
|
57 |
|