nijoow commited on
Commit
22b7b9d
ยท
1 Parent(s): 11e5e42

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -39
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()