nijoow commited on
Commit
8cfe6ad
Β·
1 Parent(s): 098450e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -4
app.py CHANGED
@@ -94,6 +94,18 @@ def get_conversation_chain(vectorstore):
94
  )
95
  return conversation_chain
96
 
 
 
 
 
 
 
 
 
 
 
 
 
97
  # μ‚¬μš©μž μž…λ ₯을 μ²˜λ¦¬ν•˜λŠ” ν•¨μˆ˜μž…λ‹ˆλ‹€.
98
  def handle_userinput(user_question):
99
  # λŒ€ν™” 체인을 μ‚¬μš©ν•˜μ—¬ μ‚¬μš©μž μ§ˆλ¬Έμ— λŒ€ν•œ 응닡을 μƒμ„±ν•©λ‹ˆλ‹€.
@@ -103,11 +115,15 @@ def handle_userinput(user_question):
103
 
104
  for i, message in enumerate(st.session_state.chat_history):
105
  if i % 2 == 0:
106
- st.write(user_template.replace(
107
- "{{MSG}}", message.content), unsafe_allow_html=True)
108
  else:
109
- st.write(bot_template.replace(
110
- "{{MSG}}", message.content), unsafe_allow_html=True)
 
 
 
 
 
111
 
112
 
113
  def main():
 
94
  )
95
  return conversation_chain
96
 
97
+ # μ‚¬μš©μž μž…λ ₯을 μ²˜λ¦¬ν•˜λŠ” ν•¨μˆ˜μž…λ‹ˆλ‹€.
98
+ from transformers import pipeline
99
+
100
+ # Hugging Face의 question-answering λͺ¨λΈμ„ λ‘œλ“œν•©λ‹ˆλ‹€.
101
+ model_name = "bert-base-uncased"
102
+ qa_model = pipeline("question-answering", model=model_name)
103
+
104
+ def generate_answer(question, context):
105
+ # 질문과 λ¬Έλ§₯을 μž…λ ₯으둜 λ°›μ•„ 닡변을 μƒμ„±ν•©λ‹ˆλ‹€.
106
+ answer = qa_model(question=question, context=context)
107
+ return answer["answer"]
108
+
109
  # μ‚¬μš©μž μž…λ ₯을 μ²˜λ¦¬ν•˜λŠ” ν•¨μˆ˜μž…λ‹ˆλ‹€.
110
  def handle_userinput(user_question):
111
  # λŒ€ν™” 체인을 μ‚¬μš©ν•˜μ—¬ μ‚¬μš©μž μ§ˆλ¬Έμ— λŒ€ν•œ 응닡을 μƒμ„±ν•©λ‹ˆλ‹€.
 
115
 
116
  for i, message in enumerate(st.session_state.chat_history):
117
  if i % 2 == 0:
118
+ st.write(user_template.replace("{{MSG}}", message.content), unsafe_allow_html=True)
 
119
  else:
120
+ st.write(bot_template.replace("{{MSG}}", message.content), unsafe_allow_html=True)
121
+
122
+ # μ§ˆλ¬Έμ— λŒ€ν•œ 닡변을 μƒμ„±ν•˜μ—¬ 좜λ ₯ν•©λ‹ˆλ‹€.
123
+ if i % 2 == 1 and i > 0:
124
+ prev_user_message = st.session_state.chat_history[i-1].content
125
+ answer = generate_answer(message.content, prev_user_message)
126
+ st.write(bot_template.replace("{{MSG}}", answer), unsafe_allow_html=True)
127
 
128
 
129
  def main():