Chaeruin commited on
Commit
079be20
Β·
1 Parent(s): cfd7b4e
Files changed (2) hide show
  1. README.md +1 -1
  2. app.py +28 -7
README.md CHANGED
@@ -1,5 +1,5 @@
1
  ---
2
- title: Basic DAG AI Chatbot With ChatGPT
3
  emoji: πŸ“š
4
  colorFrom: purple
5
  colorTo: purple
 
1
  ---
2
+ title: 9thMLchatGPT
3
  emoji: πŸ“š
4
  colorFrom: purple
5
  colorTo: purple
app.py CHANGED
@@ -28,17 +28,37 @@ def get_pdf_text(pdf_docs):
28
  # 과제
29
  # μ•„λž˜ ν…μŠ€νŠΈ μΆ”μΆœ ν•¨μˆ˜λ₯Ό μž‘μ„±
30
 
31
- def get_text_file(docs):
32
- pass
33
 
 
 
 
 
 
 
 
 
34
 
35
- def get_csv_file(docs):
36
- pass
37
 
38
- def get_json_file(docs):
39
- pass
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
 
41
-
42
  # λ¬Έμ„œλ“€μ„ μ²˜λ¦¬ν•˜μ—¬ ν…μŠ€νŠΈ 청크둜 λ‚˜λˆ„λŠ” ν•¨μˆ˜μž…λ‹ˆλ‹€.
43
  def get_text_chunks(documents):
44
  text_splitter = RecursiveCharacterTextSplitter(
@@ -76,6 +96,7 @@ def get_conversation_chain(vectorstore):
76
  )
77
  return conversation_chain
78
 
 
79
  # μ‚¬μš©μž μž…λ ₯을 μ²˜λ¦¬ν•˜λŠ” ν•¨μˆ˜μž…λ‹ˆλ‹€.
80
  def handle_userinput(user_question):
81
  # λŒ€ν™” 체인을 μ‚¬μš©ν•˜μ—¬ μ‚¬μš©μž μ§ˆλ¬Έμ— λŒ€ν•œ 응닡을 μƒμ„±ν•©λ‹ˆλ‹€.
 
28
  # 과제
29
  # μ•„λž˜ ν…μŠ€νŠΈ μΆ”μΆœ ν•¨μˆ˜λ₯Ό μž‘μ„±
30
 
 
 
31
 
32
+ def get_text_file(text_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(get_text_chunks(text_docs).getvalue())
37
+ text_loader = TextLoader(temp_filepath)
38
+ text_doc = text_loader.load()
39
+ return text_doc
40
 
 
 
41
 
42
+ def get_csv_file(csv_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_doc = csv_loader.load()
49
+ return csv_doc
50
+
51
+
52
+ def get_json_file(json_docs):
53
+ temp_dir = tempfile.TemporaryDirectory()
54
+ temp_filepath = os.path.join(temp_dir.name, json_docs.name)
55
+ with open(temp_filepath, "wb") as f:
56
+ f.write(json_docs.getvalue())
57
+ json_loader = JSONLoader(temp_filepath, jq_schema='.messages[].content', text_content=False)
58
+ json_doc = json_loader.load()
59
+ return json_doc
60
+
61
 
 
62
  # λ¬Έμ„œλ“€μ„ μ²˜λ¦¬ν•˜μ—¬ ν…μŠ€νŠΈ 청크둜 λ‚˜λˆ„λŠ” ν•¨μˆ˜μž…λ‹ˆλ‹€.
63
  def get_text_chunks(documents):
64
  text_splitter = RecursiveCharacterTextSplitter(
 
96
  )
97
  return conversation_chain
98
 
99
+
100
  # μ‚¬μš©μž μž…λ ₯을 μ²˜λ¦¬ν•˜λŠ” ν•¨μˆ˜μž…λ‹ˆλ‹€.
101
  def handle_userinput(user_question):
102
  # λŒ€ν™” 체인을 μ‚¬μš©ν•˜μ—¬ μ‚¬μš©μž μ§ˆλ¬Έμ— λŒ€ν•œ 응닡을 μƒμ„±ν•©λ‹ˆλ‹€.