please
Browse files
app.py
CHANGED
|
@@ -41,24 +41,14 @@ def get_text_file(text_docs):
|
|
| 41 |
|
| 42 |
|
| 43 |
def get_csv_file(csv_docs):
|
| 44 |
-
temp_dir = tempfile.TemporaryDirectory()
|
| 45 |
-
temp_filepath = os.path.join(temp_dir.name, csv_docs.name)
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
csv_loader = CSVLoader(temp_filepath)
|
| 52 |
-
csv_content = csv_loader.load()
|
| 53 |
-
|
| 54 |
-
except Exception as e:
|
| 55 |
-
print(f"Error loading CSV file: {e}")
|
| 56 |
-
csv_content = None
|
| 57 |
-
|
| 58 |
-
finally:
|
| 59 |
-
temp_dir.cleanup()
|
| 60 |
|
| 61 |
-
return csv_content
|
| 62 |
|
| 63 |
def get_json_file(json_docs):
|
| 64 |
with tempfile.TemporaryDirectory() as temp_dir:
|
|
|
|
| 41 |
|
| 42 |
|
| 43 |
def get_csv_file(csv_docs):
|
| 44 |
+
temp_dir = tempfile.TemporaryDirectory() # ์์ ๋๋ ํ ๋ฆฌ๋ฅผ ์์ฑํฉ๋๋ค.
|
| 45 |
+
temp_filepath = os.path.join(temp_dir.name, csv_docs.name) # ์์ ํ์ผ ๊ฒฝ๋ก๋ฅผ ์์ฑํฉ๋๋ค.
|
| 46 |
+
with open(temp_filepath, "wb") as f: # ์์ ํ์ผ์ ๋ฐ์ด๋๋ฆฌ ์ฐ๊ธฐ ๋ชจ๋๋ก ์ฝ๋๋ค.
|
| 47 |
+
f.write(csv_docs.getvalue()) # PDF ๋ฌธ์์ ๋ด์ฉ์ ์์ ํ์ผ์ ์๋๋ค.
|
| 48 |
+
csv_loader = CSVLoader(temp_filepath) # PyPDFLoader๋ฅผ ์ฌ์ฉํด PDF๋ฅผ ๋ก๋ํฉ๋๋ค.
|
| 49 |
+
csv_doc = csv_loader.load() # ํ
์คํธ๋ฅผ ์ถ์ถํฉ๋๋ค.
|
| 50 |
+
return csv_doc # ์ถ์ถํ ํ
์คํธ๋ฅผ ๋ฐํํฉ๋๋ค.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
|
|
|
| 52 |
|
| 53 |
def get_json_file(json_docs):
|
| 54 |
with tempfile.TemporaryDirectory() as temp_dir:
|