please
Browse files
app.py
CHANGED
|
@@ -30,47 +30,40 @@ def get_pdf_text(pdf_docs):
|
|
| 30 |
# μλ ν
μ€νΈ μΆμΆ ν¨μλ₯Ό μμ±
|
| 31 |
|
| 32 |
def get_text_file(docs):
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
|
| 43 |
def get_csv_file(docs):
|
| 44 |
-
temp_dir = tempfile.TemporaryDirectory()
|
| 45 |
-
temp_filepath = os.path.join(temp_dir.name,
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
csv_writer.writerow(line.split(',')) # μμ: μΌνλ‘ κ΅¬λΆλ λ°μ΄ν°λ₯Ό μ¬μ©
|
| 53 |
|
| 54 |
-
# CSV νμΌμμ λ°μ΄ν° μ½κΈ°
|
| 55 |
with open(temp_filepath, "r", encoding="utf-8") as csv_file:
|
| 56 |
csv_reader = csv.reader(csv_file)
|
| 57 |
csv_data = [row for row in csv_reader]
|
| 58 |
|
| 59 |
-
return csv_data
|
| 60 |
-
|
| 61 |
-
def get_json_file(docs):
|
| 62 |
-
temp_dir = tempfile.TemporaryDirectory() # μμ λλ ν 리λ₯Ό μμ±ν©λλ€.
|
| 63 |
-
temp_filepath = os.path.join(temp_dir.name, "json_file.json") # μμ νμΌ κ²½λ‘λ₯Ό μμ±ν©λλ€.
|
| 64 |
-
|
| 65 |
-
# ν
μ€νΈ λ°μ΄ν°λ₯Ό JSON νμΌμ μ°κΈ°
|
| 66 |
-
with open(temp_filepath, "w", encoding="utf-8") as json_file:
|
| 67 |
-
json.dump(docs, json_file, indent=2) # λ°μ΄ν°λ₯Ό JSON νμΌμ μ°κΈ°
|
| 68 |
|
| 69 |
-
|
| 70 |
-
with
|
| 71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
-
return
|
| 74 |
|
| 75 |
|
| 76 |
# λ¬Έμλ€μ μ²λ¦¬νμ¬ ν
μ€νΈ μ²ν¬λ‘ λλλ ν¨μμ
λλ€.
|
|
|
|
| 30 |
# μλ ν
μ€νΈ μΆμΆ ν¨μλ₯Ό μμ±
|
| 31 |
|
| 32 |
def get_text_file(docs):
|
| 33 |
+
temp_dir = tempfile.TemporaryDirectory()
|
| 34 |
+
temp_filepath = os.path.join(temp_dir.name, text_docs.name)
|
| 35 |
+
with open(temp_filepath, "wb") as f:
|
| 36 |
+
f.write(text_docs.getvalue())
|
| 37 |
+
text_loader = TextLoader(temp_filepath)
|
| 38 |
+
text_content = text_loader.load()
|
| 39 |
+
temp_dir.cleanup()
|
| 40 |
+
return text_content
|
|
|
|
| 41 |
|
| 42 |
def get_csv_file(docs):
|
| 43 |
+
temp_dir = tempfile.TemporaryDirectory()
|
| 44 |
+
temp_filepath = os.path.join(temp_dir.name, csv_docs.name)
|
| 45 |
+
with open(temp_filepath, "wb") as f:
|
| 46 |
+
f.write(csv_docs.getvalue())
|
| 47 |
+
csv_loader = CSVLoader(temp_filepath)
|
| 48 |
+
csv_content = csv_loader.load()
|
| 49 |
+
temp_dir.cleanup()
|
| 50 |
+
return csv_content
|
|
|
|
| 51 |
|
|
|
|
| 52 |
with open(temp_filepath, "r", encoding="utf-8") as csv_file:
|
| 53 |
csv_reader = csv.reader(csv_file)
|
| 54 |
csv_data = [row for row in csv_reader]
|
| 55 |
|
| 56 |
+
return csv_data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
+
def get_json_file(json_docs):
|
| 59 |
+
with tempfile.TemporaryDirectory() as temp_dir:
|
| 60 |
+
temp_filepath = os.path.join(temp_dir, "temp_file.json")
|
| 61 |
+
with open(temp_filepath, "wb") as f:
|
| 62 |
+
f.write(json_docs.getvalue())
|
| 63 |
+
json_loader = JSONLoader(temp_filepath)
|
| 64 |
+
json_content = json_loader.load()
|
| 65 |
|
| 66 |
+
return json_content
|
| 67 |
|
| 68 |
|
| 69 |
# λ¬Έμλ€μ μ²λ¦¬νμ¬ ν
μ€νΈ μ²ν¬λ‘ λλλ ν¨μμ
λλ€.
|