Spaces:
Runtime error
Runtime error
wassupyong
commited on
Commit
โข
f8b060d
1
Parent(s):
897ec15
jung app.py
Browse files
app.py
CHANGED
@@ -28,15 +28,32 @@ def get_pdf_text(pdf_docs):
|
|
28 |
# ๊ณผ์
|
29 |
# ์๋ ํ
์คํธ ์ถ์ถ ํจ์๋ฅผ ์์ฑ
|
30 |
|
31 |
-
def get_text_file(
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
-
def get_json_file(
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
|
42 |
# ๋ฌธ์๋ค์ ์ฒ๋ฆฌํ์ฌ ํ
์คํธ ์ฒญํฌ๋ก ๋๋๋ ํจ์์
๋๋ค.
|
|
|
28 |
# ๊ณผ์
|
29 |
# ์๋ ํ
์คํธ ์ถ์ถ ํจ์๋ฅผ ์์ฑ
|
30 |
|
31 |
+
def get_text_file(txt_docs):
|
32 |
+
temp_dir = tempfile.TemporaryDirectory() # ์์ ๋๋ ํ ๋ฆฌ๋ฅผ ์์ฑํฉ๋๋ค.
|
33 |
+
temp_filepath = os.path.join(temp_dir.name, txt_docs.name) # ์์ ํ์ผ ๊ฒฝ๋ก๋ฅผ ์์ฑํฉ๋๋ค.
|
34 |
+
with open(temp_filepath, "wb") as f: # ์์ ํ์ผ์ ๋ฐ์ด๋๋ฆฌ ์ฐ๊ธฐ ๋ชจ๋๋ก ์ฝ๋๋ค.
|
35 |
+
f.write(txt_docs.getvalue()) # txt ๋ฌธ์์ ๋ด์ฉ์ ์์ ํ์ผ์ ์๋๋ค.
|
36 |
+
txt_loader = TextLoader(temp_filepath) # TextLoader๋ฅผ ์ฌ์ฉํด PDF๋ฅผ ๋ก๋ํฉ๋๋ค.
|
37 |
+
txt_doc = txt_loader.load() # ํ
์คํธ๋ฅผ ์ถ์ถํฉ๋๋ค.
|
38 |
+
return txt_doc # ์ถ์ถํ ํ
์คํธ๋ฅผ ๋ฐํํฉ๋๋ค.
|
39 |
+
|
40 |
+
def get_csv_file(csv_docs):
|
41 |
+
temp_dir = tempfile.TemporaryDirectory() # ์์ ๋๋ ํ ๋ฆฌ๋ฅผ ์์ฑํฉ๋๋ค.
|
42 |
+
temp_filepath = os.path.join(temp_dir.name, csv_docs.name) # ์์ ํ์ผ ๊ฒฝ๋ก๋ฅผ ์์ฑํฉ๋๋ค.
|
43 |
+
with open(temp_filepath, "wb") as f: # ์์ ํ์ผ์ ๋ฐ์ด๋๋ฆฌ ์ฐ๊ธฐ ๋ชจ๋๋ก ์ฝ๋๋ค.
|
44 |
+
f.write(csv_docs.getvalue()) # csv ๋ฌธ์์ ๋ด์ฉ์ ์์ ํ์ผ์ ์๋๋ค.
|
45 |
+
csv_loader = CSVLoader(temp_filepath) # CSVLoader๋ฅผ ์ฌ์ฉํด CSV๋ฅผ ๋ก๋ํฉ๋๋ค.
|
46 |
+
csv_doc = csv_loader.load() # ํ
์คํธ๋ฅผ ์ถ์ถํฉ๋๋ค.
|
47 |
+
return csv_doc # ์ถ์ถํ ํ
์คํธ๋ฅผ ๋ฐํํฉ๋๋ค.
|
48 |
|
49 |
+
def get_json_file(json_docs):
|
50 |
+
temp_dir = tempfile.TemporaryDirectory() # ์์ ๋๋ ํ ๋ฆฌ๋ฅผ ์์ฑํฉ๋๋ค.
|
51 |
+
temp_filepath = os.path.join(temp_dir.name, json_docs.name) # ์์ ํ์ผ ๊ฒฝ๋ก๋ฅผ ์์ฑํฉ๋๋ค.
|
52 |
+
with open(temp_filepath, "wb") as f: # ์์ ํ์ผ์ ๋ฐ์ด๋๋ฆฌ ์ฐ๊ธฐ ๋ชจ๋๋ก ์ฝ๋๋ค.
|
53 |
+
f.write(json_docs.getvalue()) # json ๋ฌธ์์ ๋ด์ฉ์ ์์ ํ์ผ์ ์๋๋ค.
|
54 |
+
json_loader = JSONLoader(temp_filepath) # JSONLoader๋ฅผ ์ฌ์ฉํด JSON์ ๋ก๋ํฉ๋๋ค.
|
55 |
+
json_doc = json_loader.load() # ํ
์คํธ๋ฅผ ์ถ์ถํฉ๋๋ค.
|
56 |
+
return json_doc # ์ถ์ถํ ํ
์คํธ๋ฅผ ๋ฐํํฉ๋๋ค.
|
57 |
|
58 |
|
59 |
# ๋ฌธ์๋ค์ ์ฒ๋ฆฌํ์ฌ ํ
์คํธ ์ฒญํฌ๋ก ๋๋๋ ํจ์์
๋๋ค.
|