Ai
Browse files
app.py
CHANGED
@@ -8,6 +8,9 @@ from langchain.chains import ConversationalRetrievalChain
|
|
8 |
from htmlTemplates import css, bot_template, user_template
|
9 |
from langchain.llms import LlamaCpp # For loading transformer models.
|
10 |
from langchain.document_loaders import PyPDFLoader, TextLoader, JSONLoader, CSVLoader
|
|
|
|
|
|
|
11 |
import tempfile # μμ νμΌμ μμ±νκΈ° μν λΌμ΄λΈλ¬λ¦¬μ
λλ€.
|
12 |
import os
|
13 |
from huggingface_hub import hf_hub_download # Hugging Face Hubμμ λͺ¨λΈμ λ€μ΄λ‘λνκΈ° μν ν¨μμ
λλ€.
|
@@ -24,15 +27,35 @@ def get_pdf_text(pdf_docs):
|
|
24 |
|
25 |
# κ³Όμ
|
26 |
# μλ ν
μ€νΈ μΆμΆ ν¨μλ₯Ό μμ±
|
27 |
-
def get_text_file(
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
-
def get_csv_file(
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
# λ¬Έμλ€μ μ²λ¦¬νμ¬ ν
μ€νΈ μ²ν¬λ‘ λλλ ν¨μμ
λλ€.
|
38 |
def get_text_chunks(documents):
|
|
|
8 |
from htmlTemplates import css, bot_template, user_template
|
9 |
from langchain.llms import LlamaCpp # For loading transformer models.
|
10 |
from langchain.document_loaders import PyPDFLoader, TextLoader, JSONLoader, CSVLoader
|
11 |
+
import json
|
12 |
+
from pathlib import Path
|
13 |
+
from pprint import pprint
|
14 |
import tempfile # μμ νμΌμ μμ±νκΈ° μν λΌμ΄λΈλ¬λ¦¬μ
λλ€.
|
15 |
import os
|
16 |
from huggingface_hub import hf_hub_download # Hugging Face Hubμμ λͺ¨λΈμ λ€μ΄λ‘λνκΈ° μν ν¨μμ
λλ€.
|
|
|
27 |
|
28 |
# κ³Όμ
|
29 |
# μλ ν
μ€νΈ μΆμΆ ν¨μλ₯Ό μμ±
|
30 |
+
def get_text_file(txt_docs):
|
31 |
+
temp_dir = tempfile.TemporaryDirectory() # μμ λλ ν 리λ₯Ό μμ±ν©λλ€.
|
32 |
+
temp_filepath = os.path.join(temp_dir.name, txt_docs.name) # μμ νμΌ κ²½λ‘λ₯Ό μμ±ν©λλ€.
|
33 |
+
with open(temp_filepath, "wb") as f:
|
34 |
+
f.write(txt_docs.getvalue())
|
35 |
+
txt_loader = TextLoader(temp_filepath)
|
36 |
+
txt_doc = txt_loader.load()
|
37 |
+
return txt_doc
|
38 |
|
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_doc = pdf_loader.load()
|
46 |
+
return csv_doc
|
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(
|
54 |
+
file_path='./example_data/facebook_chat.json',
|
55 |
+
jq_schema='.messages[].content',
|
56 |
+
text_content=False)
|
57 |
+
json_doc = json_loader.load()
|
58 |
+
return json_doc
|
59 |
|
60 |
# λ¬Έμλ€μ μ²λ¦¬νμ¬ ν
μ€νΈ μ²ν¬λ‘ λλλ ν¨μμ
λλ€.
|
61 |
def get_text_chunks(documents):
|