PCFISH commited on
Commit
780971d
β€’
1 Parent(s): d806b44

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -16
app.py CHANGED
@@ -62,19 +62,21 @@ def get_vectorstore(text_chunks):
62
 
63
 
64
  def get_conversation_chain(vectorstore):
65
- gpt_model_name = 'gpt-3.5-turbo'
66
- llm = ChatOpenAI(model_name = gpt_model_name) #gpt-3.5 λͺ¨λΈ λ‘œλ“œ
67
-
68
- # λŒ€ν™” 기둝을 μ €μž₯ν•˜κΈ° μœ„ν•œ λ©”λͺ¨λ¦¬λ₯Ό μƒμ„±ν•©λ‹ˆλ‹€.
69
- memory = ConversationBufferMemory(
70
- memory_key='chat_history', return_messages=True)
71
- # λŒ€ν™” 검색 체인을 μƒμ„±ν•©λ‹ˆλ‹€.
72
- conversation_chain = ConversationalRetrievalChain.from_llm(
73
- llm=llm,
74
- retriever=vectorstore.as_retriever(),
75
- memory=memory
76
- )
77
- st.session_state.conversation = conversation_chain
 
 
78
  return st.session_state.conversation
79
 
80
  # μ‚¬μš©μž μž…λ ₯을 μ²˜λ¦¬ν•˜λŠ” ν•¨μˆ˜μž…λ‹ˆλ‹€.
@@ -99,9 +101,8 @@ def main():
99
  page_icon=":books:")
100
  st.write(css, unsafe_allow_html=True)
101
 
102
- if "conversation" not in st.session_state:
103
  st.session_state.conversation = None
104
- if "chat_history" not in st.session_state:
105
  st.session_state.chat_history = None
106
 
107
  st.header("Chat with multiple Files :")
@@ -123,7 +124,6 @@ def main():
123
  doc_list = []
124
 
125
  for file in docs:
126
- print('file - type : ', file.type)
127
  if file.type == 'text/plain':
128
  # file is .txt
129
  doc_list.extend(get_text_file(file))
 
62
 
63
 
64
  def get_conversation_chain(vectorstore):
65
+ if st.session_state.conversation is None:
66
+ gpt_model_name = 'gpt-3.5-turbo'
67
+ llm = ChatOpenAI(model_name=gpt_model_name) # gpt-3.5 λͺ¨λΈ λ‘œλ“œ
68
+
69
+ # λŒ€ν™” 기둝을 μ €μž₯ν•˜κΈ° μœ„ν•œ λ©”λͺ¨λ¦¬λ₯Ό μƒμ„±ν•©λ‹ˆλ‹€.
70
+ memory = ConversationBufferMemory(
71
+ memory_key='chat_history', return_messages=True)
72
+ # λŒ€ν™” 검색 체인을 μƒμ„±ν•©λ‹ˆλ‹€.
73
+ conversation_chain = ConversationalRetrievalChain.from_llm(
74
+ llm=llm,
75
+ retriever=vectorstore.as_retriever(),
76
+ memory=memory
77
+ )
78
+ st.session_state.conversation = conversation_chain
79
+
80
  return st.session_state.conversation
81
 
82
  # μ‚¬μš©μž μž…λ ₯을 μ²˜λ¦¬ν•˜λŠ” ν•¨μˆ˜μž…λ‹ˆλ‹€.
 
101
  page_icon=":books:")
102
  st.write(css, unsafe_allow_html=True)
103
 
104
+ if "conversation" not in st.session_state or st.session_state.conversation is None:
105
  st.session_state.conversation = None
 
106
  st.session_state.chat_history = None
107
 
108
  st.header("Chat with multiple Files :")
 
124
  doc_list = []
125
 
126
  for file in docs:
 
127
  if file.type == 'text/plain':
128
  # file is .txt
129
  doc_list.extend(get_text_file(file))