Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -27,44 +27,6 @@ def get_pdf_text(pdf_docs):
|
|
27 |
|
28 |
# ๊ณผ์
|
29 |
# ์๋ ํ
์คํธ ์ถ์ถ ํจ์๋ฅผ ์์ฑ
|
30 |
-
import os
|
31 |
-
import tempfile
|
32 |
-
import csv
|
33 |
-
import json
|
34 |
-
from PyPDF2 import PdfReader
|
35 |
-
|
36 |
-
# ํจ์๋ค ์ ์
|
37 |
-
def get_pdf_text(pdf_docs):
|
38 |
-
temp_dir = tempfile.TemporaryDirectory() # ์์ ๋๋ ํ ๋ฆฌ๋ฅผ ์์ฑํฉ๋๋ค.
|
39 |
-
temp_filepath = os.path.join(temp_dir.name, pdf_docs.name) # ์์ ํ์ผ ๊ฒฝ๋ก๋ฅผ ์์ฑํฉ๋๋ค.
|
40 |
-
with open(temp_filepath, "wb") as f: # ์์ ํ์ผ์ ๋ฐ์ด๋๋ฆฌ ์ฐ๊ธฐ ๋ชจ๋๋ก ์ฝ๋๋ค.
|
41 |
-
f.write(pdf_docs.getvalue()) # PDF ๋ฌธ์์ ๋ด์ฉ์ ์์ ํ์ผ์ ์๋๋ค.
|
42 |
-
pdf_loader = PyPDFLoader(temp_filepath) # PyPDFLoader๋ฅผ ์ฌ์ฉํด PDF๋ฅผ ๋ก๋ํฉ๋๋ค.
|
43 |
-
pdf_doc = pdf_loader.load() # ํ
์คํธ๋ฅผ ์ถ์ถํฉ๋๋ค.
|
44 |
-
return pdf_doc # ์ถ์ถํ ํ
์คํธ๋ฅผ ๋ฐํํฉ๋๋ค.
|
45 |
-
import os
|
46 |
-
import tempfile
|
47 |
-
import csv
|
48 |
-
import json
|
49 |
-
from PyPDF2 import PdfReader
|
50 |
-
|
51 |
-
# ์ถ๊ฐ ํจ์ ์ ์
|
52 |
-
def get_text_from_text_file(doc_path):
|
53 |
-
with open(doc_path, 'r', encoding='utf-8') as file:
|
54 |
-
text = file.read()
|
55 |
-
return text
|
56 |
-
|
57 |
-
def get_text_from_csv_file(doc_path):
|
58 |
-
with open(doc_path, 'r', encoding='utf-8') as file:
|
59 |
-
csv_reader = csv.reader(file)
|
60 |
-
text = '\n'.join(','.join(row) for row in csv_reader)
|
61 |
-
return text
|
62 |
-
|
63 |
-
def get_text_from_json_file(doc_path):
|
64 |
-
with open(doc_path, 'r', encoding='utf-8') as file:
|
65 |
-
data = json.load(file)
|
66 |
-
text = json.dumps(data, indent=2)
|
67 |
-
return text
|
68 |
|
69 |
def get_text_file(docs):
|
70 |
text_list = []
|
@@ -106,6 +68,7 @@ def get_vectorstore(text_chunks):
|
|
106 |
|
107 |
return vectorstore # ์์ฑ๋ ๋ฒกํฐ ์คํ ์ด๋ฅผ ๋ฐํํฉ๋๋ค.
|
108 |
|
|
|
109 |
def get_conversation_chain(vectorstore):
|
110 |
gpt_model_name = 'gpt-3.5-turbo'
|
111 |
llm = ChatOpenAI(model_name = gpt_model_name) #gpt-3.5 ๋ชจ๋ธ ๋ก๋
|
@@ -193,4 +156,4 @@ def main():
|
|
193 |
|
194 |
|
195 |
if __name__ == '__main__':
|
196 |
-
main()
|
|
|
27 |
|
28 |
# ๊ณผ์
|
29 |
# ์๋ ํ
์คํธ ์ถ์ถ ํจ์๋ฅผ ์์ฑ
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
def get_text_file(docs):
|
32 |
text_list = []
|
|
|
68 |
|
69 |
return vectorstore # ์์ฑ๋ ๋ฒกํฐ ์คํ ์ด๋ฅผ ๋ฐํํฉ๋๋ค.
|
70 |
|
71 |
+
|
72 |
def get_conversation_chain(vectorstore):
|
73 |
gpt_model_name = 'gpt-3.5-turbo'
|
74 |
llm = ChatOpenAI(model_name = gpt_model_name) #gpt-3.5 ๋ชจ๋ธ ๋ก๋
|
|
|
156 |
|
157 |
|
158 |
if __name__ == '__main__':
|
159 |
+
main()
|