Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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 |
-
|
|
|
|
|
|
|
|
|
|
|
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():
|