Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -79,22 +79,39 @@ def generate_response(user_input):
|
|
| 79 |
def wrap_text(text, max_length=40):
|
| 80 |
return '\n'.join(textwrap.wrap(text, max_length))
|
| 81 |
|
|
|
|
|
|
|
| 82 |
|
| 83 |
-
st.
|
|
|
|
|
|
|
| 84 |
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
|
|
|
|
|
|
| 92 |
|
| 93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
|
|
|
| 98 |
|
| 99 |
if st.session_state['chat_history']:
|
| 100 |
last_chat = st.session_state['chat_history'][-1]
|
|
@@ -105,3 +122,13 @@ if st.session_state['chat_history']:
|
|
| 105 |
for j in range(len(last_chat['Bot'])):
|
| 106 |
new_placeholder.text(wrap_text(sender_name + last_chat['Bot'][:j+1]))
|
| 107 |
time.sleep(0.05)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
def wrap_text(text, max_length=40):
|
| 80 |
return '\n'.join(textwrap.wrap(text, max_length))
|
| 81 |
|
| 82 |
+
|
| 83 |
+
# st.header("[μμμ§λ‘ν΅] μ½μ¬μ κΈΈ \n μ€μ μ½μ¬μ μΈν°λ·° λ΄μ©μ κΈ°λ°μΌλ‘ μ§λ‘ μλ΄μ ν΄λ³΄μΈμ")
|
| 84 |
|
| 85 |
+
# with st.form('form', clear_on_submit=True):
|
| 86 |
+
# user_input = st.text_input('You: ', '', key='input')
|
| 87 |
+
# submitted = st.form_submit_button('Send')
|
| 88 |
|
| 89 |
+
# if submitted and user_input:
|
| 90 |
+
# with st.spinner('μλ΅μ μμ±μ€μ
λλ€...'):
|
| 91 |
+
# output = generate_response(user_input)
|
| 92 |
|
| 93 |
+
# st.session_state.chat_history.append({"User": user_input, "Bot": output})
|
| 94 |
+
|
| 95 |
+
# for idx, chat in enumerate(st.session_state['chat_history'][:-1]):
|
| 96 |
+
# message(chat['User'], is_user=True, key=str(idx) + '_user')
|
| 97 |
+
# message(wrap_text("μ½μ¬: " + chat['Bot']), key=str(idx))
|
| 98 |
|
| 99 |
+
# if st.session_state['chat_history']:
|
| 100 |
+
# last_chat = st.session_state['chat_history'][-1]
|
| 101 |
+
# message(last_chat['User'], is_user=True, key=str(len(st.session_state['chat_history'])-1) + '_user')
|
| 102 |
+
|
| 103 |
+
# new_placeholder = st.empty()
|
| 104 |
+
# sender_name = "μ½μ¬: "
|
| 105 |
+
# for j in range(len(last_chat['Bot'])):
|
| 106 |
+
# new_placeholder.text(wrap_text(sender_name + last_chat['Bot'][:j+1]))
|
| 107 |
+
# time.sleep(0.05)
|
| 108 |
+
|
| 109 |
+
st.header("[μμμ§λ‘ν΅] μ½μ¬μ κΈΈ \n μ€μ μ½μ¬μ μΈν°λ·° λ΄μ©μ κΈ°λ°μΌλ‘ μ§λ‘ μλ΄μ ν΄λ³΄μΈμ")
|
| 110 |
|
| 111 |
+
if st.session_state['chat_history']:
|
| 112 |
+
for idx, chat in enumerate(st.session_state['chat_history'][:-1]):
|
| 113 |
+
message(chat['User'], is_user=True, key=str(idx) + '_user')
|
| 114 |
+
message(wrap_text("μ½μ¬: " + chat['Bot']), key=str(idx))
|
| 115 |
|
| 116 |
if st.session_state['chat_history']:
|
| 117 |
last_chat = st.session_state['chat_history'][-1]
|
|
|
|
| 122 |
for j in range(len(last_chat['Bot'])):
|
| 123 |
new_placeholder.text(wrap_text(sender_name + last_chat['Bot'][:j+1]))
|
| 124 |
time.sleep(0.05)
|
| 125 |
+
|
| 126 |
+
with st.form('form', clear_on_submit=True):
|
| 127 |
+
user_input = st.text_input('You: ', '', key='input')
|
| 128 |
+
submitted = st.form_submit_button('Send')
|
| 129 |
+
|
| 130 |
+
if submitted and user_input:
|
| 131 |
+
with st.spinner('μλ΅μ μμ±μ€μ
λλ€...'):
|
| 132 |
+
output = generate_response(user_input)
|
| 133 |
+
|
| 134 |
+
st.session_state.chat_history.append({"User": user_input, "Bot": output})
|